tomcat 8、Spring 4.X、JDK1.8

需要jar包:

1)日志组件:log4j

 # debug < info < warn < error
log4j.rootLogger=warn, console, file ###################console####################
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyy-MMM-dd HH:mm:ss} %p %m %L %n ###################file######################
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=../logs/SpuerPPP.log
log4j.appender.file.MaxFileSize=5kb
log4j.appender.file.MaxBackupIndex=100
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d %c.%M()-%m%n

2)web.xml:注册spring组件为项目启动时加载

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.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>
<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>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

3)spring.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: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-4.0.xsd"> <!-- 配置数据源信息-c3p0 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://47.93.197.247:3306/SuperPPP"></property>
<property name="user" value="yyq"></property>
<property name="password" value="yyq"></property>
<property name="initialPoolSize" value="5"></property>
<property name="maxPoolSize" value="10"></property>
<property name="maxStatements" value="100"></property>
<property name="acquireIncrement" value="2"></property>
</bean> <!-- DBUtils的queryRunner注入 -->
<bean id="queryRunner" class="org.apache.commons.dbutils.QueryRunner" scope="prototype">
<constructor-arg name="ds" ref="dataSource"/>
</bean> <!-- 组件扫描 -->
<context:component-scan base-package="henu.superppp" /> <!-- 事务管理器 -->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 注解式事务管理 -->
<tx:annotation-driven transaction-manager="txManager"/> <!-- aop注解方式 -->
<aop:aspectj-autoproxy/> <!-- MVC相关配置 -->
<!-- 拦截器,进行轻量级访问控制 --> <!-- 文件上传 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"/>
<property name="maxUploadSize" value="10000000"/>
</bean>  <!-- 处理请求返回json字符串的中文乱码问题 以及映射器、适配器和试图解析器的自动配置-->
    <mvc:annotation-driven>
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>application/json;charset=UTF-8</value>
                        <value>text/html;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven> <!-- 解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsps/"/>
<property name="suffix" value=".jsp"/>
</bean> </beans>

最新文章

  1. angularJS 服务-$provide里factory、service方法
  2. Cad 二次开发关于SelectCrossingPolygon和SelectFence返回结果Status为error的小测试
  3. MongoDB修改器的使用1
  4. jquery_事件与动画
  5. mysql中bigint、int、mediumint、smallint 和 tinyint的取值范围
  6. mysql触发器使用实例
  7. The Socket API, Part 3: Concurrent Servers
  8. HttpServletRequest 的使用
  9. IOS 常用第三方库
  10. 适用函数ALSM_EXCEL_TO_INTERNAL_TABLE把excel文件传输到内表中
  11. ACL2016信息抽取与知识图谱相关论文掠影
  12. 201521123104《java程序设计》第13周学习总结
  13. Mybatis报错:Parameter &#39;list&#39; not found. Available parameters are [groupList, param1]
  14. centos7下vim8.1的编译安装教程
  15. 启动docker容器时的Error response from daemon: devmapper: Error mounting: invalid argument. 错误解决
  16. 网络基础知识-TCP/IP协议各层详解
  17. QT 登陆对话框
  18. eclipse ant 的自动部署(autobulid)
  19. 解决:Android 8.0检测不到当前的activity
  20. 网页title添加图标

热门文章

  1. Java常见设计模式之代理模式
  2. JAVA基础知识(12)-----同步
  3. VMware虚拟机重置密码
  4. CentOS 7 搭建 LAMP
  5. [xjtu21]wmq的午餐 计数问题
  6. Spring框架IOC容器和AOP解析 非常 有用
  7. hadoop job 重要性能参数
  8. 3、Linux下配置Java环境
  9. &lt;c和指针&gt;学习笔记6输入输出函数
  10. ADT-23.0.2百度网盘下载地址