我正在尝试使用Morphia作为我使用Java EE创建的Web服务的一部分。在Java EE中使用Morphia
我了解他们的DAO支持吗啡文档对此表示:一个扩展BasicDAO
morhpia提供
In a web application environment, we would probably use a dependency injection framework (like Guice or Spring) to inject the dependencies into the DAO, and then inject the DAO into a controller, so the controller would never directly deal with the gritty details.
所以我有一个EJB标有@Stateless
注释(这样我就可以注入,当我需要它)如下:
@Stateless
public class PlayerDAO extends BasicDAO<Player, ObjectId>{
@EJB
ConnectionFactory factory;
public PlayerDAO(){};
public PlayerDAO(Morphia morphia, MongoClient mongo){
super(mongo, morphia, "testdb");
}
}
我的问题是,我需要提供取Morphia
和MongoClient
参数的构造,并调用super
ç onstructor,这意味着我还需要提供一个无参数构造函数来满足Java EE的要求。
当我加入这个构造的NetBeans显示了错误:
public PlayerDAO(){};
constructor BasicDAO.BasicDAO(Datastore) is not applicable
(actual and formal argument lists differ in length)
constructor BasicDAO.BasicDAO(MongoClient,Morphia,String) is not applicable
(actual and formal argument lists differ in length)
constructor BasicDAO.BasicDAO(Class,Datastore) is not applicable
(actual and formal argument lists differ in length)
constructor BasicDAO.BasicDAO(Class,MongoClient,Morphia,String) is not applicable
(actual and formal argument lists differ in length)
有没有办法来解决这个问题,或者我应该采取不同的方法,以便使用MongoDB的作为Java EE的一部分网络服务?