Spring+hibernate 配置文件
2017-08-03 15:12
330 查看
<?xml version="1.0" encoding="UTF-8"?> <!-- 配置xml需要的schema --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd"> <!-- 扫描包下面的所有的类是否受spring的管理,需要spring创建对象 --> <context:component-scan base-package="com.ac.test"> <!-- 不包含@Controller注解和@ControllerAdvice注解(配置全局异常处理的) (因为spring-mvc里面已经扫描并管理了,所以为了避免重复管理,应该排除) --> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> <context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/> </context:component-scan> <!-- 配置config.properties的文件路径 --> <context:property-placeholder location="classpath:config.properties" /> <!-- 配置数据库和连接池信息,使用config.properties里面的值 --> <bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <!-- 数据连接信息 --> <property name="jdbcUrl" value="${jdbc.url}"></property> <property name="driverClass" value="${jdbc.driverClassName}"></property> <property name="user" value="${jdbc.username}"></property> <property name="password" value="${jdbc.password}"></property> <!-- 初始化时获取三个连接(取值应在minPoolSize与maxPoolSize之间。默认值: 3) --> <property name="initialPoolSize" value="${jdbc.initialPoolSize}"></property> <!-- 连接池中保留的最小连接数,默认值:3 --> <property name="minPoolSize" value="${jdbc.minPoolSize}"></property> <!-- 连接池中保留的最大连接数,默认值:15 --> <property name="maxPoolSize" value="${jdbc.maxPoolSize}"></property> <!-- 当连接池中的连接数耗尽的时候,c3p0一次同时获取的连接数,默认值:3 --> <property name="acquireIncrement" value="${jdbc.acquireIncrement}"></property> <!-- 控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 --> <property name="maxStatements" value="${jdbc.maxStatements}"></property> <!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 --> <property name="maxStatementsPerConnection" value="${jdbc.maxStatementsPerConnection}"></property> <!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 --> <property name="maxIdleTime" value="${jdbc.maxIdleTime}"></property> </bean> <!-- 配置Hibernate的sessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <!-- 配置Hibernate实体类的路径(通过扫描的方式配置)允许使用通配符,例如:com.ac.test.*.entity --> <property name="packagesToScan"> <list> <value>com.ac.test.entity</value> </list> </property> <!-- 配置Hibernate属性 --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> </bean> <!-- 配置国际化 --> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="msg"></property> </bean> <!-- 声明式事务配置 --> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <!-- 配置通知(配置事务执行的方法定义的名称规则) --> <tx:advice id="myAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="del*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="*" read-only="true" /> </tx:attributes> </tx:advice> <!-- 配置AOP的规则 --> <aop:config> <!-- 配置切入点 --> <aop:pointcut id="pc" expression="execution(* com.ac.test.biz.*.*(..))" /> <aop:advisor pointcut-ref="pc" advice-ref="myAdvice" /> </aop:config> </beans>
相关文章推荐
- 使用Spring 来配置 hibernate 映射文件的 两种方法
- Hibernate注解配置 在Spring的配置文件里写法
- spring+hibernate的配置文件示例
- spring+jpa(hibernate) 配置文件代码
- Struts+spring+hibernate集成的配置文件
- spring+hibernate 配置文件(applicationContext.xml)实例
- spring配置hibernate映射文件的4种方式
- spring2.5 及 hibernate annotation 配置文件笔记
- ssh框架中spring整合hibernate的配置文件模板(带详细注释)
- spring配置hibernate映射文件
- spring整合hibernate配置文件
- Spring整合Hibernate开发 - 使用事务管理器操作数据库 - 主配置文件
- SpringMVC+HibernateValidator,配置在properties文件中的错误信息回显前端页面出现中文乱码
- Spring 整合 Hibernate 的一处简化引入PO映射文件配置
- Spring整合Hibernate配置(使用hibernate.cfg.xml文件)
- eclipse 新建 maven 项目 添加 spring hibernate 的配置文件 详情
- springMVC+hibernate+spring干净的一个配置文件
- spring整合hibernate的一个配置文件
- spring整合hibernate(不带hibernate配置文件)
- 整合Struts2.3.20 Spring4.1.3 Hibernate4.3.7 配置文件