SpringMVC与SpringBoot配置文件的加载区别

Easter79
• 阅读 752

一、SpringMVC

配置文件在classpath下。

在web.xml中配置加载。

以下项目为示例

其中引用关系为

1. applicationContext-dao.xml 引用了mybatis文件夹中的配置文件

2. applicationContext-shiro.xml 引用了shiro文件夹中的配置文件

3. springmvc.xml 引用了resource文件夹中的配置文件

4. web.xml 引用了spring文件夹中的配置文件

SpringMVC与SpringBoot配置文件的加载区别

<!-- web.xml加载spring容器 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/applicationContext-*.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

<!-- 加载log4j -->
    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:log4j.properties</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

<!-- springmvc的前端控制器 -->
    <servlet>
        <servlet-name>SSM</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- contextConfigLocation不是必须的, 如果不配置contextConfigLocation, springmvc的配置文件默认在:WEB-INF/servlet的name+"-servlet.xml" -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring/springmvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

applicationContext-dao.xml

<!-- 数据库连接池 -->
    <!-- 加载配置文件 -->
    <!-- 
        由db.properties改为*.properties, 这样也会加载其他的属性文件 可以使用 @Value
        由于父子容器关系,service层(父)的属性文件在springmvc层(子)是读取不到的,子只能读取对象,属性是读取不到的
     -->
    <context:property-placeholder location="classpath:resource/*.properties" />
    <!-- 配置sqlsessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"></property>
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    
    <!-- 配置扫描包,加载mapper代理对象 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.suen.mapper"></property>
    </bean>

applicationContext-shiro.xml

<!-- 用户授权信息Cache, 采用EhCache -->
    <bean id="shiroEhcacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
        <property name="cacheManagerConfigFile" value="classpath:shiro/ehcache-shiro.xml"/>
    </bean>

二、SpringBoot:

不需要配置,默认加载。

配置文件在classpath下。

例如:

SpringMVC与SpringBoot配置文件的加载区别

application.properties是默认加载的

而application.properties 引用了i18n、mapper、static、templates文件夹中的配置文件

只要是.yml或者.properties。

示例application.properties中的mybatis 配置

SpringMVC与SpringBoot配置文件的加载区别

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Jacquelyn38 Jacquelyn38
2年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Easter79 Easter79
2年前
spring通过注解@Value获取properties配置
在springmvc中,想通过注解读取\.properties文件的值,可以采用以下方式一.在springmvc.xml配置文件中配置<!加载配置文件<context:propertyplaceholderlocation"classpath:properties/.properties"/二.在相应
Easter79 Easter79
2年前
springMvc HandlerMethodArgumentResolver
SpringMvc在配置多个mvc:argumentresolvers(目前是分开在不同的配置文件)会出现覆盖问题;实际spring容器中只会有一个文件里配置的bean原因debug后发现,MVC实际是在调用一个name为org.springframework.web.servlet.mvc.method.annot
Wesley13 Wesley13
2年前
Spring整合activiti配置processEngine
配置xml数据时,可以直接在配置文件中填写,也可以采用properties配置文件的方式加载。采用配置文件的方式需要使用到${参数}的方式获取。引用配置文件的方式:<context:propertyplaceholderlocation"classpath:properties文件目录"/applic
Easter79 Easter79
2年前
SSM_基于传统web项目
1.这是一个单模块的项目!有四个配置文件,mybaits,spring。springmvc,web.xml!2.web.xml配置文件,导入spring和springmvc的配置文件,spring配置文件中,获取sqlsession,以及关联mybatis的mpper(增删改查)文件3.mybatis的配置文件则可以不用写
Stella981 Stella981
2年前
SSM_基于传统web项目
1.这是一个单模块的项目!有四个配置文件,mybaits,spring。springmvc,web.xml!2.web.xml配置文件,导入spring和springmvc的配置文件,spring配置文件中,获取sqlsession,以及关联mybatis的mpper(增删改查)文件3.mybatis的配置文件则可以不用写
Stella981 Stella981
2年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Python进阶者 Python进阶者
3个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这
Easter79
Easter79
Lv1
今生可爱与温柔,每一样都不能少。
文章
2.8k
粉丝
5
获赞
1.2k