基于SSM项目Spring,各种xml配置文件的作用

您所在的位置:网站首页 xml配置文件有什么用处吗知乎推荐一个软件 基于SSM项目Spring,各种xml配置文件的作用

基于SSM项目Spring,各种xml配置文件的作用

2024-07-16 16:22| 来源: 网络整理| 查看: 265

导入

在我们写ssm项目的时候,经常性的需要写xml配置文件,类如applicationContext.xml,springMVC.xml等。因为Spring本身就是一个轻代码重配置的框架,因此正确的配置,对整个项目尤为重要。

applicationContext.xml mysql true

这个配置文件主要作用有: 1.配置组件扫描器,使用注解方式开发 2.加载外部的properties配置文件 3.配置数据库连接池 4.配置session工厂 把数据源注入给Session工厂 5.配置mapper接口 MapperScannerConfigurer:配置dao接口的bean,在mybatis-spring.jar包中 6.配置事务管理器 7. 配置AOP

springMVC

web项目启动时,读取web.xml配置文件,首先解析的是applicationContext.xml文件,其次才是sping-mvc.xml文件,sping-mvc.xml文件中主要的工作是: 1.启动注解; 2.扫描controller包注解; 3.静态资源映射; 4.视图解析(defaultViewResolver); 5.文件上传(multipartResolver); 6.返回消息json配置

spring-security.xml

在使用spring-security权限认证框架才用到的配置,顾名思义,他的作用非常简单,

1.配置不拦截的资源 2.配置具体的规则 3.开启spring-security注解的配置文件 4.配置加密类等;

5.sqlMapConfig.xml

mybatis的配置文件,里面放着数据库连接信息以及自定义sql文件的引用,但是实际上这些内容都交给了Spring去管理,所以有时候空荡荡的,但是他也是不可缺少的配置文件

web.xml contextConfigLocation classpath*:applicationContext.xml,classpath*:spring_security.xml org.springframework.web.context.ContextLoaderListener dispatcherServlet org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:springmvc.xml 1 dispatcherServlet / characterEncodingFilter org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy characterEncodingFilter /* springSecurityFilterChain /* index.html index.jsp

web.xml文件是用来配置:欢迎页、servlet、filter等的,比如我们上面的各种配置文件,不是写好放在那里就能够使用的,我们需要有监听器,将监听到的信息转发给各个类中 比如:

CharacterEncodingFilter,配置这个是拦截所有的资源并设置好编号格式。 DispatcherServlet,配置这个是拦截所有请求,都交给springmvc转发


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3