Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add HowTo configure wicket-spring-boot with Standalone Tomcat to documentation #115

Closed
eximius313 opened this issue Jun 28, 2017 · 17 comments
Milestone

Comments

@eximius313
Copy link

I have standalone Tomcat and I wanted to deploy created war with wicket-spring-boot on it.
After hours of struggling I finally found this example and basicaly I ended up with:

  1. Create NEW class and place it next to your WicketApplication.class
public class WarInitializer extends SpringBootServletInitializer {

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(WicketApplication.class);
	}
}
  1. Add the following to your build.gradle
apply plugin: 'war'

war {
    version =  '0.0.1'
}

dependencies {
    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}

and that's it....

@martin-g
Copy link
Contributor

extends SpringBootServletInitializer + return application.sources(WicketApplication.class); is standard Spring Boot setup for standalone deployment.
I am not sure why you spend so much time on it.
Maybe Spring Boot docs should make it more clear ?!

@eximius313
Copy link
Author

eximius313 commented Jun 28, 2017

Well, first of all I thought that I'm not using "pure" Spring Boot application, but Wicket one, so I started carefully looking for the information on your page.

Then I was googling around for "spring boot standalone tomcat", but everything suggested extending SpringBootServletInitializer! Look at this article which says:

You’ll need to make three intuitive changes: 
1. move from a jar build to a war build in Maven: comment out the declaration of the spring-boot-maven-plugin plugin in your pom.xml file, 
2. then change the Maven packaging type to war. 
3. Finally, add a web entry point into your application. Spring configures almost everything for you using Servlet 3 Java configuration. You just need to give it the opportunity. Modify your Application entry-point class thusly:

"Modify your Application entry-point class" (which occured to be not true... And point 1. is also not required - works fine for me without changint it).

Because my Application class was already extending WicketBootSecuredWebApplication I was looking for other solutions. Finally on StackOverflow somebody pointed out, that one doesn't have to "modify" current Application class - it can be separate class, which is just placed in the classpath. This was the information I was needing!
Simple as that - "create new class and place it on your classpath"

@eximius313
Copy link
Author

have you changed anything?

@MarcGiffing MarcGiffing reopened this Jul 17, 2017
@MarcGiffing
Copy link
Owner

Sorry I thought that you've already provided the solution...

@MarcGiffing
Copy link
Owner

Maybe @reckart can help? :)
see #117

@reckart
Copy link
Contributor

reckart commented Jul 17, 2017

I don't know how to help here. Maybe it helps to point you to my code (which is mostly working).

https://github.com/webanno/webanno/blob/master/webanno-webapp/src/main/java/de/tudarmstadt/ukp/clarin/webanno/webapp/WebAnno.java

@eximius313
Copy link
Author

I already found the solution while I was creating this request.
That is why the title is "Please add HowTo configure wicket-spring-boot with Standalone Tomcat to documentation" not "Please help me configure it"
I just wanted to help the others

@MarcGiffing
Copy link
Owner

Ah ok, sorry... I've missunterstood this request. I may also add a working example in the example repository.

@eximius313
Copy link
Author

Great ideal!

@MarcGiffing MarcGiffing added this to the 1.0.10 milestone Jul 30, 2017
@MarcGiffing
Copy link
Owner

You don't have to extend SpringBootServletInitializer. See the simple-war example. You only have to mark the spring-boot-starter-tomcat as provided. Only if you want to configure specific behaviour - see simple-war-websocket.

@eximius313
Copy link
Author

eximius313 commented Jul 30, 2017

I'm affraid you are wrong. I tried it with spring-boot-starter-tomcat as provided and without SpringBootServletInitializer in the classpath and it didn't work!
Once I put next to my WicketApplication class:

public class WarInitializer extends SpringBootServletInitializer {
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(WicketApplication.class);
	}
}

it started to work - this was the only change between working and not working solution.
If it worked exactly as Spring documentation said, I wouldn't have created this issue.

And you can also put:

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
	super.onStartup(servletContext);
	servletContext.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE));
}

for the (a little bit) more secure app

@MarcGiffing
Copy link
Owner

Hmm, but I could run it without extending SpringBootServletInitializer. See https://github.com/MarcGiffing/wicket-spring-boot-examples/tree/master/simple-war[simple-war].

Maybe you should provide a pull request for the documentation which I can take :)

@eximius313
Copy link
Author

Running the app works fine indeed, but if you create war and deploy it to standalone Tomcat without SpringBootServletInitializer class, the app will not start.
I can do pull request, but what I would do is add standalone SpringBootServletInitializer class to both simple-war-websocket and simple-war. If you want that, I can do pull request

@MarcGiffing
Copy link
Owner

That would be great. You can also update the Readme accordingly. Yes you can add a standalone SpringBootServletInitializer. Thanks!

@AlexeyKravtsov
Copy link

Running the app works fine indeed, but if you create war and deploy it to standalone Tomcat without SpringBootServletInitializer class, the app will not start.

I have similar issue. My app is extended WicketBootSecuredWebApplication and has @SpringBootApplication on it.
It is running fine if I run it as standalone app, however when I build it as .war file, tomcat fails to start it.
I have added
public class WarInitializer extends SpringBootServletInitializer {
@OverRide
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MyApplication.class);
}
}
without any annotations, so MyApplication is still annotated with @SpringBootApplication, and it fails in Tomcat with
23-Jun-2020 13:56:48.029 INFO [main] org.apache.catalina.core.ApplicationContext.log 2 Spring WebApplicationInitializers detected on classpath
23-Jun-2020 13:56:50.753 INFO [main] org.apache.catalina.core.ApplicationContext.log Initializing Spring embedded WebApplicationContext
23-Jun-2020 13:56:55.754 SEVERE [main] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [com.giffing.wicket.spring.boot.starter.web.servlet.websocket.WicketServerEndpointConfigRegister]
com.giffing.wicket.spring.boot.context.exceptions.WicketSpringBootException: javax.websocket.DeploymentException: Multiple Endpoints may not be deployed to the same path [/wicket/websocket] : existing endpoint was [class org.apache.wicket.protocol.ws.javax.WicketEndpoint] and new endpoint is [class org.apache.wicket.protocol.ws.javax.WicketEndpoint]
...

if I remove @SpringBootApplication annotation from MyApplication I am getting
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myApplication': Unsatisfied dependency expressed through field 'generalSettingsProperties'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.giffing.wicket.spring.boot.starter.configuration.extensions.core.settings.general.GeneralSettingsProperties' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.giffing.wicket.spring.boot.starter.configuration.extensions.core.settings.general.GeneralSettingsProperties' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

If I put @SpringBootApplication annotation on both of them I am getting multiple endpoints
23-Jun-2020 14:03:11.017 INFO [main] org.apache.catalina.core.ApplicationContext.log 2 Spring WebApplicationInitializers detected on classpath
23-Jun-2020 14:03:13.512 INFO [main] org.apache.catalina.core.ApplicationContext.log Initializing Spring embedded WebApplicationContext
23-Jun-2020 14:03:18.700 SEVERE [main] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [com.giffing.wicket.spring.boot.starter.web.servlet.websocket.WicketServerEndpointConfigRegister]
com.giffing.wicket.spring.boot.context.exceptions.WicketSpringBootException: javax.websocket.DeploymentException: Multiple Endpoints may not be deployed to the same path [/wicket/websocket] : existing endpoint was [class org.apache.wicket.protocol.ws.javax.WicketEndpoint] and new endpoint is [class org.apache.wicket.protocol.ws.javax.WicketEndpoint]

If I leave @SpringBootApplication annotation only on WarInitializer I am getting this
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myApplication': Unsatisfied dependency expressed through field 'generalSettingsProperties'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.giffing.wicket.spring.boot.starter.configuration.extensions.core.settings.general.GeneralSettingsProperties' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.giffing.wicket.spring.boot.starter.configuration.extensions.core.settings.general.GeneralSettingsProperties' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

How did you make it work with both WicketBootSecuredWebApplication and in tomcat.
I am also using wicket 8 if it matters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants