我正在尝试在WebService中注入DAO对象
@Stateless
public class MyDAOImpl implements MyDAO {...}
@Local
public interface MyDAO {...}
在网络服务中我想注入这个DAO:
@Stateless
@WebService(endpointInterface = "...")
public class PropertyDetailsWebServiceImpl implements PropertyDetailsWebService {
...
@EJB
MyDAO myDAO; // null pointer
}
当我尝试JNDI时 - 这有效:
@Stateless
@WebService(endpointInterface = "...")
public class PropertyDetailsWebServiceImpl implements PropertyDetailsWebService {
...
InitialContext ic = new InitialContext();
loggerInstance = (MyDAO ) ic.lookup("java:global/ben/MyDAO Impl!pl.MyDAO"); //this works
}
为什么@EJB注射不起作用?
答案 0 :(得分:0)
我将maven依赖模块webservice从jar更改为ejb,这有效:D
从
改变<dependency>
<groupId>pl.xxx.webservice</groupId>
<artifactId>webservice</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
到
<dependency>
<groupId>pl.xxx.webservice</groupId>
<artifactId>webservice</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type> // this
</dependency>