2011-11-06 42 views
0

我改变了代码。原因是bean无法建立。春天,aop,批次重试,例外:预计单一豆但发现0

如果我不添加重试,它的工作原理。如果我不添加重试,它会起作用。

<?xml version="1.0" encoding="UTF-8"?> 
<beans 
xmlns="www.springframework.org/schema/beans" 
xmlns:xsi="www.w3.org/2001/XMLSchema-instance" 
xmlns:util="www.springframework.org/schema/util" 
xmlns:aop="www.springframework.org/schema/aop" 
xmlns:context="www.springframework.org/schema/context" 
xsi:schemaLocation=" 
    www.springframework.org/schema/beans www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    www.springframework.org/schema/util www.springframework.org/schema/util/spring-util-3.0.xsd 
    www.springframework.org/schema/aop www.springframework.org/schema/aop/spring-aop-3.0.xsd 
    www.springframework.org/schema/context www.springframework.org/schema/context/spring-context-3.0.xsd 
"> 
<bean class="com.company.team.task.taskMonitorImpl"/> 
<aop:config> 
    <aop:pointcut id="taskCheck" expression="execution(* com.company.team.task.taskMonitorImpl.*(..))" /> 
    <aop:advisor pointcut-ref="taskCheck" advice-ref="taskRetryAdvice" /> 
</aop:config> 

<bean id="taskRetryAdvice" class="org.springframework.batch.retry.interceptor.RetryOperationsInterceptor"> 
    <property name="RetryOperations" ref="taskBatchRetryTemplate" /> 
</bean> 

<bean id="taskBatchRetryTemplate" class="org.springframework.batch.retry.support.RetryTemplate"> 
    <property name="retryPolicy" ref="taskBatchRetryPolicy" /> 
    <property name="backOffPolicy" ref="ExponentialBackOffPolicy" /> 
</bean> 

<bean id="taskBatchRetryPolicy" class="org.springframework.batch.retry.policy.SimpleRetryPolicy"> 
    <constructor-arg index="0" value="3"/> 
    <constructor-arg index="1"> 
     <map> 
      <entry key="java.lang.RuntimeException" value="true"/> 
     </map> 
    </constructor-arg> 
</bean> 

<bean id="ExponentialBackOffPolicy" class="org.springframework.batch.retry.backoff.ExponentialBackOffPolicy"> 
    <property name="initialInterval" value="300" > 
     <description>Initial sleep interval value, default 300 ms</description> 
    </property> 
    <property name="maxInterval" value="30000" > 
     <description>The maximum value of the backoff period in milliseconds.</description> 
    </property> 
    <property name="multiplier" value="2.0" > 
     <description>The value to increment the exp seed with for each retry attempt.</description> 
    </property> 
</bean> 

<!--<context:annotation-config />--> 
</beans> 
log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext). 
log4j:WARN Please initialize the log4j system properly. 
INFO: Detected JCL Provider: Commons Logging [commons-logging-api-1.1.1.jar] 
INFO: Detected JCL Implementation: Commons Logging [commons-logging-adapters-1.1.1.jar] 
INFO: JCL output is LOG4J 
INFO: log4j.appender.APPLICATION.File = /home/me/workspace/src/teamListingDestinationWorkflow/build/private/var/output/logs/teamListingDestinationWorkflow.log 
Exception in thread "main" java.lang.ExceptionInInitializerError 
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.company.team.teamListingDstWorkflow.teamListingDstWorkflowMain#0': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.company.team.task.taskMonitorImpl com.company.team.teamListingDstWorkflow.teamListingDstWorkflowMain.mon; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.company.team.task.taskMonitorImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) 
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) 
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) 
    at com.company.team.teamListingDstWorkflow.teamListingDstWorkflowMain.<clinit>(teamListingDstWorkflowMain.java:29) 
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.company.team.task.taskMonitorImpl com.company.team.teamListingDstWorkflow.teamListingDstWorkflowMain.mon; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.company.team.task.taskMonitorImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285) 
    ... 13 more 
    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.company.team.task.taskMonitorImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:924) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:793) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480) 
    ... 15 more 

我的问题:让 “重试” 的作品提前


感谢。

+0

我只能为自己说话,但我真的不明白你的要求。如果你写更多的文字,这可能会有所帮助。并添加全堆栈跟踪 – Ralph

+0

解决!!! 加 链路以下:http://stackoverflow.com/questions/ 841231/fixing-beannotofrequiredtypeexception-on-spring-proxy-cast-on-a-non-singleton-be – Peter

回答

1

(1)也许,错误在这里: ApplicationContext ctx = new FileSystemXmlApplicationContext(“test.xml”); xxImpl monitor = ctx.getBean(xxImpl.class); ApplicationContext ctx = new ClassPathXmlApplicationContext(“file:spring-configuration/unit-testing/application-config.xml”); Main main = ctx.getBean(Main.class);

(2) 更改xxImpl,使用@Autowired

(3) 添加CGLIB

(4) 它不工作。

====== ====== ====== ======

最后,解决了!!!
新增

<aop:config proxy-target-class="true">    

继链接:Fixing BeanNotOfRequiredTypeException on Spring proxy cast on a non-singleton bean?

+0

解决!!! 添加 以下链接: http://stackoverflow.com/questions/841231/fixing-beannotofrequiredtypeexception-on-spring-proxy-cast-on-a-non-singleton-be – Peter