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
请问怎么回事

解决方案 »

  1.   

    还真不清楚,dwr源码太多,那有时间看呀!我用注解事务没有问题。
      

  2.   

    你dwr返回的数据 在jsp页面再 去list.student.name 的时候  其实 session 已经关闭了。应为你的 UserService 并没有注入 sessionFactory
    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 已经关闭了
      

  3.   

    多谢3楼朋友
    现在的情况是这样,我加上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>现在还是不好使
      

  4.   

    看了 好半天 才看清楚  以后你的目录区别可要认证 明晰啊com.zjm.ssh2.user.services;  UserService com.zjm.ssh2.*.dao.iface.*.*(..))"
    com.zjm.ssh2.*.services.iface.*.*(..))com.zjm.ssh2.user.dao.hibernate.CodedbDAO
    你自己看下  你的 事务声明的  包结构 和你所引用的对象 匹配吗???你应该看出来了吧声明和引用的不对:~~ 
      

  5.   

    com.zjm.ssh2.*.services.iface.*.*(..)) 就是下面这个包
    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{}事务里面我写的是接口,这样应该也可以啊
      

  6.   

    不行的
    你看看我的
    <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.*.*(..))  
    缩短前面的结构,把目录提上去,你运行看看