带EJB的jboss REST服务:无法启动上下文

时间:2014-01-05 20:50:48

标签: java jboss ejb resteasy

我在eclipse中用JSF和JPA使用MySQL制作动态网页,在JBoss上,我有会话bean,它与DAO通信以从DB获取数据。现在我需要创建REST服务,所以我创建了新的动态Web项目,然后我在“创建示例RESTful Web服务”向导中选择了该项目。我做了简单的方法来返回字符串“hello world”并且它有效。但是在我从第一个动态Web项目中添加了会话bean的@EJB注释后(它被添加到构建路径中),当我尝试完全发布它时,我收到错误:无法启动上下文。

请帮忙。

会话bean:

@Stateless
@LocalBean
public class SessionsSB {

    @PersistenceContext
    private EntityManager em;

    private SessionsDAO sessionsDao;

    @PostConstruct
    public void init(){
        sessionsDao = new SessionsDAO(em);
    }
some methods...
}

的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>RestWS</display-name>
  <servlet>
    <servlet-name>Resteasy</servlet-name>
    <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Resteasy</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>javax.ws.rs.Application</param-name>
    <param-value>org.jboss.samples.rs.webservices.MyRESTApplication</param-value>
  </context-param>
  <listener>
    <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
  </listener>
</web-app>

REST应用:

public class MyRESTApplication extends Application {

    private Set<Object> singletons = new HashSet<Object>();
    private Set<Class<?>> empty = new HashSet<Class<?>>();
    public MyRESTApplication(){
         singletons.add(new HelloWorldResource());
    }
    @Override
    public Set<Class<?>> getClasses() {
         return empty;
    }
    @Override
    public Set<Object> getSingletons() {
         return singletons;
    }
}

@Path("/MyRESTApplication")
public class HelloWorldResource {

    @EJB
    private SessionsSB sessionsSB;

    @GET()
    @Produces("application/xml")
    @Path("/hello")
    public Sessions sayHello() {
        Sessions sessions = sessionsSB.getSession(4);

        return sessions;
    }
}

堆栈跟踪:

22:00:15,851 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "RestWS.war"
22:00:15,864 INFO  [org.jboss.as.jpa] (MSC service thread 1-4) JBAS011401: Read persistence.xml for RestWS
22:00:15,884 INFO  [org.jboss.as.jpa] (MSC service thread 1-4) JBAS011402: Starting Persistence Unit Service 'RestWS.war#RestWS'
22:00:15,885 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-4) HHH000204: Processing PersistenceUnitInfo [
    name: RestWS
    ...]
22:00:15,895 INFO  [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-4) HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
22:00:15,902 INFO  [org.hibernate.dialect.Dialect] (MSC service thread 1-4) HHH000400: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
22:00:15,903 INFO  [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-4) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory
22:00:15,905 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-4) HHH000397: Using ASTQueryTranslatorFactory
22:00:15,908 INFO  [org.hibernate.tool.hbm2ddl.SchemaUpdate] (MSC service thread 1-4) HHH000228: Running hbm2ddl schema update
22:00:15,908 INFO  [org.hibernate.tool.hbm2ddl.SchemaUpdate] (MSC service thread 1-4) HHH000102: Fetching database metadata
22:00:15,909 INFO  [org.hibernate.tool.hbm2ddl.SchemaUpdate] (MSC service thread 1-4) HHH000396: Updating schema
22:00:15,910 INFO  [org.hibernate.tool.hbm2ddl.SchemaUpdate] (MSC service thread 1-4) HHH000232: Schema update complete
22:00:15,949 INFO  [org.jboss.resteasy.spi.ResteasyDeployment] (MSC service thread 1-3) Deploying javax.ws.rs.core.Application: class org.jboss.samples.rs.webservices.MyRESTApplication
22:00:15,950 INFO  [org.jboss.resteasy.spi.ResteasyDeployment] (MSC service thread 1-3) Adding singleton resource org.jboss.samples.rs.webservices.HelloWorldResource from Application class org.jboss.samples.rs.webservices.MyRESTApplication
22:00:15,952 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/RestWS]] (MSC service thread 1-3) Exception sending context initialized event to listener instance of class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap: java.lang.NoClassDefFoundError: entities/Sessions
    at java.lang.Class.getDeclaredMethods0(Native Method) [rt.jar:1.7.0_45]
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source) [rt.jar:1.7.0_45]
    at java.lang.Class.privateGetPublicMethods(Unknown Source) [rt.jar:1.7.0_45]
    at java.lang.Class.getMethods(Unknown Source) [rt.jar:1.7.0_45]
    at org.jboss.resteasy.spi.metadata.ResourceBuilder.fromAnnotations(ResourceBuilder.java:747) [resteasy-jaxrs-3.0.6.Final.jar:]
    at org.jboss.resteasy.spi.metadata.ResourceBuilder.rootResourceFromAnnotations(ResourceBuilder.java:700) [resteasy-jaxrs-3.0.6.Final.jar:]
    at org.jboss.resteasy.plugins.server.resourcefactory.SingletonResource.<init>(SingletonResource.java:24) [resteasy-jaxrs-3.0.6.Final.jar:]
    at org.jboss.resteasy.core.ResourceMethodRegistry.addSingletonResource(ResourceMethodRegistry.java:96) [resteasy-jaxrs-3.0.6.Final.jar:]
    at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:424) [resteasy-jaxrs-3.0.6.Final.jar:]
    at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:241) [resteasy-jaxrs-3.0.6.Final.jar:]
    at org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextInitialized(ResteasyBootstrap.java:28) [resteasy-jaxrs-3.0.6.Final.jar:]
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_45]
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_45]
Caused by: java.lang.ClassNotFoundException: entities.Sessions from [Module "deployment.RestWS.war:main" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
    ... 19 more

22:00:15,972 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-3) Error listenerStart
22:00:15,973 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-3) Context [/RestWS] startup failed due to previous errors
22:00:15,975 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC00001: Failed to start service jboss.web.deployment.default-host./RestWS: org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./RestWS: JBAS018040: Failed to start context
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:95)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_45]
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_45]

22:00:16,182 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS015870: Deploy of deployment "RestWS.war" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.web.deployment.default-host./RestWS" => "org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./RestWS: JBAS018040: Failed to start context"}}
22:00:16,182 INFO  [org.jboss.as.jpa] (MSC service thread 1-4) JBAS011403: Stopping Persistence Unit Service 'RestWS.war#RestWS'
22:00:16,186 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015877: Stopped deployment RestWS.war in 5ms
22:00:16,187 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 1) JBAS014774: Service status report
JBAS014777:   Services which failed to start:      service jboss.web.deployment.default-host./RestWS: org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./RestWS: JBAS018040: Failed to start context

22:00:16,189 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 2) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014671: Failed services" => {"jboss.web.deployment.default-host./RestWS" => "org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./RestWS: JBAS018040: Failed to start context"}}}}

0 个答案:

没有答案