在src/main下面新建一个resouces文件夹,我们继续配置一些资源

1.新增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:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd"> <description>Spring公共配置</description> <!-- 开启定时任务 -->
<task:annotation-driven/> <!-- MyBatis配置 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 显式指定Mapper文件位置 -->
<property name="mapperLocations" value="classpath*:/mybatis/*Mapper.xml" />
<!-- mybatis配置文件路径 -->
<property name="configLocation" value="classpath:/mybatis/config.xml"/>
</bean> <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
<!-- 这个执行器会批量执行更新语句, 还有SIMPLE 和 REUSE -->
<constructor-arg index="1" value="BATCH" />
</bean> <!-- 扫描basePackage接口 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 映射器接口文件的包路径, -->
<property name="basePackage" value="net.quickcodes.dao" />
</bean> <!-- 使用annotation定义事务 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /> <!-- 数据源配置, 使用Tomcat JDBC连接池 -->
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
<!-- Connection Info -->
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" /> <!-- Connection Pooling Info -->
<property name="maxActive" value="${jdbc.pool.maxActive}" />
<property name="maxIdle" value="${jdbc.pool.maxIdle}" />
<property name="minIdle" value="0" />
<property name="defaultAutoCommit" value="false" />
</bean> <!-- production环境 -->
<beans profile="production">
<context:property-placeholder ignore-unresolvable="true" file-encoding="utf-8"
location="classpath:config.properties,classpath:jdbc.properties" />
</beans> </beans>

2.新增jdbc.properties,这个文件用来配置Mysql数据库的jdbc连接信息:

在resouces文件夹上有鼠标右键选择“New”>"Other":

选择"Properties File",点击"Next"按钮:

文件名输入jdbc.properties:

输入如下配置内容,这是连接MySQL数据库的url,用户名和密码,请根据你自己的实际情况配置值:

jdbc.driver=com.mysql.jdbc.Driver

jdbc.url=jdbc:mysql://127.0.0.1:3306/lesson-1?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&allowMultiQueries=true
jdbc.username=root
jdbc.password=123456 #connection pool settings
# maxIdle是最大的空闲连接数,这里取值为20,表示即使没有数据库连接时依然可以保持20个空闲的连接,它们不会被清除,随时处于待命状态
jdbc.pool.maxIdle=20
# maxActive是最大激活连接数,这里取值为190,表示同时最多有190个数据库连接
jdbc.pool.maxActive=190

3.同样方法新建一个config.properties文件,这个配置文件暂时不配置内容,以后有用途。

4.新增一个logback.xml配置文件:

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender> <!-- 时间滚动输出 level为 DEBUG 日志 -->
<appender name="file-debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY </onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>/export/data/logs/debug.%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder>
<pattern>%date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender> <!-- 时间滚动输出 level为 INFO 日志 -->
<appender name="file-info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY </onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>/export/data/logs/info.%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder>
<pattern>%date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender> <!-- 时间滚动输出 level为 INFO 日志 -->
<appender name="file-error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY </onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>/export/data/logs/error.%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder>
<pattern>%date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender> <!-- 很多人使用Mybatis的时候,控制台不能输出SQL语句,造成调试困难。只需要让DAO层的日志级别调整为DEBUG就可以了 -->
<logger name="net.quickcodes.dao" level="DEBUG" /> <!-- 指定项目可输出的最低级别日志 -->
<root level="INFO">
<appender-ref ref="console" />
<appender-ref ref="file-debug" />
<appender-ref ref="file-info" />
<appender-ref ref="file-error" />
</root>
</configuration>

5.在resources文件夹下建立一个mybatis的文件夹,添加一个config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration> <settings>
<setting name="cacheEnabled" value="true" />
</settings> </configuration>

搭建SpringMVC+MyBatis开发框架四的更多相关文章

  1. 搭建SpringMVC+MyBatis开发框架一

    大部分 Java 应用都是 Web 应用,展现层是 Web 应用不可忽略的重要环节.Spring 为展现层提供了一个优秀的 Web 框架—— Spring MVC.和众多其他 Web 框架一样,它基于 ...

  2. 搭建SpringMVC+MyBatis开发框架六

    建立Springmvc包结构 1.看看我们在springmvc.xml中曾经配置过扫描net.quickcodes这个包下面的所有java文件:  现在我们就在"src/main/java ...

  3. 搭建SpringMVC+MyBatis开发框架二

    配置web.xml 用如下配置覆盖原有的web.xml内容 <?xml version="1.0" encoding="UTF-8"?> <w ...

  4. 搭建SpringMVC+MyBatis开发框架五

    建立web结构 1.在webapp目录下新建css.img和js文件夹,删除默认的index.jsp文件:  2.在WEB-INF文件夹下建立一个page文件夹,然后在page下新建一个index. ...

  5. 搭建SpringMVC+MyBatis开发框架三

    新增spingmvc.xml配置 在WEB-INF下新增spingmvc.xml,主要是配置spring扫描的包:  <?xml version="1.0" encodin ...

  6. Maven搭建SpringMVC+MyBatis+Json项目(多模块项目)

    一.开发环境 Eclipse:eclipse-jee-luna-SR1a-win32; JDK:jdk-8u121-windows-i586.exe; MySql:MySQL Server 5.5; ...

  7. Maven搭建SpringMVC+Mybatis项目详解

    前言 最近比较闲,复习搭建一下项目,这次主要使用spring+SpringMVC+Mybatis.项目持久层使用Mybatis3,控制层使用SpringMVC4.1,使用Spring4.1管理控制器, ...

  8. 从头开始基于Maven搭建SpringMVC+Mybatis项目(1)

    技术发展日新月异,许多曾经拥有霸主地位的流行技术短短几年间已被新兴技术所取代. 在Java的世界中,框架之争可能比语言本身的改变更让人关注.近几年,SpringMVC凭借简单轻便.开发效率高.与spr ...

  9. maven搭建springmvc+mybatis项目

    上一篇中已经成功使用maven搭建了一个web项目,本篇描述在此基础上怎么搭建一个基于springmvc+mybatis环境的项目. 说了这么久,为什么那么多人都喜欢用maven搭建项目?我们都知道m ...

随机推荐

  1. Android IOS WebRTC 音视频开发总结(三八)-- tx help

    本文主要介绍帮一个程序员解决webrtc疑问的过程,文章来自博客园RTC.Blacker,支持原创,转载请说明出处(www.rtc.help) 这篇文章内容主要来自邮件,为什么我会特别整理到随笔里面来 ...

  2. asp.net中分页与存储过程的一些总结

    一.接上文,使用的是jquery AJAX 进行分页 分页存储过程代码如下: ALTER PROCEDURE [dbo].[USP_GetAlbumByPage] @pageIndex int,--当 ...

  3. 关于Ajax跨域

    本人因工作需求,编写了一个测试页面,在页面填写完信息之后去向一个站点请求数据,然后返回结果!一开始是直接用Ajax在脚本中去访问,没有大碍(因为目标地址是本机上的一个网站),但是当站点去外部的网站时, ...

  4. JSON,JSONP

    http://blog.csdn.net/huaishuming/article/details/40046729 说明: 在做2个系统间传值时出现: 已阻止交叉源请求:同源策略不允许读取 http: ...

  5. Yii整合ZF2及soap实例

    一)如何整合? // change the following paths if necessary $yii = dirname(__FILE__).'/framework/yii.php'; $c ...

  6. LayoutInflater中四种类型inflate方法的介绍

    转自:http://blog.csdn.net/aa4790139/archive/2011/05/07/6401556.aspx 第一种: public View inflate (int reso ...

  7. DevExpress 关于 GridView 表格编辑中 点击其他按钮里导致 值未取到处理

    只需要给添加以下代码 在执行其他按钮前调 用一下 就可以了:主要是用来关闭编辑以及更新当前行编辑内容 this.gridControl1.FocusedView.CloseEditor(); this ...

  8. 解决在sublime text3在ubuntu下无法输入中文的问题

    方法链接:https://github.com/lyfeyaj/sublime-text-imfix 效果图:

  9. .net 内存分配及垃圾回收总结

        生存期垃圾回收器 目前有很多种类型的垃圾回收器.微软实现了一种生存期垃圾回收器(Generation Garbage Collector). 生存期垃圾回收器将内存分为很多托管堆,每一个托管堆 ...

  10. Iframe 自适应高度的方法!

    第一种方法:代码简单,兼容性还可以,大家可以先测试下. function SetWinHeight(obj) { var win=obj; if (document.getElementById) { ...