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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 软件工程:数据流图和结构图怎么画?

    软件工程:数据流图和结构图怎么画?文章目录Step1:根据软件的功能描述,绘制数据流图:Step2:根据数据流图,分级绘制结构图:•边界划分:•第一级分解:•第二级分解:•精化减少耦合:Step1:根据软件的功能描述,绘制数据流图:问题表述:假设的仪表板将完成下述功能:(1)通过模数转换实现传感器和微处理机接口;(2)在发光二极管面板上显示数据;(3)指示每小时英里数(mph),行驶的里程,每加仑油行驶的英里数(mpg)等等;(4)指示加速或减速;(5)超速警告:如果车速超过55英里/小时,则发出超速警告铃声。首先了

    2022年6月15日
    84
  • 阿里笔试题整理1

    阿里笔试题整理11.下面哪一个不是动态链接库的优点?(B)A.共享B.装载速度快C.开发模式好D.减少页面交换知识补充1)动态链接库:a.动态链接提供了一种方法,使进程可以调用不属于其可执行代码的函数。b.使用动态链接库可以更为容易地将更新应用于各个模块,而不会影响该程序的其他部分。c.动态链接库文件,是一种不可执行的二进制程序文件,它允许程序共享执行特殊任务所必需的代码和其他资源。https…

    2022年5月16日
    62
  • 标志寄存器EFLAGS中的IF标志可以屏蔽MINI中断相应_cpsr寄存器标志位

    标志寄存器EFLAGS中的IF标志可以屏蔽MINI中断相应_cpsr寄存器标志位EFL介绍EFL的所有标志全称如上图所示,前8位(0~7)因为用不到,所以不作介绍,想看的可以点击原文链接。状态控制位1.追踪标志位TF(TrapFlag)当追踪标志TF被置为1时,CPU进入单步执行方式,即每执行一条指令,产生一个单步中断请求。这种方式主要用于程序的调试。指令系统中没有专门的指令来改变标志位TF的值,但可直接通过文末介绍的方法来进行修改。2.中断允许标志位…

    2022年10月30日
    0
  • 大数据时代,何来隐私保护_大数据时代人还有什么隐私

    大数据时代,何来隐私保护_大数据时代人还有什么隐私数据影响力正在不断增强。网络上的个人信息帮助特朗普赢得了总统竞选,而民众的在线身份一次又一次的让Facebook突破底线。但由于美国大选以及最近揭露的Facebook数据泄密丑闻,不仅引来了联邦贸易委员会的调查,还让在线消费者和立法者对数据在我们生活中的角色提出了质疑。而数据科学家们也开始质疑起自己的未来。Facebook首席执行官马克扎克伯格对公司造成的疏忽表示道歉,但是对一些数据专家来说,这是…

    2022年9月28日
    0
  • 从零开始学习UCOSII操作系统15–总结篇[通俗易懂]

    从零开始学习UCOSII操作系统15–总结篇[通俗易懂]从零开始学习UCOSII操作系统15–总结篇前言:在大学的时候,我们班级上面都有很多人觉得学习UCOSII(包括UCOSIII)是没什么厉害的,因为很多人都喜欢去学习Linux操作系统,但是,但是,真实的对整个UCOSII操作系统进行学习,我可以保证,如果你是基于源码级别的阅读的话,绝对是不简单的。仅仅是调用几个API的话,是永远用不好UCOSII的操作系统的。还有你真正学通了UCO

    2022年5月4日
    281
  • 关于UrlHttpConnection.setRequestProperty()的调用顺序问题的验证「建议收藏」

    关于UrlHttpConnection.setRequestProperty()的调用顺序问题的验证「建议收藏」因为在项目中使用到了HttpURLConnection请求资源,对于其中的方法setRequestProperty()

    2022年9月10日
    0

发表回复

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

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