其实你 最好把hibernate的配置文件配置到spring.xml里,至于它的 生成很简单,根本不需要 手工写我总结了一个布奏,很详细,你 可以试试,我 相信你 会成功!
----------------------------------------------------------------
1. 创建web工程
2.创建包并加载Spring
步骤 :单击工程名----——MyEclipse-----Add Spring Capabilitiles-----
选择Spring version的(Spring1)并选择价包
( 1. Spring 1.2 Aop Librarues
2. Spring 1.2 Core Libraries
3. Spring 1.2 ORM/DAO/Hibernate3 Libraries
4. Spring 1.2 Web Libraries
)----点击Next
----- 把File重命名为:spring ---点击Finish
3.在MyEclipseDataSourse中配置好你所要用的数据源
4.加载Hibernate
步骤 :单击工程名----——MyEclipse-----Add Hibernate Capabilitiles----
选择Hibernate Specification的(Hibernate 3 )并选择价包
( 1. Hibernate 3.0 Core Libraries
2. Hibernate 3.0 Advanced Support Libraries
)
----点击Next----选择Spring configuration file----点击Next
----选择Existing Spring configuration file 把SessionFactory ID 起名:sessionfac
----点击Next-----
(
1.给Bean Id 起名:ds
2.DB Driver 选择刚才配置好的数据源名
)----- 点击Next ----Java package 选择(com.xaccp.util)---点击Finish5.加载struts6.生成实体类
步骤:1.在 MyEclipseDataSourse中选择你所需要的表----点击表----Hibernete Reverse Engineering
2.Java src folder 选择(com.xaccp.entity)
选择(
1.Hibernate mapping file
2.Update hiberbate configuration with mapping file location
3.Java Data Object 注意:不选择Create abstract class
4.Java Data Access Object(DAO) (Hibernate 3 only)
5.Generate precise findBy methods
)
----点击Next ---把ID Geberator 选择native---点击Next--
点击Users 把ID Generator选择(native)
选择Include referenced tables(A->B)
选择Include referenced tables(A<-B)
-----点击Finish---弹出对话框选择(NO)
7. 把entity包内的DAO移动到com.xaccp.dao并在spring文件中做相应的修改
8.自己写个类MyDelegatingRequestProcessor继承DelegatingRequestProcessor,重写processPreprocess,实现转码功能
例如:request.setCharacterEncoding("utf-8");
9.在Sturts-config-xml配置
在<action-mappings /> 下配置:<controller processorClass="com.xaccp.util.MyDelegatingRequestProcessor"></controller>
在<message-resources parameter="com.xaccp.struts.ApplicationResources" />下配置插件
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="classpath:spring.xml"/>
</plug-in>
10.在spring.xml配置
1.生成htm 相当与生成Transaction
</bean >
<bean id="htm" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionfac"></property>
</bean>
2. 把每个类的dao 注入到相应的所需的biz 注意:(biz的dao 必须具有set方法)
3. 创建事务
<bean id="basetarget" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="htm"></property>
<property name="transactionAttributes">
<props>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="upd*">PROPAGATION_REQUIRED</prop>
<prop key="del*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
4.组装带事务的biz,让它里面的每个dao都具有事物
例如:
</bean>
<bean id="usebiz" parent="basetarget">
<property name="target" ref="stubiztarget"></property>
</bean>
5.给action里的biz注入
<bean name="/stu" class="com.xaccp.struts.action.StuAction">
<property name="biz" ref="usebiz"></property>
</bean>
-----------------------------------------------------
----------------------------------------------------------------
1. 创建web工程
2.创建包并加载Spring
步骤 :单击工程名----——MyEclipse-----Add Spring Capabilitiles-----
选择Spring version的(Spring1)并选择价包
( 1. Spring 1.2 Aop Librarues
2. Spring 1.2 Core Libraries
3. Spring 1.2 ORM/DAO/Hibernate3 Libraries
4. Spring 1.2 Web Libraries
)----点击Next
----- 把File重命名为:spring ---点击Finish
3.在MyEclipseDataSourse中配置好你所要用的数据源
4.加载Hibernate
步骤 :单击工程名----——MyEclipse-----Add Hibernate Capabilitiles----
选择Hibernate Specification的(Hibernate 3 )并选择价包
( 1. Hibernate 3.0 Core Libraries
2. Hibernate 3.0 Advanced Support Libraries
)
----点击Next----选择Spring configuration file----点击Next
----选择Existing Spring configuration file 把SessionFactory ID 起名:sessionfac
----点击Next-----
(
1.给Bean Id 起名:ds
2.DB Driver 选择刚才配置好的数据源名
)----- 点击Next ----Java package 选择(com.xaccp.util)---点击Finish5.加载struts6.生成实体类
步骤:1.在 MyEclipseDataSourse中选择你所需要的表----点击表----Hibernete Reverse Engineering
2.Java src folder 选择(com.xaccp.entity)
选择(
1.Hibernate mapping file
2.Update hiberbate configuration with mapping file location
3.Java Data Object 注意:不选择Create abstract class
4.Java Data Access Object(DAO) (Hibernate 3 only)
5.Generate precise findBy methods
)
----点击Next ---把ID Geberator 选择native---点击Next--
点击Users 把ID Generator选择(native)
选择Include referenced tables(A->B)
选择Include referenced tables(A<-B)
-----点击Finish---弹出对话框选择(NO)
7. 把entity包内的DAO移动到com.xaccp.dao并在spring文件中做相应的修改
8.自己写个类MyDelegatingRequestProcessor继承DelegatingRequestProcessor,重写processPreprocess,实现转码功能
例如:request.setCharacterEncoding("utf-8");
9.在Sturts-config-xml配置
在<action-mappings /> 下配置:<controller processorClass="com.xaccp.util.MyDelegatingRequestProcessor"></controller>
在<message-resources parameter="com.xaccp.struts.ApplicationResources" />下配置插件
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="classpath:spring.xml"/>
</plug-in>
10.在spring.xml配置
1.生成htm 相当与生成Transaction
</bean >
<bean id="htm" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionfac"></property>
</bean>
2. 把每个类的dao 注入到相应的所需的biz 注意:(biz的dao 必须具有set方法)
3. 创建事务
<bean id="basetarget" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="htm"></property>
<property name="transactionAttributes">
<props>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="upd*">PROPAGATION_REQUIRED</prop>
<prop key="del*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
4.组装带事务的biz,让它里面的每个dao都具有事物
例如:
</bean>
<bean id="usebiz" parent="basetarget">
<property name="target" ref="stubiztarget"></property>
</bean>
5.给action里的biz注入
<bean name="/stu" class="com.xaccp.struts.action.StuAction">
<property name="biz" ref="usebiz"></property>
</bean>
-----------------------------------------------------
解决方案 »
- struts2警告 There is no Action mapped for namespace / and action name login
- 请教一下,Action中的方法,如何实现单例
- 新人求助
- 有关tomcat5.5中的admin模块安装的问题.
- 自己做的管理系统登陆不稳定,请大家帮忙看看,谢谢
- 如何获取XML中空元素的属性及值
- 竹哥,Ext的树向表拖拽的问题,帮我解决下
- struts和MVC问题?
- 如何对字符串求值?
- illegal attempt to dereference collection
- 求个LOG4J文件
- struts,sping,hibernate这三种框架之间的联系,各自之间的区别是什么?
没什么的啊
只要照这参数填就OK了什么地址,用户名,密码,等等
记得要把包导入哦
DBCP类包位于 <SPRING_HOME>/lib/jakarta-commons/commons-dbcp.jar,DBCP是一个依赖Jakarta commons-pool对象池机制的数据库连接池,所以在类路径下还必须包括<SPRING_HOME>/lib/jakarta-commons/commons-pool.jar。下面是使用DBCP配置MySql数据源的配置片断: <bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://127.0.0.1/sshwithdbcp">
</property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>