您的位置:首页 > 编程语言 > Java开发

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页面的调用差不多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: