Thursday, June 6, 2019

How do we Bootstrap via Java base classes not using web.xml

  • Create a class that extends "AbstractAnnotationConfigDispatcherServletInitializer".
    • This class will be instantiated when tomcat starts.
  • There are three abstract methods in this class
    • getRootConfigClasses()
      • Used to create Root Application Context such as Dispatcher Servlet
    • getServletConfigClasses()
      • Used to create Servlet Application Context.
    • getServletMappings()
      • Used to create URL Mappings for a servlet.
SimpleWebAppInitializer
 package com.springimplant.mvc.config;  
 import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;  
 public class SimpleWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {  
      @Override  
      protected Class<?>[] getRootConfigClasses() {  
           return new Class[]{SimpleWebConfiguration.class};  
      }  
      @Override  
      protected Class<?>[] getServletConfigClasses() {  
           return null;  
      }  
      @Override  
      protected String[] getServletMappings() {  
           return new String[] {"/entry/*"};  
      }  
 }  

SimpleWebContext(Dispatcher Servlet Class)
 package com.springimplant.mvc.config;  
 import org.springframework.context.annotation.ComponentScan;  
 import org.springframework.context.annotation.Configuration;  
 import org.springframework.web.servlet.config.annotation.EnableWebMvc;  
 @Configuration  
 @EnableWebMvc  
 @ComponentScan(basePackages="com.springimplant.mvc.controllers")  
 public class SimpleWebConfiguration {  
 }  


No comments:

Post a Comment

Spring Boot

What is circular/cyclic dependency in spring boot? When two services are interdependent on each other, that is to start one service, we requ...