0

I changed the code. the reason is bean can not be build.

If i don't add the retry, it works. If i don't add the retry, it works.

<?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

my question: let "retry" works


Thanks in advance.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
Peter
  • 171
  • 3
  • 6
  • I can only speek for myself, but I really did not understand what you asked for. May it would be helpful if you write a bit more text. and add the full stack trace – Ralph Nov 06 '11 at 18:07
  • Solved!!! Added following the link: http://stackoverflow.com/questions/841231/fixing-beannotofrequiredtypeexception-on-spring-proxy-cast-on-a-non-singleton-be – Peter Nov 07 '11 at 11:45

1 Answers1

1

(1)Maybe, error is here: 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) Changed xxImpl, use @Autowired

(3) add CGLib

(4) it DOESN‘T works.

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

Finally, Solved!!!
Added

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

following the link: Fixing BeanNotOfRequiredTypeException on Spring proxy cast on a non-singleton bean?

Community
  • 1
  • 1
Peter
  • 171
  • 3
  • 6
  • Solved!!! Added following the link: http://stackoverflow.com/questions/841231/fixing-beannotofrequiredtypeexception-on-spring-proxy-cast-on-a-non-singleton-be – Peter Nov 07 '11 at 11:44