首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

Spring ApplicationContextAware和事务配置有关问题

2013-10-27 
SpringApplicationContextAware和事务配置问题这个问题困扰着我几天了.....//action类public class BaseAc

Spring ApplicationContextAware和事务配置问题
这个问题困扰着我几天了.....
//action类
public class BaseAction extends ActionSupport {
public ServiceFacade facade;        //外观类
        public ServiceFacade getFacade() {
return facade;
}
public void setFacade(ServiceFacade facade) {
this.facade = facade;
}
}
//外观类
public class ServiceFacade implements ApplicationContextAware {
        private ApplicationContext ac;
        public ApplicationContext getAc() {
return ac;
}
public void setApplicationContext(ApplicationContext applicationContext){
this.ac = applicationContext;
}
}
//业务层
....

spring配置
    <!-- action配置 -->
<bean id="baseAction" class="cn.warehouse.action.BaseAction">
<property name="facade" ref="facade"></property>
</bean>

    <!-- 外观类 -->
<bean id="facade" class="cn.warehouse.facade.ServiceFacade"></bean>

    <!-- 业务层 -->
         ........


现在问题是声明式事务中
    1. <!-- 声明式事务在业务层 -->  这里完美运行程序,并已经查询到数据到页面(一切正常)
     <aop:config>
      <aop:pointcut expression="execution(* cn.warehouse.service.impl.*.*(..))" id="bizMethod"/>
      <aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethod"/>
     </aop:config>
     
    2.1. <!-- 声明式事务在外观类 -->  报错了
     <aop:config>
      <aop:pointcut expression="execution(* cn.warehouse.facade.*.*(..))" id="bizMethod"/>
      <aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethod"/>
     </aop:config>



异常:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'baseAction' defined in class path resource [applicationContext-action.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy0 implementing org.springframework.context.ApplicationContextAware,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [cn.warehouse.facade.ServiceFacade] for property 'facade'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0 implementing org.springframework.context.ApplicationContextAware,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [cn.warehouse.facade.ServiceFacade] for property 'facade': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4681)


at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5184)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5179)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy0 implementing org.springframework.context.ApplicationContextAware,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [cn.warehouse.facade.ServiceFacade] for property 'facade'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0 implementing org.springframework.context.ApplicationContextAware,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [cn.warehouse.facade.ServiceFacade] for property 'facade': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1250)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
... 22 more
Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0 implementing org.springframework.context.ApplicationContextAware,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [cn.warehouse.facade.ServiceFacade] for property 'facade': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
... 26 more



我感觉问题应该就是出在外观类的 ApplicationContextAware 
但不理解为什么会报错。

求大家帮帮忙,这个问题已经困扰了我几天。
在此先感谢大家~~~~ 事务
[解决办法]
具体实现类注入出错,加上下面的试试。
<aop:config proxy-target-class="true"></aop:config>

热点排行