java.lang.ClassNotFoundException:javax.enterprise.event.Event

Posted

技术标签:

【中文标题】java.lang.ClassNotFoundException:javax.enterprise.event.Event【英文标题】:java.lang.ClassNotFoundException: javax.enterprise.event.Event 【发布时间】:2016-02-29 10:04:32 【问题描述】:

我在将 Java EE 应用程序部署到 WildFly 时遇到问题 我尝试了不同的方法。

我通过 maven archetype (wildfly-javaee7-webapp-ear-archetype) 创建了 java 应用程序 并尝试通过 Idea(和管理控制台)运行 Wildfy,但部署时出错:

Cannot upload deployment: "WFLYCTL0080: Failed services" => "jboss.deployment.subunit.\"dtest-ear.ear\".\"dtest-ejb.jar\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.subunit.\"dtest-ear.ear\".\"dtest-ejb.jar\".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of subdeployment \"dtest-ejb.jar\" of deployment \"dtest-ear.ear\" Caused by: java.lang.RuntimeException: WFLYSRV0177: Error getting reflective information for class by.mass.service.MemberRegistration with ClassLoader ModuleClassLoader for Module \"deployment.dtest-ear.ear.dtest-ejb.jar:main\" from Service Module Loader Caused by: java.lang.NoClassDefFoundError: Ljavax/enterprise/event/Event; Caused by: java.lang.ClassNotFoundException: javax.enterprise.event.Event from [Module \"deployment.dtest-ear.ear.dtest-ejb.jar:main\" from Service Module Loader]"

在日志中:

ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.subunit."dtest-ear.ear"."dtest-ejb.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."dtest-ear.ear"."dtest-ejb.jar".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of subdeployment "dtest-ejb.jar" of deployment "dtest-ear.ear"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:163)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
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: java.lang.RuntimeException: WFLYSRV0177: Error getting reflective information for class by.mass.service.MemberRegistration with ClassLoader ModuleClassLoader for Module "deployment.dtest-ear.ear.dtest-ejb.jar:main" from Service Module Loader
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:70)
at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:57)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.handleAnnotations(InterceptorAnnotationProcessor.java:107)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:92)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:77)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:156)
... 5 more
Caused by: java.lang.NoClassDefFoundError: Ljavax/enterprise/event/Event;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2575)
at java.lang.Class.getDeclaredFields(Class.java:1908)
at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:57)
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66)
... 10 more
Caused by: java.lang.ClassNotFoundException: javax.enterprise.event.Event from [Module "deployment.dtest-ear.ear.dtest-ejb.jar:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)
... 15 more

我不知道为什么 cdi-api.jar 不使用 wildfly jar。

<dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <scope>provided</scope>
    </dependency>

我删除了 - 提供。 (cdi-api.jar打包到app.ear) 应用程序在 Wildfly 上运行。 但是在调用http://localhost:7001/dtest-web/rest/members 之后我有错误,因为所有@Inject 对象都为空。

ERROR [io.undertow.request] (default task-5) UT005023: Exception handling request to /dtest-web/rest/members: org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76)
at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212)
at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

enter image description here

发生了什么事?谁能有一个最小的例子 REST + EJB?


@Path("/members")
@RequestScoped
public class MemberResourceRESTService 
@Inject
private Logger log;

@Inject
private Validator validator;

@Inject
private MemberRepository repository;

@Inject
MemberRegistration registration;

@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Member> listAllMembers() 
    return repository.findAllOrderedByName();


@GET
@Path("/id:[0-9][0-9]*")
@Produces(MediaType.APPLICATION_JSON)
public Member lookupMemberById(@PathParam("id") long id) 
    Member member = repository.findById(id);
    if (member == null) 
        throw new WebApplicationException(Response.Status.NOT_FOUND);
    
    return member;

【问题讨论】:

你能告诉你的类从哪里调用它吗? 【参考方案1】:

部署似乎有问题。

我无法直接解决您问题的原因,但可能最简单的解决方案是将部署模型从 EAR 更改为 WAR 存档。

PS。另请确保您使用的不是不稳定的 WildFly 版本。

【讨论】:

WildFly 配置有问题。谢谢!

以上是关于java.lang.ClassNotFoundException:javax.enterprise.event.Event的主要内容,如果未能解决你的问题,请参考以下文章