how to bootstrap spring application with @Configuration within old web.xml ? Say I am building a spring project with @Configuration @ComponentScan annotation style, then how do i get it working with web.xml ? where to start the config class? I did try the following code, but it doesn't seem to work.
src/main/java/com/example/springconfig/AppConfig.java
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextClass</param-name> <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value> com.example.springconfig.AppConfig </param-value> </context-param> </web-app> src/main/webapp/WEB-INF/web.xml
package com.example.springconfig; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @Configuration @EnableWebMvc @ComponentScan("com.example") public class AppConfig { public static void main(String[] args) { System.out.println("==========================="); ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class); } } the main method has never been invoked, any idea ?
ContextLoaderListeneras mentioned in the documentation for Spring itself. There is no@SpringConfigurationannotation, that I know of.