急!!!spring整合问题

Tito10 2009-03-25 05:19:39
请问下大家,为什么我用struts执行到action里面,业务层的对象要通过在struts-config.xml里面配置个
<controller>
<set-property perty="processorClass"
value="org.springframework.web.struts.DelegatingRequestProcessor" />
</controller>
才能被实例化呢?

现在我进到了业务层的方法里面,dao的对象又没有实例化了,要怎么配置才能让dao实例化呢?下面是我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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">


<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.microsoft.jdbc.sqlserver.SQLServerDriver">
</property>
<property name="url"
value="jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=letDB">
</property>
<property name="username" value="sa"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/yyun/struts/pojo/hbm/UserInfo.hbm.xml</value>
<value>com/yyun/struts/pojo/hbm/ReleaseInfo.hbm.xml</value></list>
</property></bean>

<!-- DAO层 -->
<bean id="UserInfoDAO" class="com.yyun.struts.dao.UserInfoDAO">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="ReleaseInfoDAO"
class="com.yyun.struts.dao.ReleaseInfoDAO">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>

<!-- 业务逻辑层 -->
<bean id="userManageService"
class="com.yyun.struts.serivce.impl.UserInfoServiceImp">
<property name="userInfoDao">
<ref local="UserInfoDAO" />
</property>
</bean>

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

<!-- 声明式事务切面(AOP) -->
<bean id="txProxyTemplate"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target" ref="userManageService"/>
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="do*">PROPAGATION_REQUIRED</prop>
<prop key="reg*">PROPAGATION_REQUIRED</prop>
<prop key="login*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>

<!-- 生成的动态代理类 -->
<bean id="custProxy" parent="txProxyTemplate">
<property name="target">
<ref bean="userManageService"/>
</property>
<property name="proxyTargetClass">
<value>true</value>
</property>
</bean>

<bean name="/reg" class="com.yyun.struts.action.UserAction">
<property name="biz">
<ref local="custProxy"/>
</property>
</bean>
</beans>
...全文
52 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hwy000 2009-03-26
  • 打赏
  • 举报
回复
是的,你可以通过custProxy来获取userManageService
<bean id="custProxy" parent="txProxyTemplate">
<property name="target">
<ref bean="userManageService"/>
</property>

Tito10 2009-03-25
  • 打赏
  • 举报
回复
问题解决了 我是将<bean name="/reg" class="com.yyun.struts.action.UserAction">
<property name="biz">
<ref local="custProxy这个换成了userManageService"/>
</property>
</bean>
但是这样就没有实现AOP了是吗?
要怎样才能通过代理来实现呢?
yang_zheng_2008 2009-03-25
  • 打赏
  • 举报
回复
mark
hwy000 2009-03-25
  • 打赏
  • 举报
回复
<controller>
<set-property perty="processorClass"
value="org.springframework.web.struts.DelegatingRequestProcessor" />
</controller>
是为了添加spring对web的支持框架
你的applicationContext.xml中
<bean name="/reg" class="com.yyun.struts.action.UserAction">
<property name="biz">
<ref local="custProxy"/>
</property>
</bean>
</beans>
name = "/reg"就是web的请求表示,引入那个类就是为了解析/reg. 不然的话你在学spring的时候不是要用MyBean mybean = (MyBean) factory.getBean("mybean");没发现现在不用了嘛..

你的UserInfoDAO应该被实例化了,如果你说的是ReleaseInfoDAO没被实例化的话,是因为,我没发现他在哪被关联

81,077

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧