从swagger编辑器生成JAX-RS服务器无法正常工作

时间:2016-05-08 15:36:30

标签: java jax-rs swagger tomee

我尝试使用swagger编辑器(http://editor.swagger.io/#/)从文档中生成JAX-RS服务器。

我选择Generate Server - > JAX-RS并尝试在Apache上运行代码 TomEE 1.7.4并收到以下错误:

  

org.apache.catalina.LifecycleException:无效的生命周期   尝试过渡([before_destroy])组件   [StandardEngine [卡塔利娜] .StandardHost [本地主机] .StandardContext []]   在州[STARTING_PREP]处   org.apache.catalina.util.LifecycleBase.invalidTransition(LifecycleBase.java:401)     在   org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:291)     在   org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:1038)     在   org.apache.tomee.catalina.TomcatWebAppBuilder.undeploy(TomcatWebAppBuilder.java:1537)     在   org.apache.tomee.catalina.TomcatWebAppBuilder.undeploy(TomcatWebAppBuilder.java:1518)     在   org.apache.tomee.catalina.TomcatWebAppBuilder.undeployWebApps(TomcatWebAppBuilder.java:762)     在   org.apache.openejb.assembler.classic.Assembler.destroyApplication(Assembler.java:1982)     在   org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:839)     在   org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:677)     在   org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1261)     在   org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1100)     在   org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:130)     在   org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)     在   org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)     在   org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5472)     在   org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)     在   org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)     在   org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)     在   org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)     在   org.apache.tomee.catalina.TomcatWebAppBuilder.deployWar(TomcatWebAppBuilder.java:663)     在   org.apache.tomee.catalina.TomcatWebAppBuilder.deployWebApps(TomcatWebAppBuilder.java:622)     在   org.apache.tomee.catalina.deployment.TomcatWebappDeployer.deploy(TomcatWebappDeployer.java:43)     在   org.apache.openejb.assembler.DeployerEjb.deploy(DeployerEjb.java:176)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:497)at   org.apache.openejb.core.interceptor.ReflectionInvocationContext $ Invocation.invoke(ReflectionInvocationContext.java:192)     在   org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173)     在   org.apache.openejb.security.internal.InternalSecurityInterceptor.invoke(InternalSecurityInterceptor.java:35)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:497)at   org.apache.openejb.core.interceptor.ReflectionInvocationContext $ Invocation.invoke(ReflectionInvocationContext.java:192)     在   org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173)     在   org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:181)     在   org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:100)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:497)at   org.apache.openejb.core.interceptor.ReflectionInvocationContext $ Invocation.invoke(ReflectionInvocationContext.java:192)     在   org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173)     在   org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:85)     在   org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:227)     在   org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:194)     在   org.apache.openejb.server.ejbd.EjbRequestHandler.doEjbObject_BUSINESS_METHOD(EjbRequestHandler.java:370)     在   org.apache.openejb.server.ejbd.EjbRequestHandler.processRequest(EjbRequestHandler.java:181)     在   org.apache.openejb.server.ejbd.EjbDaemon.processEjbRequest(EjbDaemon.java:344)     在   org.apache.openejb.server.ejbd.EjbDaemon.service(EjbDaemon.java:240)     在   org.apache.openejb.server.ejbd.EjbServer.service(EjbServer.java:104)     在   org.apache.openejb.server.httpd.ServerServlet.service(ServerServlet.java:58)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:731)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)     在   org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)     在   org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)     在   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:625)     在   org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:318)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617)     在   org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)     在java.lang.Thread.run(Thread.java:745)

2 个答案:

答案 0 :(得分:0)

问题是" JAX-RS"在swagger编辑器上并不意味着" JAX-RS"但是" jersey"。在TomEE中提供了JAX-RS,因此您可以从pom中删除几乎所有依赖项。

Swagger也有" CXF" JAX-RS服务器的味道,它适合更好的TomEE默认堆栈。

答案 1 :(得分:0)

您确定要正确构建WAR包吗?

要在TomEE上运行,您必须通过更改打包来更新pom.xml,如下所示:

<packaging>war</packaging>

然后,为了与maven一起运行,你可以添加tomee-maven-plugin(pom.xml):

<plugins>
...
<plugin>
  <groupId>org.apache.openejb.maven</groupId>
  <artifactId>tomee-maven-plugin</artifactId>
  <version>1.7.4</version>
  <configuration>
    <tomeeVersion>1.7.4</tomeeVersion>
    <tomeeClassifier>plus</tomeeClassifier>
  </configuration>
</plugin>
...
</plugins>

最后:

mvn clean package
mvn tomee:run

Voilà

  

http://localhost:8080/swagger-jaxrs-server-1.0.0/有效!