一,lib目录下加入spring一般所需的jar包

  

  二,配置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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>songtian</display-name> <!-- Spring 全局上下文的 监听器,必须有spring上下文配置文件,否则报错 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- Spring上下文配置, 默认为classpath:applicationContext.xml -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-config.xml</param-value>
</context-param> <!-- 字符集编码过滤器characterEncoding -->
<filter>
<filter-name>characterEncoding</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>
</filter>
<filter-mapping>
<filter-name>characterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- spring mvc -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- DispatcherServlet上下文配置, 默认为/WEB-INF/${servlet-name}-servlet.xml -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>pages/sys/login/pages/signin.html</welcome-file>
</welcome-file-list>
</web-app>

  

  三(1),配置spring-mvc.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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- 扫描controller -->
<context:component-scan base-package="com.st"/> <!-- 注解驱动:配置映射器和适配器驱动 -->
<mvc:annotation-driven>
<mvc:message-converters>
<!-- 用fastjson替换默认的jackjson序列化方案 -->
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=utf-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven> </beans>

  三(2),配置spring-config.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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- jdbc.properteis 以下的 三(3) 指定数据源路径-->
<context:property-placeholder location="classpath:jdbc.properties"/> <!-- DataSource 配置数据源 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="driverClassName" value="${mysql.driver}"/>
<property name="url" value="${mysql.url}"/>
<property name="username" value="${mysql.user}"/>
<property name="password" value="${mysql.password}"/> <property name="initialSize" value="${initialSize}" />
<property name="maxActive" value="${maxActive}" />
<property name="minIdle" value="${minIdle}" />
<property name="maxWait" value="${maxWait}" /> <property name="testOnBorrow" value="true" />
<property name="testOnReturn" value="true" />
<property name="testWhileIdle" value="true" />
<property name="removeAbandoned" value="true" />
<property name="logAbandoned" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="removeAbandonedTimeout" value="1800" />
<property name="validationQuery" value="select 1 from dual" />
</bean> <!-- 配置事务开始 -->
<bean id="proxyDataSource" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
<constructor-arg>
<ref bean="dataSource" />
</constructor-arg>
</bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="proxyDataSource" />
</bean> <tx:annotation-driven transaction-manager="transactionManager"/>
<!-- 配置事务结束 --> <!-- 使用构造方法加载数据源 -->
<bean id="queryRunner" class="org.apache.commons.dbutils.QueryRunner">
<!-- <constructor-arg index="0" ref="proxyDataSource"></constructor-arg> -->
<constructor-arg>
<ref bean="proxyDataSource"/>
</constructor-arg>
</bean> <!-- 发送邮件配置开始 -->
<bean id="javaMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.163.com"/>
<property name="port" value="25"/>
<property name="username" value="163邮箱"/>
<property name="password" value="邮箱授权码"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.timeout">25000</prop>
</props>
</property>
</bean> <bean id="simpleMailMessage" class="org.springframework.mail.SimpleMailMessage">
<property name="from" value="163邮箱"/>
<property name="subject" value="发送邮件验证码" />
</bean>
<!-- 发送邮件结束 --> <!-- 支持上传文件 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 设置上传文件的最大尺寸为5MB -->
<property name="maxUploadSize">
<value>5242880</value>
</property>
</bean> </beans>

  

  三(3)数据库连接配置 jdbc.properties

  

#mysql
mysql.driver=com.mysql.jdbc.Driver
mysql.url=jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=utf8
mysql.user=root
mysql.password= initialSize=5
maxActive=100
minIdle=10
maxWait=6000

  

  

SpringMVC配置环境的更多相关文章

  1. SpringMVC配置环境中一般用的jar包

    配置SpringMVC需要把这些jar包加入lib目录下 下载地址,复制到地址栏.回车即可下载 http://files.cnblogs.com/files/QW-lzm/SpringMVC----. ...

  2. idea spring+springmvc+mybatis环境配置整合详解

    idea spring+springmvc+mybatis环境配置整合详解 1.配置整合前所需准备的环境: 1.1:jdk1.8 1.2:idea2017.1.5 1.3:Maven 3.5.2 2. ...

  3. Spring学习资料以及配置环境

    一.Spring4 1.介绍 新特性 SpringIDE 插件 IOC DI 在 Spring 中配置 Bean 自动装配 Bean 之间的关系(依赖.继承) Bean 的作用域 使用外部属性文件 S ...

  4. 构建web应用之——maven创建以及SpringMVC配置

    构建web应用第一步需要创建以及配置maven项目管理,同时配置启动SpringMVC,这里推荐参考CSDN的一篇文章链接:https://blog.csdn.net/weixin_42222334/ ...

  5. 基于java代码的springmvc配置

    在我的印象中,开发一个web项目首选当然是springmvc,而配置springmvc无非就是web.xml里配置其核心控制器DispatcherServlet.然后把所有的请求都交给它处理,再配个视 ...

  6. SpringMVC配置多视图-内容协商原理

    SpringMVC配置多视图-内容协商原理 2014年03月06日 16:46:59 日积月累_滴水石穿 阅读数:10964更多 个人分类: SpringMVC   Spring Framework ...

  7. Spring Boot2 系列教程(十八)Spring Boot 中自定义 SpringMVC 配置

    用过 Spring Boot 的小伙伴都知道,我们只需要在项目中引入 spring-boot-starter-web 依赖,SpringMVC 的一整套东西就会自动给我们配置好,但是,真实的项目环境比 ...

  8. Spring Boot 中自定义 SpringMVC 配置,到底继承谁哪一个类或则接口?

    看了这篇文章,写的非常的言简意赅,特此记录下: 1.Spring Boot 1.x 中,自定义 SpringMVC 配置可以通过继承 WebMvcConfigurerAdapter 来实现. 2.Sp ...

  9. Linux系统下配置环境变量

    一.环境变量文件介绍 转自:http://blog.csdn.net/cscmaker/article/details/7261921 Linux中环境变量包括系统级和用户级,系统级的环境变量是每个登 ...

随机推荐

  1. 洛谷 [P2575] 高手过招

    SG函数+状压记忆化搜索 观察题目发现,每一行都是独立的,只要处理出来每一行的SG值,异或起来就好 每一行的SG值可以用状压+记忆化搜索的方法来求,对位运算技术是个很大的考验 注意SG值要预处理出来, ...

  2. 【HDOJ5978】To begin or not to begin(概率)

    题意:有k个黑球和1个红球,两个轮流抽,抽到红球算赢,问先手赢的概率大还是后手大还是相等 k<=1e5 思路:手算前几项概率 大胆猜想 #include<cstdio> #inclu ...

  3. codevs——1294 全排列

    1294 全排列  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description 给出一个n, 请输出n的所有全 ...

  4. hdu5412CRB and Queries

    动态修改求区间K大. 整体二分是一个神奇的东西: http://www.cnblogs.com/zig-zag/archive/2013/04/18/3027707.html 入门: 一般的主席树都挂 ...

  5. CodeChef - LEMOVIE Little Elephant and Movies

    Read problems statements in Mandarin Chineseand Russian. Little Elephant from Zoo of Lviv likes to w ...

  6. ssh 卡主

    偶尔会遇到这样的现象 ssh 登录一台远程机器,显示下面的信息然后hang在那 Connecting to 192.168.137.102:22... Connection established. ...

  7. 【转载】容器技术 & Docker & 与虚拟化的比较

    看到10月份天天写博客,只有一天没写,非常棒! 11月份也基本每天都写,现在看到有三天没加新博客,应该是之前挖的坑太多了,需要填坑,呵呵. 那这篇文章是不是为了占坑呢?哈哈.我不说话. 容器技术,这篇 ...

  8. TFTP服务器

    为什么要学习有关TFTP服务器的安装及配置呢?主要是为了后续学习有关linux系统的无人值守安装做准备. TFTP简单文件传输协议,使用UDP的69端口.主要提供文件的上传和下载,TFTP一般是适用于 ...

  9. Android6.0权限管理以及使用权限该注意的地方

    Android 6.0 Marshmallow首次增加了执行时权限管理,这对用户来说,能够更好的了解.控 制 app 涉及到的权限.然而对开发人员来说却是一件比較蛋疼的事情.须要兼容适配,并保证程序功 ...

  10. Codeforces 424 C. Magic Formulas

    xor是满足交换律的,展开后发现仅仅要能高速求出 [1mod1....1modn],....,[nmod1...nmodn]的矩阵的xor即可了....然后找个规律 C. Magic Formulas ...