web.xml配置註解啓動

在這裏插入圖片描述

@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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章