0

spring boot zk WebAppInit error

asked 2016-08-03 13:32:46 +0800

aweder gravatar image aweder
0

2016-08-03 21:24:02.447 ERROR 6620 --- [main] org.zkoss.zk.ui.util.Configuration : Failed to invoke class org.zkoss.zkmax.init.WebAppInit

java.lang.IllegalStateException: Servlets can not be added to context as the context has been initialised at org.apache.catalina.core.ApplicationContext.addServlet(ApplicationContext.java:1080) ~[tomcat-embed-core-8.0.36.jar:8.0.36] at org.apache.catalina.core.ApplicationContext.addServlet(ApplicationContext.java:1067) ~[tomcat-embed-core-8.0.36.jar:8.0.36] at org.apache.catalina.core.ApplicationContextFacade.addServlet(ApplicationContextFacade.java:535) ~[tomcat-embed-core-8.0.36.jar:8.0.36] at org.zkoss.zkmax.ui.comet.CometAsyncServlet.install(CometAsyncServlet.java:56) ~[zkmax-8.0.1.1-Eval.jar:8.0.1.1] at org.zkoss.zkmax.init.WebAppInit.init(WebAppInit.java:33) ~[zkmax-8.0.1.1-Eval.jar:8.0.1.1] at org.zkoss.zk.ui.util.Configuration.invokeWebAppInits(Configuration.java:779) ~[zk-8.0.1.1.jar:8.0.1.1] at org.zkoss.zk.ui.impl.AbstractWebApp.init(AbstractWebApp.java:204) [zk-8.0.1.1.jar:8.0.1.1] at org.zkoss.zk.ui.http.SimpleWebApp.init(SimpleWebApp.java:58) [zk-8.0.1.1.jar:8.0.1.1] at org.zkoss.zk.ui.http.WebManager.<init>(WebManager.java:228) [zk-8.0.1.1.jar:8.0.1.1] at org.zkoss.zk.ui.http.DHtmlLayoutServlet.init(DHtmlLayoutServlet.java:102) [zk-8.0.1.1.jar:8.0.1.1] at javax.servlet.GenericServlet.init(GenericServlet.java:158) [tomcat-embed-core-8.0.36.jar:8.0.36] at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1238) [tomcat-embed-core-8.0.36.jar:8.0.36] at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1041) [tomcat-embed-core-8.0.36.jar:8.0.36] at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5027) [tomcat-embed-core-8.0.36.jar:8.0.36] at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedContext.deferredLoadOnStartup(TomcatEmbeddedContext.java:68) [spring-boot-1.3.7.RELEASE.jar:1.3.7.RELEASE] at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.startConnector(TomcatEmbeddedServletContainer.java:217) [spring-boot-1.3.7.RELEASE.jar:1.3.7.RELEASE] at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:154) [spring-boot-1.3.7.RELEASE.jar:1.3.7.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:293) [spring-boot-1.3.7.RELEASE.jar:1.3.7.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:141) [spring-boot-1.3.7.RELEASE.jar:1.3.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) [spring-context-4.2.7.RELEASE.jar:4.2.7.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) [spring-boot-1.3.7.RELEASE.jar:1.3.7.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:760) [spring-boot-1.3.7.RELEASE.jar:1.3.7.RELEASE] at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:360) [spring-boot-1.3.7.RELEASE.jar:1.3.7.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:306) [spring-boot-1.3.7.RELEASE.jar:1.3.7.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.3.7.RELEASE.jar:1.3.7.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.3.7.RELEASE.jar:1.3.7.RELEASE] at cn.zensoft.evcharge.EvApplication.main(EvApplication.java:19) [classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.060] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.060] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.060] at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.060] at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:478) [spring-boot-maven-plugin-1.3.7.RELEASE.jar:1.3.7.RELEASE] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]

@Configuration public class ServletsConfig {

@Bean
public ServletRegistrationBean dHtmlLayoutServlet() {
    Map<String, String> params = new HashMap<>();
    params.put("update-uri", "/zkau");
    Set<String> mappings = new HashSet<>();
    mappings.add("*.zul");
    mappings.add("*.zhtml");
    ServletRegistrationBean bean = new ServletRegistrationBean(new DHtmlLayoutServlet());
    bean.setLoadOnStartup(1);
    bean.setInitParameters(params);
    bean.setUrlMappings(mappings);
    return bean;
}

@Bean
public ServletRegistrationBean dHtmlUpdateServlet() {
    ServletRegistrationBean bean = new ServletRegistrationBean(new DHtmlUpdateServlet(), "/zkau/*");
    bean.setLoadOnStartup(2);
    return bean;
}

@Bean
public HttpSessionListener httpSessionListener() {
    return new HttpSessionListener();
}

}

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-11-23 17:57:08 +0800

cor3000 gravatar image cor3000
3494 1 7
ZK Team

an updated (for ZK 8.5) runnable zk-spring-boot starter project is available here: https://github.com/zkoss-demo/zk-spring-boot

read more: https://www.zkoss.org/wiki/ZKInstallationGuide/QuickStart/CreateandRunYourFirstZKApplicationwithSpringBoot

link publish delete flag offensive edit
-1

answered 2017-01-16 08:06:38 +0800

cor3000 gravatar image cor3000
3494 1 7
ZK Team

updated 2017-11-23 17:59:19 +0800

UPDATE: starter project available http://forum.zkoss.org/question/101283/spring-boot-zk-webappinit-error/?answer=109673#post-id-109673

When using ZK EE there is a 3rd Servlet (CometAsynchServlet) which needs to be configured for spring boot before the other servlets.

@Bean
public ServletRegistrationBean cometAsyncServlet() {
    CometAsyncServlet cometAsyncServlet = new CometAsyncServlet();
    ServletRegistrationBean reg = 
        new ServletRegistrationBean(cometAsyncServlet, "/zkcomet/*");
    reg.setAsyncSupported(true);
    reg.setLoadOnStartup(1);
    return reg;
}

@Bean
public ServletRegistrationBean dHtmlLayoutServlet() {
    ...
    bean.setLoadOnStartup(2);
    ...
}

@Bean
public ServletRegistrationBean dHtmlUpdateServlet() {
    ...
    bean.setLoadOnStartup(3);
    ...
}

Note the order 1/2/3 when callign setLoadOnStartup()

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2016-08-03 13:32:46 +0800

Seen: 48 times

Last updated: Nov 23