第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>

 

********************************************************************************************************************************************

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/328433.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

eclipse开发jsp默认编码设置

转载自 eclipse开发jsp默认编码设置 在eclipse中新建一个jsp页面时&#xff0c;一般默认的编码不是utf-8&#xff0c;而我们一般项目都是统一采用utf-8编码&#xff0c;如果要一个个改很麻烦&#xff0c;大家一般都会想到如果更改默认设置。网上搜索一般是在&#xff1a;wind…

java threadlocal 缺点_Java的ThreadLocal如何在后台实现?

小编典典这里的所有答案都是正确的&#xff0c;但是有些令人失望&#xff0c;因为它们多少掩盖了聪明ThreadLocal的实现是多么的明智。我只是在寻找源代码&#xff0c;ThreadLocal并且对它的实现方式印象深刻。天真的实现如果我要求您ThreadLocal在javadoc中描述的给定API的基础…

第10步 (1)logback.xml日志配置(2) ftp(上传文件)服务器配置(3) idea注入和自动编译配置(4)项目提交gitee(5)fe助手和restlet client

****************************************************************************************************************************************** 1.直接复制 logback.xml 比较简单 <?xml version"1.0" encoding"UTF-8"?> <configuratio…

第11步 git推送失败 用户模块开发

别忘了git push ************************************************************************************************************************************* 1. 用户模块开发 共11个接口 用户 status 0 则是正确响应 其他1等是错误 用户信息是session中拿过来的 use…

java 继承 实现 会重写 方法吗_java 中继承,组合,重载,重写的实现原理 (转)...

我们知道&#xff0c;继承&#xff0c;组合&#xff0c;重载&#xff0c;重写是java语言的面向对象实现的基本特征。 那么在java内部&#xff0c;究竟是如何实现这些面对对象的基本特征的呢&#xff1f;继承和组合是面向对象中代码复用的主要实现方式&#xff0c;他们可以达到类…

Java 调用EXE

转载自 Java 调用EXE 使用Runtime.getRuntime().exec()方法可以在java程序里运行外部程序. 该方法有6个可访问版本: 1.exec(String command) 2.exec(String command, String envp[], File dir) 3.exec(String cmd, String envp[]) …

基于SignalR的消息推送与二维码描登录实现

1 概要说明 使用微信扫描登录相信大家都不会陌生吧&#xff0c;二维码与手机结合产生了不同应用场景&#xff0c;基于二维码的应用更是比较广泛。为了满足ios、android客户端与web短信平台的结合&#xff0c;特开发了基于SinglarR消息推送机制的扫描登录。本系统涉及到以下知识…

Java调用exe阻塞

转载自 Java调用exe阻塞 今天遇到了个奇怪的问题&#xff0c;用VC写了个小程序&#xff0c;编译成exe文件&#xff0c;然后用Java去调&#xff0c;居然卡住不运行了。如果双击这个exe程序&#xff0c;单独让它运行&#xff0c;是可以的&#xff0c;那么为什么用Java调用就不好…

java中iscontinue意思_Java 中return、continue和break的区别

写在前面&#xff1a;适合Java初学者&#xff0c;大神就别来了。今天同事突然问我return和break的区别&#xff0c;以前觉得随口都能说出来的东西&#xff0c;今天突然卡了&#xff0c;记得模模糊糊&#xff0c;只能说出个大概&#xff0c;所以这里做一个总结&#xff0c;还是那…

第13步 用户模块前端(Admin)

bootstrap 就不用谢css样式 了 都写好了 http://www.bootcss.com/ https://www.bootcdn.cn/ <meta charset"utf-8"> <!-- 防止网站在手机端看变形了 --> <meta name"viewPort" content"widthdevice-width,initial…

ASP.NET Core 静态文件及JS包管理器(npm, Bower)的使用

在 ASP.NET Core 中添加静态文件 虽然ASP.NET主要大都做着后端的事情&#xff0c;但前端的一些静态文件也是很重要的。在ASP.NET Core中要启用静态文件&#xff0c;需要Microsoft.AspNetCore.StaticFiles组件。可以通过Nuget添加&#xff0c;或者在project.json配置文件中添加&…

Java 正则表达式匹配模式[贪婪型、勉强型、占有型]

转载自 Java 正则表达式匹配模式[贪婪型、勉强型、占有型]Greediness&#xff08;贪婪型&#xff09;&#xff1a;最大匹配 X?、X*、X、X{n&#xff0c;} 是最大匹配。例如你要用 “<.>” 去匹配 “a<tr>aava </tr>abb”&#xff0c;也许你所期待的结果是想…

新闻发布项目——分页公共类(PageUitl )

package bdqn.newsManageServlet.Util; /*** 分页的类* author Administrator**/ public class PageUitl {private int pagesize;//页大小private int pageindex1;//页码private int recordCount;//总记录数private int totalPageCount;//总页数//计算总页数public int getTota…

java代码配置 mybatis_配置简介(MyBatis源码篇)

1 SqlSessionFactoryBuilder#上篇例子中&#xff0c;我们以SqlSessionFactoryBuilder去创建SqlSessionFactory, 那么&#xff0c;我们就先从SqlSessionFactoryBuilder入手&#xff0c; 咱们先看看源码是怎么实现的。SqlSessionFactoryBuilder源码片段&#xff1a;public class …

js 方法传递对象参数

js 方法传递对象参数 2017年12月06日 16:35:39 qq_26676207 阅读数&#xff1a;7696 版权声明&#xff1a;本文为博主原创文章&#xff0c;未经博主允许不得转载。 https://blog.csdn.net/qq_26676207/article/details/78732117 第一步&#xff1a; //通过JSON.stringify()方…

Java8中 Date和LocalDateTime的相互转换

转载自 Java8中 Date和LocalDateTime的相互转换一.在Java 8中将Date转换为LocalDateTime 方法1: 将Date转换为LocalDatetime&#xff0c;我们可以使用以下方法&#xff1a; 1.从日期获取ZonedDateTime并使用其方法toLocalDateTime&#xff08;&#xff09;获取LocalDateTime 2…

java 时分秒格式小时8_Java里得到00:00:00格式的时分秒的Timestamp

复制代码 代码如下:import java.sql.Timestamp;import java.text.SimpleDateFormat;import java.util.TimeZone;public class Test {public static void main(String[] args) {SimpleDateFormat sdf new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");long t System.cu…

免费开源的 .NET 分布式组件库 Exceptionless Foundatio

前言 在互联网时代&#xff0c;分布式应用、系统变得越来越多&#xff0c;我们在使用 .Net 技术构建分布式系统的时候&#xff0c;需要使用到一些组件或者是助手库来帮助我们提高生产力以及应用程序解耦&#xff0c;但是纵观.Net圈&#xff0c;能够符合要求的这样的组件并不是很…