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>


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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • 运维架构师-并不遥远的彼岸

    运维架构师-并不遥远的彼岸在百度里搜索运维架构师,你会发现招聘的职位还不少并且月薪、年薪都很可观。提到架构师,大家都觉得挺神秘的,而作为运维领域的架构师,站在系统稳定和高可用、高扩展的角度,其承载着太多的责任和挑战。对于运维工

  • kong网关架构_kong网关性能

    kong网关架构_kong网关性能Kong是一个使用了lua-nginx-module运行在Nginx之上的Lua应用。Kong是一个成熟的API网关解决方案。API网关,即APIGateway,是大型分布式系统中,为了保护内部服务而设计的一道屏障,可以提供高性能、高可用的API托管服务,从而帮助服务的开发者便捷地对外提供服务,而不用考虑安全控制、流量控制、审计日志等问题,统一在网关层将安全认证,流量控制,审计日志,黑白名单…

  • Mask Rcnn目标分割-训练自己数据集-详细步骤[通俗易懂]

    Mask Rcnn目标分割-训练自己数据集-详细步骤[通俗易懂]本文接着介绍了MaskRcnn目标分割算法如何训练自己数据集,对训练所需的文件以及训练代码进行详细的说明。本文详细介绍在只有样本图片数据时,如果建立MaskRcnn目标分割训练数据集的步骤。过程中用到的所有代码均已提供。

  • 关闭防火墙 linux_linux系统防火墙关闭

    关闭防火墙 linux_linux系统防火墙关闭抛开实际生产环境个人平时练习的时候安装虚拟机可能遇到过很多坑就很烦,可能很大一部分原因都是防火墙没关掉哈哈哈哈所以建议永久性关闭防火墙下面是CentOs7关闭防火墙的命令!1:查看防火状态systemctlstatusfirewalld如果是这样就开着呢如果是这样就是关着2:暂时关闭防火墙systemctlstopfirewalld3:重启防火墙systemctlenablefirewalld5:永久关闭后重启Linux永久关闭防火墙firewalld和selli

  • (五)通俗易懂理解——双向LSTM

    (五)通俗易懂理解——双向LSTM中文翻译作者博客:https://www.cnblogs.com/wangduo/p/6773601.html?utm_source=itdadao&utm_medium=referral英文原文作者网址:http://colah.github.io/posts/2015-08-Understanding-LSTMs/参考相关网址:https://www.imooc.com/art…

发表回复

您的电子邮箱地址不会被公开。

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