一、SpringMVC:
配置文件在classpath下。
在web.xml中配置加载。
以下项目为示例
其中引用关系为
1. applicationContext-dao.xml 引用了mybatis文件夹中的配置文件
2. applicationContext-shiro.xml 引用了shiro文件夹中的配置文件
3. springmvc.xml 引用了resource文件夹中的配置文件
4. web.xml 引用了spring文件夹中的配置文件

1<!-- web.xml加载spring容器 --> 2 <context-param> 3 <param-name>contextConfigLocation</param-name> 4 <param-value>classpath:spring/applicationContext-*.xml</param-value> 5 </context-param> 6 <listener> 7 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 8 </listener> 9 10<!-- 加载log4j --> 11 <context-param> 12 <param-name>log4jConfigLocation</param-name> 13 <param-value>classpath:log4j.properties</param-value> 14 </context-param> 15 <listener> 16 <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> 17 </listener> 18 19<!-- springmvc的前端控制器 --> 20 <servlet> 21 <servlet-name>SSM</servlet-name> 22 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 23 <!-- contextConfigLocation不是必须的, 如果不配置contextConfigLocation, springmvc的配置文件默认在:WEB-INF/servlet的name+"-servlet.xml" --> 24 <init-param> 25 <param-name>contextConfigLocation</param-name> 26 <param-value>classpath:spring/springmvc.xml</param-value> 27 </init-param> 28 <load-on-startup>1</load-on-startup> 29 </servlet>
applicationContext-dao.xml
1<!-- 数据库连接池 --> 2 <!-- 加载配置文件 --> 3 <!-- 4 由db.properties改为*.properties, 这样也会加载其他的属性文件 可以使用 @Value 5 由于父子容器关系,service层(父)的属性文件在springmvc层(子)是读取不到的,子只能读取对象,属性是读取不到的 6 --> 7 <context:property-placeholder location="classpath:resource/*.properties" /> 8 <!-- 配置sqlsessionFactory --> 9 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 10 <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"></property> 11 <property name="dataSource" ref="dataSource"></property> 12 </bean> 13 14 <!-- 配置扫描包,加载mapper代理对象 --> 15 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 16 <property name="basePackage" value="com.suen.mapper"></property> 17 </bean>
applicationContext-shiro.xml
1<!-- 用户授权信息Cache, 采用EhCache --> 2 <bean id="shiroEhcacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager"> 3 <property name="cacheManagerConfigFile" value="classpath:shiro/ehcache-shiro.xml"/> 4 </bean>
二、SpringBoot:
不需要配置,默认加载。
配置文件在classpath下。
例如:

application.properties是默认加载的
而application.properties 引用了i18n、mapper、static、templates文件夹中的配置文件
只要是.yml或者.properties。
示例application.properties中的mybatis 配置
