spring4、hibernate4整合xml配置

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" 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/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">
<!-- 配置属性覆盖器 ,可以将数据库的配置信息配置到properties中,便于阅读、修改和维护-->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>
<!-- 数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- 配置hibernate会话工厂以及hibernate属性 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- xml实体映射使用
<property name="mappingLocations">
<value>classpath*:/org/ltsh/**/*.hbm.xml</value>
</property>
-->
<property name="packagesToScan">
<list>
<value>com.test.model</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect = org.hibernate.dialect.Oracle10gDialect
hibernate.hbm2ddl.auto = update
hibernate.show_sql=true
</value>
</property>
</bean>

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- 默认的注解映射的支持 -->
<context:annotation-config />
<context:component-scan base-package="com.test" /> <!-- 自动扫描该包路径下的所有注解 -->

<!-- 事务配置 -->
<!-- 定义事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>

</beans>

时间: 2024-08-04 17:41:37

spring4、hibernate4整合xml配置的相关文章

关于spring4和hibernate4整合,配置事务报“Cannot unwrap to requested type [javax.sql.DataSource]”错误的解决方法及心得

Cannot unwrap to requested type [javax.sql.DataSource] 配置hibernate4和spring4时,出现错误,解决方法: 1.我去了spring4中的事务配置,数据库可以正常执行并访问.如下: <!-- 配置Hibernate  数据事务 --> <bean id="transactionManager" class="org.springframework.orm.hibernate4.Hibernat

J2EE开发框架搭建(2) - springmvc4 + spring4 + hibernate4 整合

1. 打开hqhop-framework-parent项目下的pom.xml文件,添加springmvc4 , spring4 , hibernate4 ,以及数据源druid的依赖包,插件,依赖包版本号 <!-- data source 相关jar? --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version&g

SpringMvc+Spring4+Hibernate4整合常见错误

最近一直在做SpringMvc+Spring4+Hibernate4的整合,出了不少错误,这都是我们宝贵的经验啊,在整合的过程中,最大的问题就是 版本升级的问题,之前做过jdk1.6的例子,很顺利,但是升级到jdk1.8后,突然爆出了很多的错误,后来在调试的时候才发现,原来spring3和 jdk1.8是不兼容的版本,要么降低jdk到1.7及以下,或者升级spring版本,在更新换代和维稳的情况下,我选择了升级spring版本,结果 如果,咱们一起来看! 运行结果: 源码下载:springMvc

Spring4+Hibernate4 事务管理 配置 注解 AOP

在单独使用hibernate的时候 使用如下配置: <property name="hibernate.current_session_context_class">thread</property> 根据文档,这个是hibernate3.1以后的一个新扩展,目的在于可以让我们在某一个上下文环境(比如说当前线程)中可以通过SessionFactory.getCurrentSession()得到同一个session会话. 该方式hibernate会自动关闭sess

spring4+springmvc+springdataJPA+hibernate4整合懒加载问题

摘要 第一个问题 解决办法 第二个问题 解决办法 摘要 本文主要是为了解决"spring4+springmvc+springdataJPA+hibernate4整合",注解了OneToMany.ManyToOne,并配置了懒加载,然后报错的问题 第一个问题 org.hibernate.LazyInitializationException: could not initialize proxy - no Session at 解决办法: 在web.xml中,配置springSevlet

[SSH] Eclipse+Struts2+Hibernate4+Spring4的整合

在前面Struts2和Hibernate4的整合基础上,对Spring4进行整合,网上参考的大概都是Spring4+Hibernate3或者基于MyEclispe的,这里把自己研究后的配置和大家分享一下. 本次相关的版本如下: Spring : spring-framework-4.0.1.RELEASE 1.将相关的jar包导入: 1.1libs目录下包含所有的jar包(不需要复制结尾为sources和javadoc的jar包)到SSHProject项目的lib目录 1.2 Hibernate

Spring Hibernate4 整合配置文档

1 applicationContext.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:/

SSH 框架整合(maven版本 xml配置方式)

如何整合Struts2 Hibernate 和Spring 首先你必须了解三个框架是如何独立运行的:代码下载:http://download.csdn.net/detail/zhanglinlang/9775160 Struts2 是通过在web.xml 中 Filter拦截器来启动自己的核心类StrutsPrepareAndExecuteFilter,完成事件的分发. Spring 是通过 在web.xml 注册监听器来监听ContextLoaderListener,监听web应用的启动事件来

丢弃重口味的xml配置--spring4用groovy配置bean(转)

spring4之前,bean的配置可以主要分为两种方式,一种是使用基于xml,个人非常讨厌这种方式,因为明明一件很简单的事,放在xml中就会多了不少繁杂的信息.另一种方式,是从spring3.0开始,spring提供了是基于java的配置,相比于xml的配置方式,看起来会好一点儿.而在几天前release的spring4.0中,我们可以用groovy作为spring的配置文件啦!比起最早的基于xml配置,使用groovy会更加灵活,而且干扰信息会更少.比起基于java的配置,groovy配置还要