第9步 spring 配置 springmvc配置
spring配置
有5个网址 springboot
再讲一遍 spring的学习最好的方法是运行 官方demo 学习它里面的配置 。
我们不可能一下子理解spring里面的源码
spring配置直接复制好了 视频老师也是从官方demo中复制过来的
直接复制
********************************************************************************************************************************************
1.首先讲web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"id="WebApp_ID" version="2.5"><display-name>Archetype Created Web Application</display-name><!-- CharacterEncodingFilter 配置过滤器 为了转码用的 --><filter><filter-name>characterEncodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param><init-param><param-name>forceEncoding</param-name><param-value>true</param-value></init-param></filter><filter-mapping><filter-name>characterEncodingFilter</filter-name><!-- /* 拦截所有请求 走CharacterEncodingFilter我们就不用再写转utf-8这种了过滤所有的请求 --><url-pattern>/*</url-pattern></filter-mapping><listener><!-- web容器启动和关闭的监听器 只是监听web容器的启动和关闭 --><listener-class>org.springframework.web.context.request.RequestContextListener</listener-class></listener><listener><!-- ContextLoaderListener web容器和spring容器进行整合进行监听 --><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><context-param><param-name>contextConfigLocation</param-name><param-value><!-- 指向spring配置文件 -->classpath:applicationContext.xml<!-- ContextLoaderListener 会 通过applicationContext.xml、将spring容器和web容器进行整合--></param-value></context-param><servlet><!--DispatcherServlet 配置spring-mvc --><servlet-name>dispatcher</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 指定SpringMVC的文件 不写是 默认dispatcher-servlet.xml名字 --><!--<init-param>--><!--<param-name>contextConfigLocation</param-name>--><!--<param-value>/WEB-INF/spring-mvc.xml</param-value>--><!--<param-value>/WEB-INF/xxxx.xml (叫什么名字都可以)</param-value>--><!--</init-param>--><!-- servlet的配置 当大于等于0 就在容器启动时初始化这个servlet小于0或不指定 只有请求时才初始化servlet--><load-on-startup>1</load-on-startup></servlet><servlet-mapping><!-- DispatcherServlet dispatcher 引用上面的springmvc配置 拦截所有的*.do --><servlet-name>dispatcher</servlet-name><!-- springmvc 将所有的*.do进行拦截 --><url-pattern>*.do</url-pattern></servlet-mapping><!--NFDFlightDataTaskListener 监听器--><!--<listener>--><!--<listener-class>com.zjyouth.utils.NFDFlightDataTaskListener</listener-class>--><!--</listener>--></web-app>
********************************************************************************************************************************************
1.首先讲web.xml
2.再讲一下spring容器的主配置 applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"xmlns:context="http://www.springframework.org/schema/context"xmlns:task="http://www.springframework.org/schema/task"xsi:schemaLocation="http://www.springframework.org/schema/taskhttp://www.springframework.org/schema/task/spring-task-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"><!-- spring容器的主配置 --><!-- 扫描com.zjyouth下的一些注解 可以很方便的进行注入<context:component-scan base-package="com.zjyouth" annotation-config="true"/>--><context:component-scan base-package="com.zjut" annotation-config="true"/><!-- 定时 --><context:component-scan base-package="com.zjyouth.*" /><task:executor id="executor" pool-size="5" /><task:scheduler id="scheduler" pool-size="10" /><task:annotation-driven executor="executor" scheduler="scheduler" /><!-- <context:annotation-config/>--><!--在使用spectj注解实现springAOP:1.需要使用@Aspect注解来标注切面2.可以使用@before,@afterRuning,@around,@afterThrowning注解,来标注通知3.必须有切入点point-cut,使用@pointcut(execution(""))注解来标注切入点4.在aop.xml中,需要有https://blog.csdn.net/qq_37761074/article/details/72859266Spring配置- - -<aop:aspectj-autoproxy />2017年11月01日 11:54:08 阅读数:488更多个人分类: 日记版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ke_zhang_123/article/details/78412536<aop:aspectj-autoproxy proxy-target-class="true"/> 基于类的动态代理(依赖于CGlib库)通过配置织入@Aspectj切面--><!-- aop的配置 spring配置文分成多个文件 datasource.xml --><aop:aspectj-autoproxy/><!-- spring配置文件 dataSource分出来的子文件 --><import resource="applicationContext-datasource.xml"/></beans>
********************************************************************************************************************************************
1.首先讲web.xml
2.再讲一下spring容器的主配置 applicationContext.xml
3.spring配置文件 dataSource分出来的子文件 applicationContext-datasource.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"><!-- spring容器的自配置文件 --><!-- 扫描com.zjyouth下的所有注解 <context:component-scan base-package="com.zjyouth" annotation-config="true"/>--><context:component-scan base-package="com.zjut" annotation-config="true"/><!-- 将常量分离出来 分出1个文件 --><bean id="propertyConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="order" value="2"/><property name="ignoreUnresolvablePlaceholders" value="true"/><property name="locations"><list><!-- 将常量分离出来 分出1个文件 --><value>classpath:datasource.properties</value></list></property><!-- 指定字符集 --><property name="fileEncoding" value="utf-8"/></bean><!-- dbcp数据库连接池配置 使用dbcp数据库连接池 --><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"><property name="driverClassName" value="${db.driverClassName}"/><property name="url" value="${db.url}"/><property name="username" value="${db.username}"/><property name="password" value="${db.password}"/><!-- 连接池启动时的初始值 --><property name="initialSize" value="${db.initialSize}"/><!-- 连接池的最大值 --><property name="maxActive" value="${db.maxActive}"/><!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 --><property name="maxIdle" value="${db.maxIdle}"/><!-- 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 --><property name="minIdle" value="${db.minIdle}"/><!-- 最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制 --><property name="maxWait" value="${db.maxWait}"/><!--#给出一条简单的sql语句进行验证 --><!--<property name="validationQuery" value="select getdate()" />--><property name="defaultAutoCommit" value="${db.defaultAutoCommit}"/><!-- 回收被遗弃的(一般是忘了释放的)数据库连接到连接池中 --><!--<property name="removeAbandoned" value="true" />--><!-- 数据库连接过多长时间不用将被视为被遗弃而收回连接池中 --><!--<property name="removeAbandonedTimeout" value="120" />--><!-- #连接的超时时间,默认为半小时。 --><property name="minEvictableIdleTimeMillis" value="${db.minEvictableIdleTimeMillis}"/><!--# 失效检查线程运行时间间隔,要小于MySQL默认--><property name="timeBetweenEvictionRunsMillis" value="40000"/><!--# 检查连接是否有效--><property name="testWhileIdle" value="true"/><!--# 检查连接有效性的SQL语句--><property name="validationQuery" value="SELECT 1 FROM dual"/></bean><!-- 这个配置重要 是mybatis的sqlSesstion的bean --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!-- ref="dataSource" 指的是上面dpcp数据库连接池 --><property name="dataSource" ref="dataSource"/><!-- 这个就能读取到mybatis的所有的实现 --><property name="mapperLocations" value="classpath*:mappers/*Mapper.xml"></property><!-- 分页插件 在加上 pom中配置jar mybatis的分页插件就配置好了 --><property name="plugins"><array><bean class="com.github.pagehelper.PageHelper"><property name="properties"><value><!-- 指明一下方言是mysql -->dialect=mysql</value></property></bean></array></property></bean><!-- mybatis 扫描包的方式 --><!-- mybatis的一个扫描 会扫描dao层 对service层提供接口 这个配置很重要 --><bean name="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer"><!-- (空格删一些不然报错) <property name="basePackage" value="com.zjyouth.dao"/> --><property name="basePackage" value="com.zjut.rtcf.dao"/></bean><!-- spring事务管理的配置 --><!-- 使用@Transactional进行声明式事务管理需要声明下面这行 --><tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /><!-- 事务管理 --><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><!-- 数据库连接池 dbcp --><property name="dataSource" ref="dataSource"/><!-- 提交事务失败 出错是否回滚 true 回滚 --><property name="rollbackOnCommitFailure" value="true"/></bean></beans>
spring配置讲完了
********************************************************************************************************************************************
1.首先讲web.xml
2.再讲一下spring容器的主配置 applicationContext.xml
3.spring配置文件 dataSource分出来的子文件 applicationContext-datasource.xml spring配置讲完了
4.再讲一下spring mvc配置 dispatcher-servlet.xml (名字可以在web.xml里面修改)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd"><!-- springmvc配置文件 这个是默认的名字 dispatcher-servlet.xml --><!-- 扫描controller注解 <context:component-scan base-package="com.zjyouth" annotation-config="true"/>--><context:component-scan base-package="com.zjut.rtcf" annotation-config="true"/><mvc:annotation-driven><mvc:message-converters><bean class="org.springframework.http.converter.StringHttpMessageConverter"><property name="supportedMediaTypes"><list><!-- 配置字符集 --><value>text/plain;charset=UTF-8</value><value>text/html;charset=UTF-8</value></list></property></bean><!-- @ResponseBody 注解将对象数据直接转换为json数据 --><!-- SpringMVC自动进行反序列化的时候 的配置类 Jackson配置类 --><bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"><!-- 返回对象的时候 返回的可以是null 通过配置就过滤这个 本项目使用默认配置就不要了 --><!--<property name="objectMapper">--><!--<bean class="org.codehaus.jackson.map.ObjectMapper">--><!--<property name="serializationInclusion" value="NON_EMPTY"/>--><!--</bean>--><!--</property>--><property name="supportedMediaTypes"><list><!-- 字符集 --><value>application/json;charset=UTF-8</value></list></property></bean></mvc:message-converters></mvc:annotation-driven><!-- --><!-- 文件上传 直接使用SpringMVC提供的multipart这个工具就好了 --><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><property name="maxUploadSize" value="10485760"/> <!-- 单位字节 上传的最大字节10m --><property name="maxInMemorySize" value="4096" /> <!-- 单位字节 最大内存4M 块的大小 --><property name="defaultEncoding" value="UTF-8"></property> <!-- 默认编码 --></bean><!-- SpringMVC配置讲完了 --></beans>
********************************************************************************************************************************************
第9步 spring 配置 springmvc配置相关推荐
- spring与springMVC配置扫描的问题
为什么80%的码农都做不了架构师?>>> 首先,如果不配置事务在哪里扫描都是可以的,但是这是不可能的,所以扫描的时候就需要有先后的顺序. 顺序:spring负责除control ...
- 配置spring、SpringMVC,mybatis进行整合
springframwork的官网 spring-projects/spring-mvc-showcase https://github.com/spring-projects/spring-mvc- ...
- springmvc 配置 tag lib_Java自学之springMVC:Hello Spring MVC
学习目的:初识SpringMVC,了解SpringMVC的工作原理 Part 1 新建一个动态web项目,命名为springMVC,在WEB-INF/lib中,添加所需要的jar包. Part 2 在 ...
- springMVC+Spring+mybatis整合配置版与注解版
springMVC+Spring+mybatis整合 , 使用配置版来完成: -----------------------------前端 1.创建web系统,导入jar包: spring的jar包 ...
- springmvc 配置和spring配置?
最近在接触mybatis,之间使用springmvc时,配置文件一直是,web.xml+XX-servlet.xml 的配置(xx为web.xml中servlet name名称). 为了整合mybat ...
- spring boot实现WebMvcConfigurer接口定制SpringMvc配置
文章目录 自定义静态资源映射 addResourceHandlers() 拦截器 addInterceptors() 无业务逻辑页面跳转 addViewControllers() 合而为一 sprin ...
- SpringBoot配置与应用 SpringBoot与(Spring和springmvc的区别)
1.什么是springboot? springboot与springmvc的区别,springboot代替了springmvc? ssm包含了spring与springmvc还有mybatis. 用到 ...
- SSM6==spring体系回顾,纯XML配置springMVC,纯注解配置springMVC
spring全家桶 spring framework 官方文档: Spring Framework Reference Documentationhttps://docs.spring.io/spri ...
- spring boot web开发------自定义springmvc配置
1.如何自定义springmvc配置 旧的springmvc配置文件 <?xml version="1.0" encoding="UTF-8"?> ...
最新文章
- 制药行业SAP项目里的那些MES系统
- sublime快捷键
- lintcode:Unique Characters 判断字符串是否没有重复字符
- php通过Mysqli和PDO连接mysql数据详解
- std和android空间,ANDROID平台通讯中STDM加密技术的应用
- java replaceall删除中括号和内容_「技术文章」《阿里巴巴 Java 开发手册》精华摘要...
- 【跃迁之路】【651天】程序员高效学习方法论探索系列(实验阶段408-2018.11.24)...
- linux 安装 交换分区大小,给已安装的Linux新增Swap交换分区
- 【OpenCV 例程200篇】61. 导向滤波(Guided filter)
- Apache Lucene Java 全文检索引擎架构
- warning: implicit declaration of function ‘typeof’
- 在线教育与计算机网络的融合发展,[浅谈线上教育和线下教育的融合]
- Atitit 扩大个人影响力和宣传目录1. 发文舆论阵地 11.1. 简书 知乎 csdn等 11.2. Ifttt出发同步 11.3. 问答平台 知乎 quaro 11.4. Tik
- 高清版计算机组成原理(第2版)-唐朔飞
- 摄像头视频画面接入,使用iframe标签嵌入到页面中(海康威视、萤石)
- [TCL]Tcl语言基礎教程(一)
- 2.高速PCB设计规范(一)
- Black-Scholes期权定价模型
- Matlab-simulink汽车二自由度模型
- 如何高效录制教学视频?
热门文章
- ZOJ The Sum of Unitary Totient(min_25 筛)
- SP5971 LCMSUM - LCM Sum
- Codeforces Round #740 (Div. 2) D2. Up the Strip dp + 分块优化 + 逆向思维
- Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)
- C - Insertion Sort Gym - 101955C
- CF765F Souvenirs(势能线段树)
- 树哈希判断同构无根同构问题转有根同构问题
- P4100-[HEOI2013]钙铁锌硒维生素【矩阵求逆,最大匹配】
- CF1110E-Magic Stones【结论题,差分】
- 【DP】字串距离(luogu 1279)