我正在使用jersey,EJB开发RESTful Web应用程序。使用JBoss版本6.4.0
我的其他控制器在没有EJB依赖注入的情况下工作正常,但是当我尝试使用EJB依赖注入时,它会在REST控制器中抛出NullPointerException。
我的控制器控制器
prefetchRowsAt
我的服务
@Path("message")
public class DocumentController {
@EJB
private TestService testService;
@GET
public String greeting()
{
return testService.greeting(); // testService is null in there !!!
}
}
单身人士
@Stateless
public class TestServiceImpl implements TestService {
@EJB
private SingletonBean singletonBean;
@Override
public String greeting()
{
return singletonBean.getName();
}
}
public interface TestService {
String greeting();
}
Maven依赖
@Singleton
public class SingletonBeanImpl implements SingletonBean {
@Override
public String getName()
{
return "Vazgen";
}
}
public interface SingletonBean {
String getName();
}
我禁用了resteasy web.xml文件
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<version>1.0.2.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
JBoss日志
<?xml version="1.0" encoding="ISO-8859-1" ?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<display-name>Application display name</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.myorg.application.controller</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.providers</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.resources</param-name>
<param-value>false</param-value>
</context-param>
</web-app>
你能帮我理解什么是问题吗?