ssm和c3p0连接池配置文件的详解

ssm和c3p0连接池配置文件的详解spring.xml配置<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:co…

大家好,又见面了,我是你们的朋友全栈君。

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: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-3.0.xsd
	  
	  http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-3.0.xsd
 	  
	  http://www.springframework.org/schema/aop 
	  http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
	  
	  http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        
      ">
 <!-- 配置数据源,记得去掉myBatis-config.xml的数据源相关配置 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="com.mysql.jdbc.Driver" />
		<property name="jdbcUrl"
			value="jdbc:mysql://localhost:3306/ssm?useUnicode=true&characterEncoding=UTF-8" />
		<property name="user" value="root" />
		<property name="password" value="root" />
	</bean>
	<!-- 配置session工厂 -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation" value="classpath:myBatis-config.xml" />
		<!--配置扫描式加载SQL映射文件,记得去掉mybatis-config配置-->
		<property name="mapperLocations" value="classpath:com/ssm/dao/*.xml"/>
		
	</bean>

	<!-- 配置事务管理器,管理数据源事务处理 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- 配置事务通知 -->
	<tx:advice id="advice" transaction-manager="transactionManager">
		<tx:attributes>
			<!-- 默认只处理运行时异常,可加rollback-for="Exception/Throwable"等处理所有异常或包括错误 -->
			<tx:method name="insert*" propagation="REQUIRED"
				rollback-for="Exception" />
			<tx:method name="update*" propagation="REQUIRED"
				rollback-for="Exception" />
			<tx:method name="delete*" propagation="REQUIRED"
				rollback-for="Exception" />
			<tx:method name="*" propagation="SUPPORTS" />
                       <!--下面懒式配置也可以,注意要把异常处理也配上,这样出现异常才会回滚,rollback-for:"Exception" -->
      			
                           <!--<tx:method name="*" propagation="REQUIRED" rollback-for="Exception"/>-->
</tx:attributes></tx:advice>
        

 

<!-- 配置切面织入的范围,后边要把事务边界定在service层第一*表示返回类型 第二*表示包下哪些类,第三*表示类中那些方法 -->
	<aop:config>
		<aop:advisor advice-ref="advice"
			pointcut="execution(* cn.itcast.scm.service.impl.*.*(..))" />
	</aop:config>
	<!-- 配置SessionTemplate,已封装了繁琐的数据操作 -->
	<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
		<constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory" />
	</bean>

	<!-- <context:component-scan base-package="*" /> -->


	<!-- 自动扫描组件,要把controller去除,他们是在spring-mvc.xml中配置,如果不去除会影响事务管理。 -->
	<context:component-scan base-package="cn.itcast">
		<context:exclude-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
	</context:component-scan>
	<!-- 配置 转换器,对于在basePackage设置的包(包括子包)下的接口类,
	如果接口类的全类名在Mapper.xml文件中和定义过命名空间一致,
	 将被转换成spring的BEAN,在调用 
		的地方通过@Autowired方式将可以注入接口实例 -->

	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="sqlSessionFactory" ref="sqlSessionFactory" />
		<property name="basePackage" value="cn.itcast.scm.dao" />
	</bean>

<beans>

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:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
	http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
	">
	<!-- 同时开启json格式的支持 -->
	<mvc:annotation-driven></mvc:annotation-driven>
	<!-- <context:component-scan base-package="*"/> -->
	
	<!-- 扫描所有的controller 但是不扫描service -->
	<context:component-scan base-package="com.ssm">
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
		<context:exclude-filter type="annotation"
			expression="org.springframework.stereotype.Service" />
	</context:component-scan>


	
	
	
</beans>

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" version="2.5">
 <!-- 注册springmvc核心控制器 -->
  <servlet>
    <servlet-name>DispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
    <!-- 配置加载spring.xml -->
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring.xml</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>*.action</url-pattern>
  </servlet-mapping>
  
  
  <!-- 注册spring提供的针对POST请求的中文乱码问题 -->
  <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>


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/135522.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 【已解决】罗技K380蓝牙键盘可以连接电脑,但无法输入怎么办?[通俗易懂]

    【已解决】罗技K380蓝牙键盘可以连接电脑,但无法输入怎么办?[通俗易懂]【问题】罗技k380可以连接并正常使用平板、手机。电脑显示着已连接,但就是无法输入。之前是可以用的,最近需要频繁配对突然不能用了。网上的各种方法都不好使,问京东客服也解决不了准备申请售后。【解决方案】后来仔细看了下k380使用方法,发现Fn+F1可以重置键盘的蓝牙设备,于是在电脑删除了k380蓝牙设备后,在蓝牙键盘上进行了Fn+F1重置,最后进行重启配对就ok了。可能是频繁配对让键盘有了缓存错误了。

    2022年10月16日
    2
  • php memcache 数组,PHP Memcache

    php memcache 数组,PHP MemcacheMemcache memcache 是一套分布式的高速缓存系统 目前被许多网站使用提升网站的访问速度 尤其是对于一些大型的 需要频繁访问数据库的网站访问速度提升效果很明显 具体是在内存中维护一个巨大的 hash 表 简单的说就是将数据调用到内存中 然后从内存中读取 就能大大提高读取速度 工作流程 先检查客户端请求的数据是否在 memcached 中 如有 将数据直接返回 不再对数据库进行操作 请求数据不存在

    2025年11月18日
    9
  • 【iOS7一些总结】9、与列表显示(在):列表显示UITableView

    【iOS7一些总结】9、与列表显示(在):列表显示UITableView

    2022年1月11日
    40
  • linux中777是什么权限_centos切换到root用户

    linux中777是什么权限_centos切换到root用户基本上就是全部开放读写执行操作权限一个文件有三个权限,分别是读、写和执行,它们对应的数分别是4、2和1。如果某个用户只有读权限没有写和执行权限当然就是4,如果三个如果有读和执行权限就是5(4+1)所以有全部权限就是7了。而一个文件或文件夹面对的用户分三类:所属用户、所属用户的组其他用户以及组外用户。所以777三个数字就是对应这三个用户对象全部都有读、写、执行权限。如果是所属用户有全部权限,组员有读…

    2022年10月9日
    2
  • odrive入门教程(securecrt使用教程串口)

    ODrive官方入门指南中,采用的是USB连接控制模式(中文翻译版本链接)使用的是NativeProtocol。当我们需要尝试串口通信实现时,需要专程ASCII协议来进行串口通信实现相关的命令,结合着入门指南以及ODrive中的相关属性方法参数,将流程中用到的相关方法整理如下:importserialimporttimeted=serial.Serial(port=’/dev/tty.wchusbserial1470′,baudrate=115200)ted.writ

    2022年4月16日
    52

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号