我有以下课程:
@Component
public class DasServiceHelper {
@Autowired ConcurrentTaskExecutor executor;
protected void retrieveDASReferenceData() {
Callable<List<ReferenceDataType>> callable1 = new Callable<List<ReferenceDataType>>() {
@Override public List<ReferenceDataType> call() throws Exception {
//Some method logic
}
};
Callable<List<ReferenceDataType>> callable2 = new Callable<List<ReferenceDataType>>() {
@Override public List<ReferenceDataType> call() throws Exception {
//Some method logic
}
};
Callable<List<ReferenceDataType>> callable3 = new Callable<List<ReferenceDataType>>() {
@Override public List<ReferenceDataType> call() throws Exception {
//Some method logic
}
};
Callable<List<ReferenceDataType>> callable4 = new Callable<List<ReferenceDataType>>() {
@Override public List<ReferenceDataType> call() throws Exception {
//Some method logic
}
};
Future<List<ReferenceDataType>> result1 = executor.submit(callable1);
Future<List<ReferenceDataType>> result2 = executor.submit(callable2);
Future<List<ReferenceDataType>> result3 = executor.submit(callable3);
Future<List<ReferenceDataType>> result4 = executor.submit(callable4);
Future<List<ReferenceDataType>> result5 = executor.submit(callable5);
}
这是我的spring配置xml:
<bean name="dasServiceHelper" class="com.nyl.corp.das.DasServiceHelper"/>
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ConcurrentTaskExecutor"/>
我正在从我的服务类调用retrieveDASReferenceData()
。
编译代码时,我遇到以下异常:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.scheduling.concurrent.ConcurrentTaskExecutor] 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:967)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:837)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:749)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
知道我在这里缺少什么。
编辑: Spring配置文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd">
<context:component-scan base-package="com.nyl.corp">
<context:include-filter type="regex" expression="com.nyl.corp.*.web.*.*"/>
</context:component-scan>
<mvc:annotation-driven />
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
<bean id="beanNameResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver">
<property name = "order" value = "0" />
</bean>
<bean id="excelView" class="com.nyl.corp.das.web.ExcelView" />
<bean id="reportExcelView" class="com.nyl.corp.das.web.ReportExcelView" />
<mvc:resources mapping="/static/**" location="/"/>
<mvc:default-servlet-handler />
<aop:aspectj-autoproxy/>
<cache:annotation-driven/>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages"/>
</bean>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"
p:cache-manager-ref="ehcache" />
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
p:config-location="classpath:dasEhCache.xml" p:shared="true"/>
<bean name="dasServiceHelper" class="com.nyl.corp.das.DasServiceHelper"/>
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ConcurrentTaskExecutor"/>
<!-- <task:executor id="myExecutor" pool-size="10-20" queue-capacity="11"/>
<bean id="asyncBean" class="com.nyl.corp.das.DasServiceHelper"/> -->
</beans>