Why is my WebApplicationInitializer not loaded
See original GitHub issueI have a really simple Spring-Boot application and I wonder why my WebApplicationInitializer is not recognized by SpringServletContainerInitializer?
At application startup in console everythings looks fine, but there is no System.err-output from the Initializer. Also, if I set a breakpoint inside the onStartup method it is never reached.
Did I miss anything?
Thanks.
My classes:
package de.tbosch.web.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
package de.tbosch.web.springboot;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.springframework.web.WebApplicationInitializer;
public class Initializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
System.err.println("------------------------------------");
}
}
Details: https://github.com/dickerpulli/playground/tree/master/web/spring-boot
Issue Analytics
- State:
- Created 10 years ago
- Comments:15 (5 by maintainers)
Top Results From Across the Web
spring - WebApplicationInitializer not loading - Stack Overflow
I am using tomcat 7. The problem remains there even if I remove hibernate dependency and update the project. What can be the...
Read more >Spring WebApplicationInitializer - Java Development Journal
A quick and practical guide to Spring WebApplicationInitializer. ... One of the natural questions will arise in your mind is “If we are...
Read more >Spring WebApplicationInitializer tutorial - ZetCode
Spring WebApplicationInitializer tutorial shows how to bootstrap Spring web applications programatically with WebApplicationInitializer.
Read more >[Solved]-WebApplicationInitializer not reached-Spring MVC
Coding example for the question WebApplicationInitializer not reached-Spring MVC. ... your pom.xml file is missing the dependency:spring-context-support ...
Read more >WebApplicationInitializer (Spring Framework 6.0.2 API)
The code-based approach with WebApplicationInitializer ... Even if a component (e.g. non-Spring, other third party) has not been specifically updated for ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Great hints …
Now I solved it just with using a ServletContextInitializer instead of WebApplicationInitializer and added this one to my spring context.
With declaring it as
@Configuration
I can add it in the main-Method as follows… and it’s getting loaded.
Thanks a lot!
I have a Spring Boot project with a WebApplicationInitializer - the initializer works fine when I build a war and deploy it to a standalone Tomcat 7. However if I build my Spring Boot app as an executable jar with an embedded Tomcat 7, the WebApplicationInitialier is NOT called when the application is started.
For my project I need to deliver a war file, so it is not a big problem for me, but it would be nice to get this to work the same way regardless of using the embedded Tomcat or deploying to a standalone Tomcat.
I found an old issue on the Tomcat issue tracker that might be related to why my WebApplicationInitializer is not found - apparently the class has to be in a JAR file for the Tomcat scanner to find it. It should be possible to work around - by doing what Mark suggests in comment #19 - https://issues.apache.org/bugzilla/show_bug.cgi?id=52853#c19.
As for other ways to register servlets/filters in a Spring Boot Web application you should be able to create a @Bean in your configuration that returns a Servlet, or Filter - have a look at http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-add-a-servlet-filter-or-servletcontextlistener
Cheers Flemming
On 18 Mar 2014, at 20:53, Thomas Bosch notifications@github.com wrote: