What you are missing is a way to initialize the Spring Dispatcher Servlet servlet. You need to implement the WebApplicationInitializer interface, and in this class you pass all the Java configurations necessary for your application.
You must define AnnotationConfigWebApplicationContext where you can register your configuration class:
context.register(MyConfig.class);
or you can define base packages containing all of your configuration classes:
context.setConfigLocation("com.example.app.config");
Full example:
public class MyWebAppInitializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext container) { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setConfigLocation("com.example.app.config"); container.addListener(new ContextLoaderListener(context)); ServletRegistration.Dynamic dispatcher = container .addServlet("dispatcher", new DispatcherServlet(context)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); } }
Last, if you are using maven, remember to set the failOnmissingwebxml property to false in pom.xml .
You can find more information here.
source share