2016-05-08 86 views
0

我試圖用swagger編輯器(http://editor.swagger.io/#/)從文檔生成JAX-RS服務器。從swagger編輯器生成JAX-RS服務器不起作用

我選擇生成服務器 - > JAX-RS,並試圖在Apache TomEE 1.7.4運行代碼,並得到了以下錯誤:

org.apache.catalina.LifecycleException: An invalid Lifecycle transition was attempted ([before_destroy]) for component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]] in state [STARTING_PREP] at org.apache.catalina.util.LifecycleBase.invalidTransition(LifecycleBase.java:401) at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:291) at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:1038) at org.apache.tomee.catalina.TomcatWebAppBuilder.undeploy(TomcatWebAppBuilder.java:1537) at org.apache.tomee.catalina.TomcatWebAppBuilder.undeploy(TomcatWebAppBuilder.java:1518) at org.apache.tomee.catalina.TomcatWebAppBuilder.undeployWebApps(TomcatWebAppBuilder.java:762) at org.apache.openejb.assembler.classic.Assembler.destroyApplication(Assembler.java:1982) at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:839) at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:677) at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1261) at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1100) at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:130) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117) at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5472) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652) at org.apache.tomee.catalina.TomcatWebAppBuilder.deployWar(TomcatWebAppBuilder.java:663) at org.apache.tomee.catalina.TomcatWebAppBuilder.deployWebApps(TomcatWebAppBuilder.java:622) at org.apache.tomee.catalina.deployment.TomcatWebappDeployer.deploy(TomcatWebappDeployer.java:43) at org.apache.openejb.assembler.DeployerEjb.deploy(DeployerEjb.java:176) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:192) at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173) at 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) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:192) at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173) at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:181) at org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:100) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:192) at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173) at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:85) at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:227) at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:194) at org.apache.openejb.server.ejbd.EjbRequestHandler.doEjbObject_BUSINESS_METHOD(EjbRequestHandler.java:370) at org.apache.openejb.server.ejbd.EjbRequestHandler.processRequest(EjbRequestHandler.java:181) at org.apache.openejb.server.ejbd.EjbDaemon.processEjbRequest(EjbDaemon.java:344) at org.apache.openejb.server.ejbd.EjbDaemon.service(EjbDaemon.java:240) at org.apache.openejb.server.ejbd.EjbServer.service(EjbServer.java:104) at org.apache.openejb.server.httpd.ServerServlet.service(ServerServlet.java:58) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

+0

貼完整的錯誤堆棧跟蹤 –

+0

@GautamSavaliya添加,還可以生成從http://editor.swagger.io/#/代碼,看看是否可以運行它。謝謝! –

+0

我可以用'mvn jetty:run'運行jaxrs服務器存根。您遇到的問題可能會指定給Apache TomEE –

回答

0

問題是 「JAX-RS」 上招搖編輯器沒有按不是指「JAX-RS」,而是「球衣」。在TomEE中提供了JAX-RS,因此您可以從pom中刪除幾乎所有的依賴關係。

Swagger也具有JAX-RS服務器的「CXF」風格,這將適合更好的TomEE默認堆棧。

0

您確定要正確構建WAR包嗎?

要在TomEE運行,必須通過改變包裝如下更新pom.xml中:

<packaging>war</packaging> 

那麼對於使用Maven運行,您可以添加tomee - Maven的插件(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 

而且

http://localhost:8080/swagger-jaxrs-server-1.0.0/ works!