Spring 小知识点

一、引入配置文件的方式:

方式一:

<context:property-placeholder location="classpath:jdbc.properties,classpath:dubbo.properties" />

 方式二:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath*:jdbc.properties</value>
            <value>classpath*:dubbo.properties</value>
        </list>
    </property>
    <property name="fileEncoding" value="UTF-8" />
    <property name= "ignoreResourceNotFound" value="false"/>
</bean>

方式三:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:jdbc.properties" />
</bean>

 二、SpringMVC DispatcherServlet 在web.xml中的配置

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

 

如果使用如上配置,Spring Web MVC框架将加载“classpath:spring-servlet-config.xml”来进行初始化上下文而不是“/WEB-INF/[servlet名字]-servlet.xml”

三、web.xml配置上下文关系

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

 

 

参考:

posted @ 2018-02-17 21:53  寻找风口的猪  阅读(243)  评论(0编辑  收藏  举报