spring和dwr的整合
2012-08-13 19:34
204 查看
//dwr.xml,路径是在web-inf/dwr.xml
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
"http://directwebremoting.org/schema/dwr20.dtd">
<dwr>
<allow>
<convert match="com.pojos.*" converter="bean"></convert>
<!--这是让ckService给spring容器实例化-->
<create javascript="myjs" creator="spring">
<!--第一个参数是一个固定的值,第二个参数是一个被spring容器实例化的bean的name的值-->
<param name="beanName" value ="ckService"></param>
<!--这是这个service中包含的方法-->
<include method="getID"/>
<include method="saveForm"/>
<include method="updateForm"/>
</create>
</allow>
</dwr>
//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:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
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/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/utilhttp://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="TSaleformDAO" class="com.dao.TSaleformDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="TSaleformDetailDAO"
class="com.dao.TSaleformDetailDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- service -->
<bean id="ckService" class="com.service.CKService">
<property name="tsaleformDAO" ref="TSaleformDAO"></property>
<property name="tsaleformDetailDAO" ref="TSaleformDetailDAO"></property>
</bean>
<!-- 事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 事务属性 -->
<tx:advice id="mytx">
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<!-- 织入 -->
<aop:config>
<aop:advisor advice-ref="mytx" pointcut="execution(* com.service.*.*(..))"/>
</aop:config>
</beans>
//hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">scott</property>
<property name="connection.url">
jdbc:oracle:thin:@127.0.0.1:1521:ora92
</property>
<property name="dialect">
org.hibernate.dialect.Oracle9Dialect
</property>
<property name="myeclipse.connection.profile">oracle</property>
<property name="connection.password">tiger</property>
<property name="connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<property name="show_sql">true</property>
<mapping resource="com/pojos/TSaleform.hbm.xml" />
<mapping resource="com/pojos/TSaleformDetail.hbm.xml" />
</session-factory>
</hibernate-configuration>
//pojos和dao就省略
//页面的调用跟上一章讲的dwr页面的调用差不多
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
"http://directwebremoting.org/schema/dwr20.dtd">
<dwr>
<allow>
<convert match="com.pojos.*" converter="bean"></convert>
<!--这是让ckService给spring容器实例化-->
<create javascript="myjs" creator="spring">
<!--第一个参数是一个固定的值,第二个参数是一个被spring容器实例化的bean的name的值-->
<param name="beanName" value ="ckService"></param>
<!--这是这个service中包含的方法-->
<include method="getID"/>
<include method="saveForm"/>
<include method="updateForm"/>
</create>
</allow>
</dwr>
//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:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
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/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/utilhttp://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="TSaleformDAO" class="com.dao.TSaleformDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="TSaleformDetailDAO"
class="com.dao.TSaleformDetailDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- service -->
<bean id="ckService" class="com.service.CKService">
<property name="tsaleformDAO" ref="TSaleformDAO"></property>
<property name="tsaleformDetailDAO" ref="TSaleformDetailDAO"></property>
</bean>
<!-- 事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 事务属性 -->
<tx:advice id="mytx">
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<!-- 织入 -->
<aop:config>
<aop:advisor advice-ref="mytx" pointcut="execution(* com.service.*.*(..))"/>
</aop:config>
</beans>
//hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">scott</property>
<property name="connection.url">
jdbc:oracle:thin:@127.0.0.1:1521:ora92
</property>
<property name="dialect">
org.hibernate.dialect.Oracle9Dialect
</property>
<property name="myeclipse.connection.profile">oracle</property>
<property name="connection.password">tiger</property>
<property name="connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<property name="show_sql">true</property>
<mapping resource="com/pojos/TSaleform.hbm.xml" />
<mapping resource="com/pojos/TSaleformDetail.hbm.xml" />
</session-factory>
</hibernate-configuration>
//pojos和dao就省略
//页面的调用跟上一章讲的dwr页面的调用差不多
相关文章推荐
- 使用MyEclipse集成SSH和DWR(三)整合Spring和DWR
- DWR通过Annotation与spring整合
- Spring整合DWR
- Spring完全整合DWR(转)
- Ajax------------- spring+dwr整合
- dwr spring整合
- DWR的安装使用和与spring的整合
- SSH整合之使用spring-DWR实现动态综合查询数据
- DWR+Spring+Hibernate的整合
- Spring+hibernate+DWR整合
- dwr和spring的整合
- spring整合dwr 3.0 聊天功能
- dwr spring整合
- Spring与DWR整合
- dwr和struts2和spring整合
- Spring整合Dwr,Cannot locate BeanDefinitionParser for element [annotation-scan]
- spring 与dwr 3整合遇到的问题
- dwr3.0整合spring2.5全注解配置
- spring整合dwr架构(ftl+ssm)以及dwr.xml配置,原理,优缺点讲解,面试题总结
- dwr和spring的整合