interface:
package com.zjm.ssh2.user.services.iface;
import ........
public interface IUserService {
public List getSexList();
}UserService:
package com.zjm.ssh2.user.services;
import ........
public class UserService implements IUserService {
public List getSexList() {
return codedbDao.findAll();
}
}dwr:
<dwr>
<allow>
<create creator="spring" javascript="sexService">
<param name="beanName" value="UserService"/>
<include method="getSexList" />
</create>
<convert converter="bean" match="com.zjm.ssh2.pojo.Codedb">
<param name="include" value="id, text"></param>
</convert>
</allow>
</dwr>applicationContext.xml:
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" read-only="false" />
<tx:method name="save*" propagation="REQUIRED" read-only="false" />
<tx:method name="delete*" propagation="REQUIRED" read-only="false" />
<tx:method name="update*" propagation="REQUIRED" read-only="false" />
<tx:method name="edit*" propagation="REQUIRED" read-only="false" />
<tx:method name="attachDirty*" propagation="REQUIRED" read-only="false" />
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="get*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="daoMethod" expression="execution(* com.zjm.ssh2.*.dao.iface.*.*(..))" />
<aop:pointcut id="serviceMethod" expression="execution(* com.zjm.ssh2.*.services.iface.*.*(..))" />//把这句删掉,不要事务控制就正常,否则就报错
<aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethod" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod" />
</aop:config>
<bean id="UserService" class="com.zjm.ssh2.user.services.UserService">
<property name="codedbDao">
<ref bean="UserCodedbDAO" />
</property>
</bean>jsp:
<script src="${pageContext.request.contextPath}/dwr/engine.js"></script>
<script src="${pageContext.request.contextPath}/dwr/util.js"></script>
<script src="${pageContext.request.contextPath}/dwr/interface/sexService.js"></script>
<script type="text/javascript">
sexService.getSexList(function(selectlist){ }
);
</script>
事务控制里如果不要这个execution(* com.zjm.ssh2.*.services.iface.*.*(..))就正常
被事务控制就报错:object is not aninstance of declaring class
请问怎么回事
package com.zjm.ssh2.user.services.iface;
import ........
public interface IUserService {
public List getSexList();
}UserService:
package com.zjm.ssh2.user.services;
import ........
public class UserService implements IUserService {
public List getSexList() {
return codedbDao.findAll();
}
}dwr:
<dwr>
<allow>
<create creator="spring" javascript="sexService">
<param name="beanName" value="UserService"/>
<include method="getSexList" />
</create>
<convert converter="bean" match="com.zjm.ssh2.pojo.Codedb">
<param name="include" value="id, text"></param>
</convert>
</allow>
</dwr>applicationContext.xml:
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" read-only="false" />
<tx:method name="save*" propagation="REQUIRED" read-only="false" />
<tx:method name="delete*" propagation="REQUIRED" read-only="false" />
<tx:method name="update*" propagation="REQUIRED" read-only="false" />
<tx:method name="edit*" propagation="REQUIRED" read-only="false" />
<tx:method name="attachDirty*" propagation="REQUIRED" read-only="false" />
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="get*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="daoMethod" expression="execution(* com.zjm.ssh2.*.dao.iface.*.*(..))" />
<aop:pointcut id="serviceMethod" expression="execution(* com.zjm.ssh2.*.services.iface.*.*(..))" />//把这句删掉,不要事务控制就正常,否则就报错
<aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethod" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod" />
</aop:config>
<bean id="UserService" class="com.zjm.ssh2.user.services.UserService">
<property name="codedbDao">
<ref bean="UserCodedbDAO" />
</property>
</bean>jsp:
<script src="${pageContext.request.contextPath}/dwr/engine.js"></script>
<script src="${pageContext.request.contextPath}/dwr/util.js"></script>
<script src="${pageContext.request.contextPath}/dwr/interface/sexService.js"></script>
<script type="text/javascript">
sexService.getSexList(function(selectlist){ }
);
</script>
事务控制里如果不要这个execution(* com.zjm.ssh2.*.services.iface.*.*(..))就正常
被事务控制就报错:object is not aninstance of declaring class
请问怎么回事
解决方案 »
- Struts2 action路径问题
- Mybatis 如何 返回 List<String> 类型 或 List<Map<String,Object>>类型
- 请问List集合存了几个字符串,我要获取第几个字符串的时候,结果越界了,如何解决?
- 为什么我的struts2 intercept拦截器 老是编译错误 我只求编译通过就行
- 求教。关于weblogic运行时报错,之后就连接不上数据库的问题。
- 一波未平,一波又起.(Ftp上传问题)
- spring aop 问题 大家帮下
- 遇到一个问题我在 <input name="id" type="text" >里输入的值怎么在下一行代码里获得
- struts+hibernate+sql2000出现下面的错误,大家来看下.
- 请问谁知道学习Struts的好网站?
- struts2工程,启动时报debug Starting filter 'struts2',求助
- 关于业务层方法出现线程死锁
web.xml 补充 <filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter><bean id="UserService" class="com.zjm.ssh2.user.services.UserService">
<property name="codedbDao">
<ref bean="UserCodedbDAO" />
</property>
</bean>这里你的UserCodedbDAO 不要忘记了 是集成HibernateDaoSupport
并且不要忘记注入 sessionFactory <bean id="UserCodedbDAO" class="com.xxx.dao.impl.hibernate.DataDictionaryDAOImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
主要是应为你 在 jsp页面时候 session 已经关闭了
现在的情况是这样,我加上OpenSessionInViewFilter配置了,还是不行
而且dwr配置:
<dwr>
<allow>
<create creator="spring" javascript="sexService">
<param name="beanName" value="UserService"/>
<include method="getSexList" />
</create>
<convert converter="bean" match="com.zjm.ssh2.pojo.Codedb">
<param name="include" value="id, text"></param>
</convert>
</allow>
</dwr>
取出的数据存在pojo里,就算session关闭了也没问题啊,数据已经在内存里了
注入session也一直都有:
<bean id="UserCodedbDAO" class="com.zjm.ssh2.user.dao.hibernate.CodedbDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>现在还是不好使
com.zjm.ssh2.*.services.iface.*.*(..))com.zjm.ssh2.user.dao.hibernate.CodedbDAO
你自己看下 你的 事务声明的 包结构 和你所引用的对象 匹配吗???你应该看出来了吧声明和引用的不对:~~
com.zjm.ssh2.user.services.iface 这里面都是接口UserService实现了里面的接口package com.zjm.ssh2.user.services;
import com.zjm.ssh2.user.services.iface.IUserService;
public class UserService implements IUserService{}事务里面我写的是接口,这样应该也可以啊
你看看我的
<bean id="UserCodedbDAO" class="com.xxx.dao.impl.hibernate.DataDictionaryDAOImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>这个目录是
UserCodedbDAO com.zjm.ssh2.user.dao.hibernate.CodedbDAO">
com.zjm.ssh2.*.dao.iface.*.*(..))"
dao() 接口 是没有实现 HibernateDaoSupport的 他没有引用到sessionfactory而你的dao实现<bean id="UserCodedbDAO" class="com.zjm.ssh2.user.dao.hibernate.CodedbDAO">
这个应该是借口的 实现类 了 而不是接口你的 事务控制应该是围绕这个 而不是他的接口主要的是应为你被别人的包结构混淆了,所以当你的包结构不一样的时候 你还以为是给接口注入一般别人是这样来规则包结构:接口: com.csdn.dao;
实现类: com.csdn.dao.impl;你会发现 实现类其实是在包里面的文件夹
所以当人们开启事务的时候 是 到 dao
execution(* com.csdn.dao.*.*(..))那么 com.csdn.dao 这个文件夹里面所有要注入的都会成功。最后你这样来:
execution(* com.zjm.*.*(..)) 缩短前面的结构,把目录提上去,你运行看看