Here is the question how to configure Spring MVC in SpringBoot Application.
SpringBoot solution is minimal configuration for integration of SpringModules.
A Complete integration and code clean up as per advance provided by Spring Boot.
- No web.xml & dispatcher-servlet.xml
- Required a main class ( extends SpringBootServletInitializer )
- Invoke static run method in SpringApplication
Spring Boot provides simple steps it involves following steps:
1. Add application.properties. 2. Configure Spring Application class. 3. Invoke SpringApplication class Thats All !!
Lets have look into it how to do practically.
- Add application.properties under resources.
# Add below properties # View resolver settings as below spring.mvc.view.prefix: /WEB-INF/view/ spring.mvc.view.suffix: .jsp # Custom messages can be configured as below welcome.message: Hello Techie !! Welcome to Spring Boot.
Message can be read in the Controller as below.
@org.springframework.beans.factory.annotation.Value("$welcome.message:test")
private String message = "Hello World";
2. Configure the Application Class
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
@EnableAutoConfiguration
@SpringBootApplication
@ComponentScan( "org.app.controllers" )
public class ApplicationRunner extends SpringBootServletInitializer
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
return application.sources(ApplicationRunner.class);
public static void main(String[] args)
SpringApplication.run(ApplicationRunner.class, args);
3. Run ApplicationRunner class:
Now Spring Boot will perform the action internally.
- Invokes configured web server. Here it is tomcat. org.springframework.boot spring-boot-starter-tomcat provided
- Webserver will run with application with out context path.
- Services can be accessed with actions or mapping name directly.
Example: localhost:8080 // will results in default page. localhost:8080/response // will find the service mapped with "response"
Hope it helps, Thanks for reading post !!

Leave a comment