0

zk spring boot payara 5 deployment error

asked 2020-11-29 06:18:37 +0800

RomanZK gravatar image RomanZK
1 1

updated 2020-11-29 15:56:31 +0800

I get the following error when deploying my zk spring boot app to payara 5 app server.

Caused by: java.lang.IllegalStateException: ServletConfig has not been initialized at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:200) at org.springframework.web.servlet.FrameworkServlet.destroy(FrameworkServlet.java:863) at org.apache.catalina.core.StandardWrapper.unload(StandardWrapper.java:1797) ... 78 more ----- Root Cause -----

Caused by: java.lang.IllegalStateException: ZK WebManager already exists. Could not initialize via Spring Boot configuration. at org.zkoss.zkspringboot.ZkAutoConfiguration$1.contextInitialized(ZkAutoConfiguration.java:90) at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:5178) at com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:681) at org.apache.catalina.core.StandardContext.start(StandardContext.java:5756) ... 73 more

This only happens when I use the zk spring boot starter. I have deployed a normal spring mvc app (i.e. without zk) to payara 5 and it works fine.

I have been able to trace the exact line to ZkAutoConfiguration.java:90 in the zk spring boot autoconfig jar.

I have no intention of using zats for this deployment to payara 5. Any ideas what could be the issue ?

Would appreciate help on this.

I am using zk 9.0.0.1 CE.

Regards,

delete flag offensive retag edit

11 Answers

Sort by ยป oldest newest most voted
0

answered 2020-11-30 09:50:36 +0800

cor3000 gravatar image cor3000
5868 2 7
ZK Team

updated 2020-12-01 10:39:05 +0800

In order to deploy a springboot application into an existing application server (e.g. paraya/tomcat/wildfly ...) I assume you are building a war-file. When doing so you have to also configure zkspringboot to activate the war-file specific configuration.

this means the configuration should configure the HttpSessionListener in lines 78-80 and NOT run the block in lines 81-100

You have to set the application property:

zk.springboot-packaging=war

Then also remove the HttpSessionListener from your web.xml in case you added it.

If you prefer to configure ZK manually in your web.xml/zk.xml you don't need zkspringboot-autoconfig, especially in a war file desployment all the classical (without spring boot) configuration options are available.

In case my assumption was wrong about the deployment type please provide the related configuration leading to this error.


Besides this has nothing to do with ZATS, if you read the code carefully the configuration only activates when ZATS is NOT on the classpath (Line 76 @ConditionalOnMissingClass)

@ConditionalOnMissingClass("org.zkoss.zats.mimic.Zats")
link publish delete flag offensive edit
0

answered 2020-12-01 17:16:56 +0800

RomanZK gravatar image RomanZK
1 1

I am using zk spring boot.

I have added the configuration zk.springbootPackaging=war

It finally deployed. However I am unable to access the log in page.

I get an error 404 /login.zul the requested resource is not available.

I have open the war file. I can see that the login.zul page inside it. it is located in the classes folder.

Any ideas why I am getting error 404 ?

link publish delete flag offensive edit
0

answered 2020-12-01 17:39:30 +0800

cor3000 gravatar image cor3000
5868 2 7
ZK Team

updated 2020-12-01 17:39:46 +0800

yes a 404 occurs if the web application can't locate the resource based on its configuration. Most likely there is not servlet or view resolver configured to search in your classpath. Without your whole application source code it's hard to tell. Spring boot offers many configuration options.

Here our demo for a minimal war file, maybe you can find the difference to your setup or adapt the example to your requirements.

https://github.com/zkoss/zkspringboot/tree/master/zkspringboot-demos/zkspringboot-minimal-war

link publish delete flag offensive edit
0

answered 2020-12-01 18:18:55 +0800

RomanZK gravatar image RomanZK
1 1

Thanks for sharing an example. I have studied the one you shared. For now I can point out four differences.

  1. In your pom.xml I can see you added javax.servlet as a dependency.

  2. Also in the pom.xml, I can the executions maven tag.

  3. I have also noticed that the minimal.zul is located in the webapp folder.

  4. The server context path is commented out.

For no 1 and 2, I will simply modify my pom.xml accordingly.

for no 3, I think there is a misunderstanding here. In the zk spring boot tutorial I was instructed to create a "web" folder under src/main/resources. All .zul should be placed in this folder. In the example you shared, the minimal.zul is placed under the "webapp" folder.

Note: I am using spring security so I have already configured my .zul to be under src/main/resources/web

for no 4, I have configured a context path for my app. I cannot use the root "/" as payara already maps localhost:8080 to as it's default index page.

link publish delete flag offensive edit
0

answered 2020-12-02 16:00:28 +0800

cor3000 gravatar image cor3000
5868 2 7
ZK Team

for no 3, I think there is a misunderstanding here. In the zk spring boot tutorial I was instructed to create a "web" folder under src/main/resources.

sounds like a misunderstanding ... all these changes are only necessary when packaging as self runnable spring boot .jar file

for a .war file you can just keep the file structure as in any other zk web application

src/main/webapp

When packaging a spring boot application as a .jar file the src/main/webapp folder (including WEB-INF) is not available, that's why the alternative folder locations need to be chosen below src/main/resources/web. zk-springboot-autoconfig will adjust the configuration to either the war or the jar file model automatically.

e.g. in the ".war" scenario the view resolver will look for zul files in the src/main/webapp folder (webcontent) and no longer under src/main/resources (classpath) as you can see in the source code.

https://github.com/zkoss/zkspringboot/blob/v2.3.1/zkspringboot-autoconfig/src/main/java/org/zkoss/zkspringboot/ZkWebMvcConfiguration.java#L28-L32

The autoconfig module just assumes the natural default for war- and jar-files packaging. That doesn't mean this is set in stone. You can disable the built-in view resolver and configure your own, spring mvc is quite flexible there. Even Spring-mvc is optional in case of a war file deployment. ZK's default servlet will still handle zul files as enabled here:

https://github.com/zkoss/zkspringboot/blob/v2.3.1/zkspringboot-autoconfig/src/main/java/org/zkoss/zkspringboot/ZkAutoConfiguration.java#L39

link publish delete flag offensive edit
0

answered 2020-12-04 00:32:51 +0800

RomanZK gravatar image RomanZK
1 1

Thank you for the clarification. I guess my situation is unique then. For the current web app I am working on I am using zk and spring boot to develop the app but my target deployment for production is payara.

I don't think it will be feasible to make duplicate copies of my zul files i.e. 1. src/main/resources/web 2. src/main/webapp.

This will certainly cause lot of problems.

My questions are as follows is it possible to

  1. Still retain my .zul files in src/main/resources/web. Since I am developing using spring boot.

  2. can I configure the existing view resolver to look for the .zul files in src/main/resources/web during war deployment ? If this is not possible can I at least create a custom spring mvc view resolver to do this ?

To summarise I would want to stick with zk and spring boot for development and still be able to deploy to payara for production.

Changing production app server might be a tricky thing to do at the moment.

link publish delete flag offensive edit
0

answered 2020-12-07 09:46:34 +0800

cor3000 gravatar image cor3000
5868 2 7
ZK Team

I agree duplicating the files is nonsense ... what I don't fully understand is the benefit of switching the deployment methods between dev and production. I'd suggest just creating a war file in both cases, you can still run a war application efficiently during development without spring boot (e.g. using jetty-runner or webapp-runner) however that's just my preference. Spring boot should also be possible it's just more of a challenge. Anyway I don't need to agree and understand everyone's intentions and preference so here the answers to your question.

  1. (not really a question but) that's possible just keep them there, ZK will be able to handle them as long as you resolve them correctly in your custom view resolver.

  2. yes configuring your own view resolver is definitely possible, simply disable the one provided within zkspringboot (in application.properties: zk.zul-view-resolver-enabled=false ) and configure/implement one as needed.

Here the code how zkspringboot implements the view resolver depending on the war/jar packaging option for your reference:

https://github.com/zkoss/zkspringboot/blob/v2.3.1/zkspringboot-autoconfig/src/main/java/org/zkoss/zkspringboot/ZkWebMvcConfiguration.java

link publish delete flag offensive edit
0

answered 2020-12-07 21:50:50 +0800

RomanZK gravatar image RomanZK
1 1

updated 2020-12-08 10:31:49 +0800

cor3000 gravatar image cor3000
5868 2 7
ZK Team

I have attempted disabling the default zk view resolver

zk.zul-view-resolver-enabled=false
zk.springbootPackaging=war

I have written my own. It's still not working. I don't think my custom view resolver is being invoked. I added log messages to check this.

link publish delete flag offensive edit
0

answered 2020-12-07 21:58:04 +0800

RomanZK gravatar image RomanZK
1 1

updated 2020-12-08 10:32:04 +0800

cor3000 gravatar image cor3000
5868 2 7
ZK Team

I have noticed that if I enable

zk.zul-view-resolver-enabled=true

In the log file I can see that my custom view resolver is initialised then immediately after the default zk mvc view resolver is initialised as well.

if i set it to

zk.zul-view-resolver-enabled=false

non of them get initialized.

link publish delete flag offensive edit
0

answered 2020-12-08 10:49:41 +0800

cor3000 gravatar image cor3000
5868 2 7
ZK Team

updated 2020-12-09 10:28:59 +0800

I tried what you describe and I can't see a problem

configure war packaging / disable the provided view resolver:

zk.springbootPackaging=war
zk.zul-view-resolver-enabled=false

register my own view resolver:

@SpringBootApplication
@Controller
public class Application implements WebMvcConfigurer {

    public static void main(String[] args) throws Throwable {
        SpringApplication.run(Application.class, args);
    }

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        // just hard coding one possible prefix/suffix here (your path might be different)
        registry.viewResolver(new InternalResourceViewResolver("/zkau/web/zul/", ".zul"));
    }
}

This just works, since you forgot to provide the relevant configuration I can't comment on that.

link publish delete flag offensive edit

Comments

since your case sounds very specific I am not sure the general public will benefit from this also if you can't share your code in a public forum please contact our support for dedicated help including remote debug sessions: https://www.zkoss.org/support

cor3000 ( 2020-12-08 10:52:00 +0800 )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
1 follower

RSS

Stats

Asked: 2020-11-29 06:18:37 +0800

Seen: 17 times

Last updated: Dec 14 '20

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More