java – 我的耳朵无法找到ejb模块类

我是EAR的新手.我开发了一个Web模块和一个ejb模块,它们相互依赖于功能.为此,我试图在EAR中确认他们.我将web和ejb模块映射到EAR,并且可以将application.xml视为

  <display-name>EBS-ear</display-name>
  <module>
    <ejb>EBS-ejb.jar</ejb>
  </module>
  <module>
    <web>
      <web-uri>EBS-web.war</web-uri>
      <context-root>EBS-web</context-root>
    </web>
  </module>
</application>

但是当我尝试执行EAR时,我的服务器会抛出异常

23:58:29,606 ERROR [io.undertow.request] (default task-5) UT005023: Exception handling request to /EBS-web/: java.lang.NoClassDefFoundError: com/ebs/service/UserAuthorisationService
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.getConstructor(Unknown Source)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:480)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:429)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:556)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:295)
    at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112)
    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:264)
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
    at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:967)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:435)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:479)
    at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57)
    at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:111)
    at org.wildfly.extension.undertow.security.RunAsLifecycleInterceptor.init(RunAsLifecycleInterceptor.java:84)
    at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:97)
    at io.undertow.servlet.core.ManagedFilter.createFilter(ManagedFilter.java:80)
    at io.undertow.servlet.core.ManagedFilter.getFilter(ManagedFilter.java:66)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.jsp.JspFileHandler.handleRequest(JspFileHandler.java:32)
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
    at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
    at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
    at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
    at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.ebs.service.UserAuthorisationService from [Module "deployment.EBS-web.war:main" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
    ... 61 more

我从上面可以理解的是,EAR无法找到EJB模块中存在的类,因此抛出了异常.我正在使用WildFLy 10服务器和eclipse IDE.

解决方法:

EAR文件只是各种企业模块(EJB jar,WAR文件和常规jar文件)的容器,其中有一些明确定义(但经常被误解)的规则,哪些类可以看到哪些.

在大多数情况下,您将看到具有以下内部结构的EAR文件:

EAR
 \-lib
 |  \- utilityA.jar
 |  \- utilityB.jar
 |  \- ...
 |- ejb-jarC.jar
 |- ejb-jarD.jar
 |- ...
 |- warE.jar
 |- warF.jar
 |- ...

出于类可见性的目的,上面的EAR显示了五个模块:

> lib模块
> ejb-jar1.jar
> ejb-jar2.jar
> war1.jar
> war2.jar

哪里:

> lib模块中的所有jar都被认为是在同一个模块中;
>每个WAR文件中的所有jar和类都被认为是在同一个模块中;
>每个ejb-jar都是一个独立的模块.

通常,每个模块都有自己的类加载器.

现在,JBossAS / WildFly放宽了类可见性规则,使开发人员的生活更简单(并且由于历史原因).在这些服务器实现上,规则是:

>每个WAR模块都可以看到它自己的类,每个EJB jar中的类以及EAR / lib目录中每个jar中的类

>它无法看到其他WAR模块中的类;

>每个EJB模块都可以看到它自己的类,其他EJB模块中的类以及EAR / lib目录中每个jar中的类;

>它无法在任何WAR模块中看到类;

> EAR / lib模块中的类只能看到对方:

>他们无法在任何EJB模块或WAR模块中看到类

更严格的实现需要定义清单类路径条目,以使EJB模块彼此和WAR模块可见.

现在,考虑到上述所有问题,您的特定问题很可能是以下问题之一:

> lib模块中的一个类试图访问其中一个EJB模块或一个WAR模块中的类 – 您是否将struts2 jar放在EAR / lib目录中?
> EJB模块中的一个类,试图访问其中一个WAR模块中的类

说完所有这些,你可以让你的生活变得更轻松,因为你使用的是JavaEE 7服务器.只需将包含EJB的所有内容打包到WAR文件中即可.您可能无法从构建和部署EAR中获益

上一篇:java – 从jar中自动检测Hibernate中的类


下一篇:java – JBoss 7.1无法部署战争