在尝试将应用程序从JBoss EAP 5迁移到JBoss EAP以及添加一些额外的功能(例如JAX-RS)时,我收到以下错误:
WELD-000082:类net.MyCompany.My.service.MyIPAuthJaxRsService的无状态会话bean上不允许使用范围接口javax.enterprise.context.RequestScoped。只允许@Dependent。
完整堆栈跟踪:
1:02:29,721 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC000001: Failed to start service jboss.deployment.unit."C1Authentication.ear".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."C1Authentication.ear".WeldStartService: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-000082: Scope interface javax.enterprise.context.RequestScoped is not allowed on stateless session beans for class net.MyCompany.My.service.MyIPAuthJaxRsService. Only @Dependent is allowed.
at org.jboss.weld.bean.SessionBean.checkScopeAllowed(SessionBean.java:122)
at org.jboss.weld.bean.SessionBean.internalInitialize(SessionBean.java:101)
at org.jboss.weld.bean.RIBean.initialize(RIBean.java:69)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$5.doWork(ConcurrentBeanDeployer.java:121)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$5.doWork(ConcurrentBeanDeployer.java:118)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:63)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:56)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
在Eclipse中,项目方面是EJB 3.2和Java 1.7
我的EJB-Jar.xml文件包含:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/ejb-jar_3_2.xsd" version="3.2">
<display-name>C1AuthService</display-name>
<enterprise-beans>
<session>
<ejb-name>MyWSService</ejb-name>
<ejb-class>net.MyCompany.My.service.MyWSService</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
<session>
<ejb-name>MyIPAuthJaxRsService</ejb-name>
<ejb-class>net.MyCompany.My.service.MyIPAuthJaxRsService</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
<session>
<ejb-name>MyIPAuthJaxRsServiceApplication</ejb-name>
<ejb-class>net.MyCompany.My.service.MyIPAuthJaxRsServiceApplication</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
两个JAX-RS类是:
package net.mycompany.my.service;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;
@ApplicationPath(value="/C1AuthService")
public class MyIPAuthJaxRsServiceApplication extends Application {
private Set singletons = new HashSet();
public MyIPAuthJaxRsServiceApplication() {
singletons.add(new MyIPAuthJaxRsService());
}
@Override
public Set getSingletons() {
return singletons;
}
@Override
public Set> getClasses() {
// TODO Auto-generated method stub
return null;
}
}
package net.mycompany.my.service;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@Path("/C1AuthService")
public class MyIPAuthJaxRsService {
public MyIPAuthJaxRsService() {
}
@GET
@Path("/test")
public String test() {
return "Hello RESTFul 2";
}
}
答案 0 :(得分:0)
在搜索网页后,我发现以下文章提供了一个线索: https://dzone.com/articles/valid-cdi-scopes-session-ejb
我也偶然发现了这个: http://docs.jboss.org/resteasy/docs/2.0.0.GA/userguide/html/CDI.html
似乎已经发生的事情是在EJB-Jar.xml中我宣称EJB是无状态会话bean,并且没有在java类本身中注释它们CDI / Weld默认它们是@Dependent,例如来自JBoss的文章A CDI bean that does not explicitly define a scope is @Dependent scoped by default.
只需在两个类中添加以下导入和注释:
package net.mycompany.my.service;
import javax.ejb.Stateless;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;
@Stateless
@ApplicationPath(value="/C1AuthService")
public class MyIPAuthJaxRsServiceApplication extends Application {
private Set singletons = new HashSet();
public MyIPAuthJaxRsServiceApplication() {
singletons.add(new MyIPAuthJaxRsService());
}
}
package net.mycompany.my.service;
import javax.ejb.Stateless;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@Stateless
@Path("/C1AuthService")
public class MyIPAuthJaxRsService {
public MyIPAuthJaxRsService() {
}
@GET
@Path("/test")
public String test() {
return "Hello RESTFul 2";
}
}
基本上检查您是否注释了您的EJB&#39;使用@Stateless
并添加了正确的导入import javax.ejb.Stateless;
编辑 - 正如@SteveC所指出的那样我已经删除了覆盖但当我尝试从MyIPAuthJaxRsServiceApplication中删除@Stateless时,他建议我最终再次获取MyIPAuthJaxRsServiceApplication的异常。另外值得注意的是,这个例子甚至不能正常工作,因此在EJB-Jar.xml中使用EJB并且注释可能根本不是必需的,我试图在一个EJB项目和jar中使用它。 EAR,使用JAX-RS对EJB进行注释,但显然它不受支持,因为我在这里与JBoss人员一起工作 https://developer.jboss.org/message/972433#972433
看起来你必须拥有一个用于JAX-RS的servlet容器,并且EJB可以拥有Web服务注释的事实并不意味着他们正在使用servlet容器 - 哦,我试过!此外,这个Q&amp; A更多的是用于修复A CDI bean that does not explicitly define a scope is @Dependent scoped by default.
,我努力了一点,并且如果他们遇到同样的事情我会帮助别人。