Thursday, January 30, 2020

Controller not scanning in SpringBoot

If our controller is not getting identified/mapped by Tomcat while deploying any War/jar,  we need to make sure that we have created a class extending SpringBootServletInitializer.
Based on google, I tried defining basepackage with @SpringBootApplication but did not work but defining this class worked.

Here is the example.





import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

   @Override   protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
      return application.sources(ApplicationSample.class);
   }

}

No comments:

Post a Comment