我使用JavaEE创建了REST服务,但是无法部署它。 我只有1个资源类,如下所示:
@Stateless
@Path("messages")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public class ApproverResource {
public ApproverResource() {
}
@EJB
ApproverDao approverDao;
@GET
public JsonArray findAll() {
JsonArrayBuilder list = Json.createArrayBuilder();
List<Approver> all = this.approverDao.findAll();
//all.stream().map(m -> m.toJson().forEach(list::add));
return list.build();
}
@GET
@Path("{id}")
public JsonObject findById(@PathParam("id") Long id) {
Approver approver = this.approverDao.findById(id);
return approver.toJson();
}
@POST
public Response create(@Valid Approver approver) {
this.approverDao.create(approver);
return Response.ok().build();
}
}
当我尝试部署到wildfly(13.0)时,出现以下异常:
18:20:07,690 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC000001: Failed to start service jboss.deployment.unit."TMS.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."TMS.war".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment "TMS.war"
at org.jboss.as.server@5.0.0.Final//org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:150)
at org.jboss.msc@1.4.2.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1736)
at org.jboss.msc@1.4.2.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1698)
at org.jboss.msc@1.4.2.Final//org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1556)
at org.jboss.threads@2.3.2.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads@2.3.2.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
at org.jboss.threads@2.3.2.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
at org.jboss.threads@2.3.2.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1364)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEE0024: Could not configure component ApproverResource
at org.jboss.as.ee@13.0.0.Final//org.jboss.as.ee.component.deployers.EEModuleConfigurationProcessor.deploy(EEModuleConfigurationProcessor.java:106)
at org.jboss.as.server@5.0.0.Final//org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:143)
... 8 more
Caused by: java.lang.NoSuchMethodError: sun.misc.Unsafe.defineClass(Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class;
at org.jboss.classfilewriter@1.2.2.Final//org.jboss.classfilewriter.ClassFile.defineInternal(ClassFile.java:285)
at org.jboss.classfilewriter@1.2.2.Final//org.jboss.classfilewriter.ClassFile.define(ClassFile.java:267)
at org.jboss.invocation@1.5.1.Final//org.jboss.invocation.proxy.AbstractClassFactory.defineClass(AbstractClassFactory.java:160)
at org.jboss.invocation@1.5.1.Final//org.jboss.invocation.proxy.AbstractProxyFactory.getCachedMethods(AbstractProxyFactory.java:146)
at org.jboss.as.ejb3@13.0.0.Final//org.jboss.as.ejb3.component.stateless.StatelessComponentDescription$3.configure(StatelessComponentDescription.java:145)
at org.jboss.as.ee@13.0.0.Final//org.jboss.as.ee.component.DefaultComponentViewConfigurator.configure(DefaultComponentViewConfigurator.java:67)
at org.jboss.as.ee@13.0.0.Final//org.jboss.as.ee.component.deployers.EEModuleConfigurationProcessor.deploy(EEModuleConfigurationProcessor.java:92)
... 9 more
18:20:07,719 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {
"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"TMS.war\".INSTALL" => "WFLYSRV0153: Failed to process phase INSTALL of deployment \"TMS.war\"
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEE0024: Could not configure component ApproverResource
Caused by: java.lang.NoSuchMethodError: sun.misc.Unsafe.defineClass(Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class;"},
"WFLYCTL0412: Required services that are not installed:" => [
"jboss.deployment.unit.\"TMS.war\".WeldStartService",
"jboss.deployment.unit.\"TMS.war\".beanmanager"
],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.deployment.unit.\"TMS.war\".batch.artifact.factory is missing [jboss.deployment.unit.\"TMS.war\".beanmanager]",
"jboss.deployment.unit.\"TMS.war\".weld.weldClassIntrospector is missing [jboss.deployment.unit.\"TMS.war\".WeldStartService, jboss.deployment.unit.\"TMS.war\".beanmanager]"
]
基于创建默认构造函数的方法,我阅读了类似的答案,检查了wildfly和项目是否使用相同的jdk,但我无法使其正常工作。