springMVC中bean容器:bean.xml的配置
来源:互联网 发布:淘宝网购物情侣装 编辑:程序博客网 时间:2024/06/05 17:58
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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:xsi="http://www.w3.org/2001/XMLSchema-instance"
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/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!-- 1.添加组件对注解的支持:扫描 -->
<context:component-scan base-package="com.lovo.elec"></context:component-scan>
<!-- 2.C3P0连接池 (另一种还有dbcp) -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<!-- &的转义字符:& -->
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/elec_u16?useUnicode=true&characterEncoding=utf-8"></property>
<property name="user" value="root"></property>
<property name="password" value="root"></property>
<!-- 连接池中保留的最小连接数。 -->
<property name="minPoolSize" value="5"></property>
<!-- 连接池中保留的最大连接数。Default: 15 -->
<property name="maxPoolSize" value="30"></property>
<!-- 初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
<property name="initPoolSize" value="10"></property>
<!-- 最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime" value="60"/>
<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
<property name="acquireIncrement" value="5" />
<!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30-->
<property name="acquireRetryAttempts" value="30" />
<!-- 获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效
保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试
获取连接失败后该数据源将申明已断开并永久关闭。Default: false -->
<property name="breakAfterAcquireFailure" value="true" />
</bean>
<!-- 3.创建sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation">
<value>
classpath:hibernate.cfg.xml
</value>
</property>
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 4.创建事务管理器 -->
<bean id="transManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 5.事务处理:注解 -->
<tx:annotation-driven transaction-manager="transManager" />
<!-- 事务处理:配置文件 -->
<!--
<tx:advice id="adviceBean" transaction-manager="trManager">
<tx:attributes> <tx:method name="save*" isolation="DEFAULT"
propagation="REQUIRED" read-only="false"/> <tx:method name="update*"
isolation="DEFAULT" propagation="REQUIRED" read-only="false"/>
<tx:method name="delete*" isolation="DEFAULT" propagation="REQUIRED"
read-only="false"/> <tx:method name="*" read-only="true"/>
</tx:attributes> </tx:advice> <aop:config> <aop:pointcut
expression="execution(* cn.lovo.elec.service..*.*(..))"
id="pointcutBean"/> <aop:advisor advice-ref="adviceBean"
pointcut-ref="pointcutBean"/> </aop:config>
-->
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
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:xsi="http://www.w3.org/2001/XMLSchema-instance"
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/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!-- 1.添加组件对注解的支持:扫描 -->
<context:component-scan base-package="com.lovo.elec"></context:component-scan>
<!-- 2.C3P0连接池 (另一种还有dbcp) -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<!-- &的转义字符:& -->
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/elec_u16?useUnicode=true&characterEncoding=utf-8"></property>
<property name="user" value="root"></property>
<property name="password" value="root"></property>
<!-- 连接池中保留的最小连接数。 -->
<property name="minPoolSize" value="5"></property>
<!-- 连接池中保留的最大连接数。Default: 15 -->
<property name="maxPoolSize" value="30"></property>
<!-- 初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
<property name="initPoolSize" value="10"></property>
<!-- 最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime" value="60"/>
<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
<property name="acquireIncrement" value="5" />
<!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30-->
<property name="acquireRetryAttempts" value="30" />
<!-- 获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效
保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试
获取连接失败后该数据源将申明已断开并永久关闭。Default: false -->
<property name="breakAfterAcquireFailure" value="true" />
</bean>
<!-- 3.创建sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation">
<value>
classpath:hibernate.cfg.xml
</value>
</property>
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 4.创建事务管理器 -->
<bean id="transManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 5.事务处理:注解 -->
<tx:annotation-driven transaction-manager="transManager" />
<!-- 事务处理:配置文件 -->
<!--
<tx:advice id="adviceBean" transaction-manager="trManager">
<tx:attributes> <tx:method name="save*" isolation="DEFAULT"
propagation="REQUIRED" read-only="false"/> <tx:method name="update*"
isolation="DEFAULT" propagation="REQUIRED" read-only="false"/>
<tx:method name="delete*" isolation="DEFAULT" propagation="REQUIRED"
read-only="false"/> <tx:method name="*" read-only="true"/>
</tx:attributes> </tx:advice> <aop:config> <aop:pointcut
expression="execution(* cn.lovo.elec.service..*.*(..))"
id="pointcutBean"/> <aop:advisor advice-ref="adviceBean"
pointcut-ref="pointcutBean"/> </aop:config>
-->
</beans>
0 0
- springMVC中bean容器:bean.xml的配置
- spring 8 bean配置--IOC容器中bean的生命周期
- Spring中bean的基本xml配置
- Spring中bean的基本xml配置
- Spring中bean的基本xml配置
- Spring中bean的基本xml配置
- Spring中bean的基本xml配置
- Spring中bean的基本xml配置
- spring中bean的基本xml配置
- spring中bean的基本xml配置
- spring中bean的基本xml配置
- spring中bean的基本xml配置
- spring中bean的基本xml配置
- 容器中Bean的生命周期
- 容器中Bean的生命周期
- 容器中Bean的生命周期
- Spring bean.xml的配置
- Spring Bean的XML配置
- java并发编程(一)-线程池
- recyclerView 的坑
- popen管道
- C语言---格式问题
- Android源码地址
- springMVC中bean容器:bean.xml的配置
- AOP事务原理相应连接
- rtsp流测试地址
- jboss-as-7.1.1.Final:(四)Eclipse集成下的自动发布和JSP的热加载
- Django REST Framework v.3官方中文教程 索引
- 第6周-项目4-静态成员应用
- [JEEWX问题修复] JeeWX开源版2.3几处代码修改。
- 离散傅里叶变换(DFT)数学例子
- Jenkins ProcessTreeKiller 问题。