Open kkrgwbj opened 7 years ago
restful协议只是通过SPI扩展了protocol,与启动方式没有关联的。请可以给出一下具体报错异常栈,看看有没有什么线索。 建议可以先使用注解方式跑通一个标准motan协议的demo,然后在改成restful协议试试
Initialization of bean failed; nested exception is com.weibo.api.motan.exception.MotanFrameworkException: error_message: register error! Could not find extension for registry protocol:restful, make sure registry module for restful is in classpath!, status: 500, error_code: 20008,r=null
但是我确实引入有restful的包。
谢谢,已经可以了。
@rayzhang0603 虽然支持了,但是我发现了问题很多。因为目前很多项目都会基于springBoot方式开发,但是restful协议,如果想走标准的http请求离不开servlet容器,而boot是没有 web.xml配置文件的,能否提供servlt3.0类似的注解方式启动或者让restful完美兼容boot呢?感谢。
我用spring boot集成后控制台报错:
java.lang.UnsupportedOperationException: Section 4.4 of the Servlet 3.0 specification does not permit this method to be called from a ServletContextListener that was not defined in web.xml, a web-fragment.xml file nor annotated with @WebListener at org.apache.catalina.core.StandardContext$NoPluggabilityServletContext.setInitParameter(StandardContext.java:6549) ~[tomcat-embed-core-8.5.20.jar:8.5.20] at com.weibo.api.motan.protocol.restful.support.servlet.RestfulServletContainerListener.contextInitialized(RestfulServletContainerListener.java:34) ~[motan-protocol-restful-0.3.1.jar:na] at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4743) [tomcat-embed-core-8.5.20.jar:8.5.20] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207) [tomcat-embed-core-8.5.20.jar:8.5.20] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.20.jar:8.5.20] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) [tomcat-embed-core-8.5.20.jar:8.5.20] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) [tomcat-embed-core-8.5.20.jar:8.5.20] at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_79] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_79] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_79] at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79]
2017-10-03 22:52:09.959 ERROR 14804 --- [ost-startStop-1] o.apache.catalina.core.StandardContext : One or more listeners failed to start. Full details will be found in the appropriate container log file 2017-10-03 22:52:09.960 ERROR 14804 --- [ost-startStop-1] o.apache.catalina.core.StandardContext : Context [] startup failed due to previous errors 2017-10-03 22:52:09.963 ERROR 14804 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Exception sending context destroyed event to listener instance of class [com.weibo.api.motan.protocol.restful.support.servlet.RestfulServletContainerListener]
java.lang.NullPointerException: null at org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextDestroyed(ResteasyBootstrap.java:37) ~[resteasy-jaxrs-3.0.7.Final.jar:na] at com.weibo.api.motan.protocol.restful.support.servlet.RestfulServletContainerListener.contextDestroyed(RestfulServletContainerListener.java:45) ~[motan-protocol-restful-0.3.1.jar:na] at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4790) [tomcat-embed-core-8.5.20.jar:8.5.20] at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5429) [tomcat-embed-core-8.5.20.jar:8.5.20] at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:226) [tomcat-embed-core-8.5.20.jar:8.5.20] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) [tomcat-embed-core-8.5.20.jar:8.5.20] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) [tomcat-embed-core-8.5.20.jar:8.5.20] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) [tomcat-embed-core-8.5.20.jar:8.5.20] at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_79] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_79] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_79] at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79]
2017-10-03 22:52:09.972 WARN 14804 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat 2017-10-03 22:52:09.985 INFO 14804 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 2017-10-03 22:52:09.993 ERROR 14804 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
at com.xwtec.sso.SsoApplication.main(SsoApplication.java:25) [classes/:na]
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:123) ~[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.
我的源代码
@Bean public ServletRegistrationBean servletRegistrationBean(){ ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean();
servletRegistrationBean.setServlet(new HttpServletDispatcher());
servletRegistrationBean.addInitParameter("resteasy.servlet.mapping.prefix","/servlet");
servletRegistrationBean.addUrlMappings("/servlet/*");
servletRegistrationBean.setLoadOnStartup(1);
return servletRegistrationBean;
}
@Bean
public ServletListenerRegistrationBean listenerRegistrationBean(){
ServletListenerRegistrationBean listenerRegistrationBean = new ServletListenerRegistrationBean();
listenerRegistrationBean.setListener(new RestfulServletContainerListener());
return listenerRegistrationBean;
}
@kkrgwbj 非常感谢建议,后续版本会考虑增加@weblistener注解声明。 如果不使用web.xml的话, 可以试试使用ServletListenerRegistrationBean配置bean来完成listener注册
@rayzhang0603 我看了spring boot的文档,官方确实有这样的支持。但是我已经加过了,依然报错。可能是你们底层的用法在servlet后续版本得到了禁用。
@kkrgwbj 这个异常应该跟springboot的SpringBootServletInitializer加载顺序有关。建议使用独立rpc进程方式由motan监听的端口处理服务。 关于SpringBoot使用servlet方式导出restful协议的问题,会在后续的版本中解决。 如果想尝试解决此问题,可以参照RestfulServletContainerListener类实现支持springboot的listener,非常欢迎PR 另外,可以参考一下这两个issue中的方法。https://github.com/spring-projects/spring-boot/issues/2070 , https://github.com/spring-projects/spring-boot/issues/2098 中的方法试试。
请问找到解决方法了吗, 我也遇到了
@rayzhang0603 你好,我今天在demo的过程中,发现当用restful协议暴露后,用注解启动报错。是不是不支持注解?motan给的demo是用的配置文件做的。