<?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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- 一个错误说明:schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/aop/spring-aop-3.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. 造成这个问题的原因是因为没有将aop的jar包导入工程中,所以报这个错,也说明spring会从本地去读取这个XSD-->
<!-- 从属性配置文件中读取值,dataSource.properties文件位于src目录下-->
<!-- 也可以写成下面这样
<context:property-placeholder location="classpath:dataSource.properties"/>
-->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:dataSource.properties</value>
</property>
</bean>
<!-- 数据源配置 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${mysql.driverClassName}"></property>
<property name="url" value="${mysql.url}"></property>
<property name="username" value="${mysql.username}"></property>
<property name="password" value="${mysql.password}"></property>
<!-- 可以从对象池中取出的对象最大个数,为 0 则表示没有限制,默认为 8 -->
<property name="maxActive" value="${mysql.maxActive}"></property>
<!-- 最大等待连接中的数量 , 设 0 为没有限制 (对象池中对象最大个数) -->
<property name="maxIdle" value="${mysql.maxIdle}"></property>
<!-- 最大等待秒数 , 单位为 ms, 超过时间会丟出错误信息 -->
<property name="maxWait" value="${mysql.maxWait}"></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQL5Dialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
</props>
</property>
<!-- 自动搜索com.utstar.ivas.model包下所有的实体类(@Entity) -->
<property name="packagesToScan">
<list>
<value>com.utstar.ivas.model</value>
</list>
</property>
<!-- 和packagesToScan属性一样的功能,annotatedClasses需要将每个实体类都配置在文件中,比较麻烦 -->
<!--
<property name="annotatedClasses">
<list>
<value>com.utstar.jqueryportal.model.Privilege</value>
<value>com.utstar.jqueryportal.model.RolePrivilege</value>
<value>com.utstar.jqueryportal.model.UserRole</value>
<value>com.utstar.jqueryportal.model.Role</value>
<value>com.utstar.jqueryportal.model.User</value>
<value>com.utstar.jqueryportal.model.SysUser</value>
</list>
</property>
-->
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="edit*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="publish*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 那些类的哪些方法参与事务 -->
<aop:config>
<!-- (* com.utstar.ivas.service.impl.*.*(..))的意思是任意修饰符 任意返回值 com.utstar.ivas.service.impl下的任何类的任意方法 任意参数,具体参考spring参考文档;如果(* com.utstar.ivas.service.impl..*.*(..))包后面有两个点,则代表包括任何子包 -->
<aop:pointcut id="allServiceMethod"
expression="execution(* com.utstar.ivas.service.impl.*.*(..))" />
<aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice" />
</aop:config>
<!-- 使Spring关注Annotation -->
<context:annotation-config />
<!-- 让Spring通过自动扫描来查询和管理Bean,会自动激活上面的标签,因此上面的标签也可以不加 -->
<context:component-scan base-package="com.utstar.ivas" />
</beans>
dataSource.properties:
mysql.driverClassName=com.mysql.jdbc.Driver
mysql.url=jdbc:mysql://localhost:3306/ssh?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true
mysql.username=root
mysql.password=root
mysql.maxActive=100
mysql.maxIdle=30
mysql.maxWait=500
分享到:
相关推荐
spring配置文件实例
使用Spring配置文件实现AOP
Spring配置文件集合Spring配置文件集合Spring配置文件集合Spring配置文件集合Spring配置文件集合Spring配置文件集合Spring配置文件集合
spring 配置文件 归类 IOC AOPspring 配置文件 归类 IOC AOP
spring配置文件详解,Spring的applicationContext.xml文件代码:
spring配置文件加密实现
spring 配置 文件
spring配置文件详解,交你如何理解spring,熟练运用spring
spring配置文件详细介绍 通过对xml配置的熟练掌握 相信spring真的太简单
大型项目的struts,spring配置文件
Spring配置文件:注入各种数据时配置文件的配置格式
Spring框架的一个配置文件。Spring框架主要解决了创建对象和管理对象的问题!
官方spring.xml中约束的引用说明文档,配置spring文件的时候添加约束所需要的文档说明.
spring配置文件是用于指导Spring工厂进行Bean生产、依赖关系注入(装配)及Bean实例分发的"图纸"。Java EE程序员必须学会并灵活应用这份"图纸"准确地表达自己的"生产意图"。Spring配置文件是一个或多个标准的XML文档...
java开发时使用的配置文档,希望能帮到大家。
NULL 博文链接:https://zheyiw.iteye.com/blog/1096213