本帖最后由 linshow3 于 2012-5-7 23:07 编辑
* 这个问题可能与SPRING事务有关。
异常信息:::
Exception in thread "main" org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'mgrManager' must be of type [service.impl.MgrManagerImpl], but was actually of type [$Proxy1]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:349)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1079)
at tools.TestDao.main(TestDao.java:38)*我只要把SPRING的事务配置删除掉就可以正常运行了。但是却无法使用事务了,有没有什么解决办法。这是我在网上找到的同类异常情况。Beannamed 'txAdvice' must be of type [org.aopalliance.aop.Advice], but was actually of type [org.springframework.transaction.interceptor.TransactionInterceptor]但是网上的这个异常是jar包冲突,org.aopalliance.aop.Advice这个类是框架提供的,
我这个情况就是service.impl.MgrManagerImpl。这个类是我自己写的,应该不会有什么jar包冲突吧。 xml部分配置
<bean id="managerTemplate" abstract="true" lazy-init="true"
p:appDao-ref="appDao"
p:attendDao-ref="attendDao"
p:typeDao-ref="attendTypeDao"
p:checkDao-ref="checkDao"
p:empDao-ref="employeeDao"
p:mgrDao-ref="managerDao"
payDao-ref="payDao"/> <!-- 定义两个业务逻辑组件,继承业务逻辑组件的模板 -->
<bean id="empManager"
class="service.impl.EmpManagerImpl"
parent="managerTemplate"/>
<bean id="mgrManager"
class="service.impl.MgrManagerImpl"
parent="managerTemplate"/>
<bean id="transactionManager" class=
"org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory"/> <!-- 配置事务增强处理Bean,指定事务管理器 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 用于配置详细的事务语义 -->
<tx:attributes>
<!-- 所有以'get'开头的方法是read-only的 -->
<tx:method name="get*" read-only="true"/>
<!-- 其他方法使用默认的事务设置 -->
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<aop:config>
<!-- 配置一个切入点,匹配empManager和mgrManager
两个Bean的所有方法的执行 -->
<aopointcut id="servicePointcut"
expression="bean(empManager)||bean(mgrManager)"/>
<!-- 指定在servicePointcut切入点应用txAdvice事务增强处理 -->
<aop:advisor advice-ref="txAdvice"
pointcut-ref="servicePointcut"/>
</aop:config>测试程序:::public class TestDao { /**
* @param args
*/
public static void main(String[] args) {
ApplicationContext ctx=new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml","daoContext.xml"});
ApplicationDao app=ctx.getBean("appDao", ApplicationDaoHibernate.class);
AttendDao att=ctx.getBean("attendDao",AttendDaoHibernate.class);
AttendTypeDao attType=ctx.getBean("attendTypeDao",AttendTypeDaoHibernate.class);
CheckBackDao che=ctx.getBean("checkDao",CheckBackDaoHibernate.class);
EmployeeDao emp=ctx.getBean("employeeDao",EmployeeDaoHibernate.class);
ManagerDao mgr=ctx.getBean("managerDao",ManagerDaoHibernate.class);
PaymentDao pay=ctx.getBean("payDao",PaymentDaoHibernate.class); MgrManager mss=ctx.getBean("mgrManager",MgrManagerImpl.class); ///异常信息提示出问题的地方 //EmpManager empmgr=(EmpManagerImpl)ctx.getBean("empManager";
/*下面这些是一开始写的,出了异常之后就先注释了。
EmpManager empmgr=ctx.getBean("empManager",EmpManagerImpl.class);
/*
Manager manager=new Manager();
manager.setDept("sss部";
mgr.save(manager);
Employee employee=emp.get(1);
List<PaymentBean> payment=empmgr.empSalary("mysql";
Iterator it=payment.iterator();
while(it.hasNext())
{
PaymentBean paym=(PaymentBean)it.next();
System.out.println(paym.getAmount()+paym.getPayMonth());
}
System.out.print("===================================";
for(Object obj : payment)
{
PaymentBean paym=(PaymentBean)obj;
System.out.println("月份: "+paym.getAmount()+"工资:"+paym.getPayMonth());
}
*/
//emp.delete(employee);
System.out.print("程序执行完成===================================";
}}补充一点:
因为之前有个Unable to get the default Bean Validation factory 异常
所以我在配置文件
加了这句。javax.persistence.validation.mode=none我上面这个异常是出现在hibernate和srping整合的时候的,如果再整合struts ,spring容器由listener创建的话。就不会出现异常。
解决方案 »
- java 如何获取一个文件的绝对路径。。。
- 高手请进,100分赠送。
- 表单传送数据的问题,大家来看看!
- 那位大哥做过j2ee产品的安装程序,请给点思考
- servlet往mysql中插入中文乱码
- 一个JSP中多个ajax请求一ACTION中多个方法的问题
- 关于jsp的严重问题!!!!
- 急问:jboss+tomcat如何访问LDAP服务?
- 请问哪儿有能够支持jsp+数据库(mysql或MSSQL)的空间,公司需要,付费的可以。
- Tomcat4连Oracle的中文问题!!!急:在线等待!!!
- 把图片相对路径存储到oracle数据库,如何在jsp中调用显示
- STRUTS2.0 s:if标签中 TEST 比较问题
不知道楼主解决了没???