1.首先导入各种需要的配置包,在这里个人的习惯就是先导入mybatis相关包,然后通过编程软件集成一个spring3.0或者spring3.1进来并选择里面相应的包,这样就不需要我们自己去导入相应的spring包了。

2.新建spring-mybatis.xml文件以及spring-mvc.xml文件,分别配置如下:

  spring-mybatis.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
">
<!-- 采用注释的方式配置bean -->
<context:annotation-config />
<!-- 配置要扫描的包 -->
<context:component-scan base-package="com.julong.testoracle" /> <!-- 分解配置 jdbc.properites -->
<context:property-placeholder location="classpath:jdbc.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!-- 队列中的最小等待数 -->
<property name="minIdle" value="${jdbc.minIdle}"></property>
<!-- 队列中的最大等待数 -->
<property name="maxIdle" value="${jdbc.maxIdle}"></property>
<!-- 最长等待时间,单位毫秒 -->
<property name="maxWait" value="${jdbc.maxWait}"></property>
<!-- 最大活跃数 -->
<property name="maxActive" value="${jdbc.maxActive}"></property>
<property name="initialSize" value="${jdbc.initialSize}"></property>
</bean> <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:com/julong/testoracle/mapper/*.xml"></property>
</bean> <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.julong.testoracle.dao"> </property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean> <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>

spring-mvc.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">

  <!-- 配置需要用过mvc监听的文件 -->
<context:component-scan base-package="com.julong.testoracle.controller" /> </beans>

3.配置相应的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" version="3.0">
<display-name>oracle</display-name>
<!-- spring的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!--全局范围内环境参数初始化,即初始化spring-mybatis.xml-->
<context-param>
<param-name>contextConfigLocation</param-name> <!--参数名称-->
<param-value>classpath:spring-mybatis.xml</param-value><!--参数取值-->
</context-param> !--用来声明一个servlet的数据 -->
<servlet>
<servlet-name>springMVC</servlet-name><!--指定servlet的名称-->
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!--指定servlet的类名称,这里配置了前端控制器-->
<init-param>
<param-name>contextConfigLocation</param-name><!--参数名称-->
<param-value>classpath:spring-mvc.xml</param-value><!--参数值-->
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name> <!--指定servlet的名称-->
<url-pattern>*.mvc</url-pattern> <!--指定servlet所对应的URL-->
</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>

4.指定数据库连接时需要引入的资源文件(因前面给其分解开来了)

#jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.driverClassName=oracle.jdbc.OracleDriver
#jdbc.url=jdbc:mysql://localhost:3306/operationLog
jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
#jdbc.url=jdbc:oracle:thin:@192.168.1.111:1521:orcl
jdbc.username=oracle
jdbc.password=oracle
#jdbc.password=root
jdbc.maxActive = 2
jdbc.maxIdle =5
jdbc.minIdle=1
jdbc.initialSize =3
jdbc.maxWait =3000

最新文章

  1. Linux修改命令提示符(关于环境参量PS1)
  2. Percona XtraDB Cluster(转)
  3. Excel 中单元格和范围的引用(即访问的表示方法)
  4. openerp模块收藏 auto_setup 自动帮你完成建新库时必做几个操作(转载)
  5. inline-block元素之间出现间隙
  6. Binary Tree Zigzag Level Order Traversal——LeetCode
  7. AppStore安装APP发生错误解决方法
  8. Silverlight的Socket通信
  9. Java 程序测试_循环语句中的break和continue
  10. 【PAT_Basic日记】1002. 写出这个数
  11. immutable日常操作之深入API
  12. angular2 学习笔记 ( app initialize 初始化 )
  13. Java开发笔记(四十一)日历工具Calendar
  14. centos7 配置lamp 环境
  15. 洛谷P2704 炮兵阵地
  16. 网页提示504 gateway time-out是什么意思?如何解决?
  17. 【机器学习】激活函数(Activation Function)
  18. 强化学习10-Deep Q Learning-fix target
  19. python抓取内涵段子文章
  20. 如何用STAF进行自动化测试分布式运行

热门文章

  1. fatal error C1853
  2. ISNULL
  3. xrange和range区别
  4. C# winform 弹出输入框
  5. php smarty 缓存和配置文件的基本使用方法
  6. IIS虚拟目录实现与文件服务器网络驱动器映射共享
  7. ANDROID_MARS学习笔记_S02_005_AppWidget1
  8. Android 透明Button
  9. javascript模板引擎Mustache
  10. IPv6 tutorial 1 Get started now