It seems that CDI needs the no-arg constructor for MyDAO
for some reason. Maybe because of how you use this bean (see specs ch.5.4 "Client Proxies" for possible reasons).
You cannot create a default constructor, because the base class does not have one and, from what I see from the code the super
constructors make immediate use of their args. Therefore passing null to super()
from a no-arg constructor will throw errors.
My suggestion is to create an interface (optionally extending org.mongodb.morphia.dao.DAO
), e.g. MyDAOInterface
that has all public business methods of MyDAO
. Then modify MyDAO
to implement this interface and change your producer to return MyDAOInterface
:
public interface MyDAOInterface extends DAO {...}
public class MyDAO implements MyDAOInterface {
// same implementation
}
public class MyDAOFactory {
@Inject
private Datastore mongoDatastore = null;
/**
* Creates the DAO
*/
@Produces
@ApplicationScoped
public MyDAOInterface createDAO() {
MyDAO dao = new MyDAO(this.mongoDatastore);
return dao;
}
}
By the way, programming to interfaces has the extra benefit of making your code more testable, so it is worth the minor hassle.