基于SpringMVC的web应用的ContextLoaderListener与DispatcherServlet标准组合配置

来源:互联网 发布:三维全景漫游软件 编辑:程序博客网 时间:2024/06/04 23:22

A standard spring web application create a web.xml with ContextLoaderListener and DispatcherServlet


I understand that the ContextLoaderListener should be used to load the stuff that is not web relevant and the DispatcherServlet is used to load the web relevant stuff (Controllers,...). And this result in two contexts: a parent and a child context.


web.xml文件:

    <context-param>        <param-name>contextConfigLocation</param-name>        <param-value>classpath:spring-context.xml</param-value>    </context-param>    <listener>        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    </listener>

    <servlet>        <servlet-name>spring-mvc</servlet-name>        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>        <init-param>            <param-name>contextConfigLocation</param-name>            <param-value>classpath:spring-velocity.xml</param-value>        </init-param>        <load-on-startup>1</load-on-startup>    </servlet>    <servlet-mapping>        <servlet-name>spring-mvc</servlet-name>        <url-pattern>*.jhtml</url-pattern>    </servlet-mapping>


spring-context文件:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="location" value="classpath:dbcp-config.properties" /></bean><import resource="spring-datasource-jdbc.xml" /><import resource="spring-dao.xml" /><import resource="spring-manager.xml" /><import resource="spring-service.xml" />

spring-service文件:

        <context:component-scan base-package="com.xhd.lender.web.service"/>


spring-velocity文件:

        <context:component-scan base-package="com.xhd.lender.web.controller"/>



0 0
原创粉丝点击