@Configuration
@ComponentScan(basePackages = "com.liu.spring.xml")
public class SpringConfig {
}
web.xml配置
<!--告訴ContextLoaderListener使用註解-->
<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.liu.spring.xml.configuration.SpringConfig</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
https://gitee.com/null_631_9084/myhomework/tree/master/stage01-spring/spring-demo-anno