很久没看spring和hibernate整合的东西了,正好赶上新项目,也搭个架子,就抽空学习了下,这里记录下来以便复习!
首先,下载spring和hibernate最新版本,最近都更新的挺频繁的,包也有点不同。(不明白为什么spring不出中文文档,虽然hibernate的有乱码,总算还能看的过去!)
其次新建一个普通的工程,创建applicationContext.xml文件,头文件命名空间什么的就直接从网上找别人的拷贝好了,没用myeclipse,不太方便,自己写出来也不太可能。(IE9怎么插入不了图片和代码?还是我级别太低?)
<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: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-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<!-- 注解需要用到的-->
<context:component-scan base-package="com.wenbo" />
<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/manchat" />
<property name="user" value="root" />
<property name="password" value="2580233" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<!--hibernate注解需要改变的东西-->
<property name="annotatedClasses">
<list>
<value>com.wenbo.model.User</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.default_batch_fetch_size=8
hibernate.generate_statistics=true
</value>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution (* com.wenbo.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" />
</aop:config>
最后贴上整合的时候在下载的包里找不到的不常用的jar
分享到:
相关推荐
Myeclipse8.5下搭建SSH框架(图解)Struts2.1+Spring3.0+Hibernate3.3
spring3.0+hibernate3.3+struts2整合jar包
搭建Struts2.1+Spring3.0+Hibernate3.3框架
Myeclipse10下搭建SSH框架(图解)Struts2.1+Spring3.0+Hibernate3.3 该文件的内容来自网络,我搜集并整理供大家参考学习。
struts2.1+spring3.0+hibernate3.3 整合小例子 oracle 数据库
struts2.0+hibernate3.0+spring3.5框架搭建 通俗易懂,适合初学者;里面有struts2.0+hibernate3.0+spring3.5框架搭建的详细配置 详细:http://itba.taobao.com 如有不懂联系:QQ:294647378
jquery easy UI+spring3.0+struts2.1.8.1+hibernate3.5整合的CRM包括所有Jar包.
三大框架Struts2+Spring2.5+Hibernate3.5的整合开发
用spring security3 spring3.0 hibernate3.5 struts2整合的安全框架,欢迎大家下载
MyEclipse-10.0下Struts2.1+Spring3.0+Hibernate3.3整合过程+源码
spring3.0+hibernate3.6+struts2.38整合包加配置文件下载ctl+v一下搞定
struts2.2.3+spring3.0.1+hibernate3.6.5整合jar包
Spring3.0+Hibernate4.0+SpringMVC整合ExtJS4是一个集成的应用系统,希望对学习javaweb和extjs的朋友有帮助
spring3.0+hibernate3.0+struts2,此Demo有,增,删,查,改
csdn只能上传50MB的,不够用,我上传的是网盘的下载地址,包含PDF和源码,PDF是226MB的清晰完整版,源码也是完整的。 附:源码使用方式,看到有.project的的,可以直接通过import导到myeclipse里面,没有这个文件的...
Flex4+Blazeds4.0+Spring3.0+hibernate2.5.2整合笔记,自己看了不少网上所说,都没配置成功,后来通过spring的一个插件搞定了,希望对大家有帮助吧!
spring3.0+hibernate3.0+struts2整合实现,直接导入就可以用。
spring3.0+hibernate3.0+struts2
Struts1+Spring3.0+Hibernate3.3 练习登录注册的例子,适合初学者