spring(2.5或者3.2)集成hibernate3.5的配置文件

1 篇文章 0 订阅
1 篇文章 0 订阅
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context"
	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"
	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.xsd
       http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
	<!-- 
		<context:annotation-config/>他的作用是隐式地向 Spring 容器注册
		AutowiredAnnotationBeanPostProcessor(使用@Autowired注解)、 
		CommonAnnotationBeanPostProcessor(使用@ Resource 、@ PostConstruct、@ PreDestroy)、 
		PersistenceAnnotationBeanPostProcessor(使用@PersistenceContext注解)、 
		RequiredAnnotationBeanPostProcessor(使用 @Required的注解)
		这 4 个BeanPostProcessor。
		传统注入:
		<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor "/> 
		<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/> 
		...
		 -->
	<context:annotation-config />
	
	<!-- 使用注解一般都会配置扫描包路径选项 
	该配置项其实也包含了自动注入上述processor的功能,
	因此当使用 <context:component-scan/> 后,
	就可以将 <context:annotation-config/> 移除了。
	-->
	<context:component-scan base-package="cn.sd.erp" />
	
	<!-- 
	加载properties文件.
	如果想要配置多个properties文件
	<context:property-placeholder location="classpath:jdbc.properties"/>
	<context:property-placeholder location="classpath:jdbc.properties"/>
	这种方式是不被允许的,一定会出"Could not resolve placeholder"。

	解决方案:
	(1) 在Spring 3.0中,可以写:
	<context:property-placeholder location="xxx.properties" ignore-unresolvable="true"/>
	<context:property-placeholder location="xxx.properties" ignore-unresolvable="true"/>

	(2) 但是在Spring 2.5中,<context:property-placeholder>没有ignore-unresolvable属性,所以就不能使用上面的那种方法去配置,可以改如下的格式:
	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:/jdbc.properties</value>
			</list>
		</property>
		</bean>
	 -->
	 <context:property-placeholder location="/WEB-INF/jdbc_hibernate.properties"/>
	 
	 <!-- 配置数据数据库连接池这里使用c3p0 -->
	 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
	 	<property name="driverClass" value="${jdbc.driverClassName}" />
		<property name="jdbcUrl" value="${jdbc.url}" />
		<property name="user" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		<property name="initialPoolSize" value="${jdbc.initialPoolSize}" />
		<property name="minPoolSize" value="${jdbc.minPoolSize}" />
		<property name="maxPoolSize" value="${jdbc.maxPoolSize}" />
		<property name="maxIdleTime" value="${jdbc.maxIdleTime}" />
		<property name="acquireIncrement"
			value="${jdbc.acquireIncrement}" />
		<property name="idleConnectionTestPeriod" value="60"></property>
	 </bean>
	 
	 <!-- 
	 1.关于AnnotationSessionFactoryBean和LocalSessionFactoryBean的区别.
	 annotation是注释、注解 的意思,在hibernate配置实体及字段与表的映射时,
	 annotationSessionFactoryBean提供一种注解的方式来映射,
	 它可以依赖@注解通过实体类生成表(包括字段、主键···)。
	 这种方法是spring2.5以后才有的。
	 2.LocalSessionFactoryBean
	  在applicationContext.xml中配置之后,需要另外一个***.hbm.xml的配置文件对实体和表的具体映射进行配置。
	  <property name="mappingLocations">
		<list>
		<value>classpath:/cn/cuit/crm/domain/*.hbm.xml</value>
		</list>
		</property>
	 3.如果使用org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean,还需要配置
	 <property name="annotatedClasses">
			<list>
				<value>com.cddgg.jcoa.domain.authority.Department</value>
				<value>com.cddgg.jcoa.domain.authority.Log</value>
				...
			</list>
	 <property>
	  -->
	 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
	 	<property name="dataSource" ref="dataSource" />
	 	<property name="mappingLocations">
					<list>
						<value>classpath:/cn/sd/erp/domain/*.hbm.xml</value>
					</list>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					${hibernate.dialect}
				</prop>
				<prop key="hibernate.show_sql">
					${hibernate.show_sql}
				</prop>
				<prop key="hibernate.hbm2ddl.auto">
					${hibernate.hbm2ddl.auto}
				</prop>
				<prop key="hibernate.format_sql">
					${hibernate.format_sql}
				</prop>
			</props>
		</property>
	 </bean>
	 
	 <!-- 申明一个事务管理容器,这个容器里面需要注入sessionFactory -->
	 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
	 	<property name="sessionFactory" ref="sessionFactory"/>
	 </bean>
	 
	 <!-- 事务策略:对于具体方法进行开启事务 -->
	 <tx:advice id="crudAdvice" transaction-manager="transactionManager">
	 	<tx:attributes>
	 		<tx:method name="get*" read-only="true"/>
	 		<tx:method name="list*" read-only="true"/>
	 		<tx:method name="*" />
	 	</tx:attributes>
	 </tx:advice>
	 
	 <!-- AOP配置 -->
	 <aop:config>
	 	<!-- 切点定义,对哪些类进行切点 -->
	 	<aop:pointcut expression="execution(* cn.sd.crm.erp..*Service*.*(..))" id="crudPointCut"/>
	 	<aop:advisor advice-ref="crudAdvice" pointcut-ref="crudPointCut"/>
	 </aop:config>

	
</beans>




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是一个实际使用中的项目,可访问 http://cdbke.cuit.edu.cn 可查看效果及功能,后台需要登录后才能使用(出于安全性考虑这里就不给大家介绍了,另外还有一个struts1版本的,如有需要可以与我联系)。 此项目整合了目前主流和最前源的web开发技术:采用ehcache实现二级缓存(包含查询缓存);用sf4j及logback(log4j的升级版)记录日志;proxool(据说是dbcp和c3p0三者中最优秀的)做连接池;使用jquery的ajax实现仿google人名自动补全;头像上传剪切压缩处理。 包含有完整的jar包和源代码,可以直接下载编译部署和运行,这是专门为我们实验室定制开发的。虽然后台逻辑并不复杂,但已经包含了架构基于s2sh技术型系统的全部基础部分:如分页,缓存,文件上传,连接池等。很适合学习使用,希望对初学JavaEE WEB开的人有所帮助。 这个资源在去年发布了第一版,已经有很多朋友下了觉得对他们有帮助,所以我才再发了一个第二版,希望对有需要的朋友有所帮助。本版本全面更新了jar包,全部使用了当前最新版本的jar包,struct2.1.8 spring3 hibernate3.5,全面使用注解取代xm的l配置。 另外增加了一个ant构建脚本,支持使用hudson完成每日构建,持续集成,自动测试,代码规范检查,代码审查等功能(与此相关的jar包由于上传文件大小限制未导入) 本系统一直在使用中,所以还会不段更新,之后我打算再做一个基于javaee6的实现,给需要想学习ejb3.1等技术的朋友一个参考实现 集成测试相关jar包和更新构建脚本下载:http://download.csdn.net/source/2427972

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值