English 中文(简体)
春、 a、bat、例外:预期单一豆类,但发现0
原标题:spring, aop, batch retry, exception: expected single bean but found 0
  • 时间:2011-11-06 17:22:24
  •  标签:
  • spring
  • aop

我改变了该守则。 原因不能成立。

如果不加工业,它就能够发挥作用。 如果不加工业,它就能够发挥作用。

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

最佳回答

(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">              

页: 1 链接: 排序 BeanNotOfRequiredTypeException on Spring autsingleton bean?

问题回答

暂无回答




相关问题
array dependency injection in spring?

is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @...

Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

How can I determine Objects in application context?

I am trying to write a portlet for Liferay (using Tomcat and Spring) and need to use a database via Persistence API/Hibernate. I am using some configuration XMLs (applicationContext.xml, etc.) and ...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

热门标签