Tobias Gassmann
Tobias Gassmann

Reputation: 11819

WebApplicationInitializer Simple Example

I need a simple example how to use the WebApplicationInitializer. I have seen plenty of sample implementations, but where do I declare that my individual MyVeryIndividualWebApplicationInitializer should be used?

Do I declare this in the pom-file, or whereever?

Upvotes: 0

Views: 1207

Answers (1)

Avinash
Avinash

Reputation: 4279

Since Servlet 3.0, it is possible to create web application without using any xml configuration, precisely web.xml. WebApplicationInitializer is an Interface provided by Spring to be implemented in Servlet 3.0+ environments in order to configure the ServletContext programmatically -- as opposed to (or possibly in conjunction with) the traditional web.xml-based approach.

If you are using Spring Boot you can use SpringBootServletInitializer which is a handy opinionated WebApplicationInitializer for applications that only have one Spring servlet, and no more than a single filter (which itself is only enabled when Spring Security is detected). If your application is more complicated consider using one of the other WebApplicationInitializers.

Note that a WebApplicationInitializer is only needed if you are building a war file and deploying it. If you prefer to run an embedded container (we do) then you won't need this at all.

Ref: http://docs.spring.io/spring-boot/docs/0.5.0.M4/api/org/springframework/boot/web/SpringBootServletInitializer.html

http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/WebApplicationInitializer.html

Do I declare this in the pom-file, or wherever?

Since WebApplicationInitializer is part of Spring Web MVC, you dont need any explicit declaration in pom file for WebApplicationInitializer.

Upvotes: 1

Related Questions