[英]Error when start spring Could not find class [org.springframework.ws.config.annotation.WsConfigurationSupport]
[英]Exception when using @Scheduled spring annotation (Cannot find class [org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor])
我使用@Scheduled
注釋創建了一個預定作業。 它看起來像這樣:
package example.tools.rr;
public class RequestProcessorJob {
private RequestService requestService;
...
@Scheduled(fixedRate = 10000)
public void process() {
...
}
public RequestService getRequestService() { return requestService; }
public void setRequestService(RequestService requestService) { this.requestService = requestService; }
}
我把它放在一個包A中,所以我可以在其他包中使用這個類。 我在bundle B中導入它.B的blueprint.xml看起來像這樣:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://www.eclipse.org/gemini/blueprint/schema/blueprint-compendium"
xmlns:ctx="http://www.springframework.org/schema/context" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://www.eclipse.org/gemini/blueprint/schema/blueprint-compendium http://www.eclipse.org/gemini/blueprint/schema/blueprint-compendium/gemini-blueprint-compendium.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd
">
...
<bean id="handsetService" class="example.handset.impl.HandsetServiceImpl">
...
</bean>
<task:scheduler id="taskScheduler" />
<task:executor id="taskExecutor" pool-size="1" />
<task:annotation-driven executor="taskExecutor"
scheduler="taskScheduler" />
<bean class="example.tools.rr.RequestProcessorJob">
<cm:managed-properties persistent-id="example.handset.processing"
autowire-on-update="true" />
<property name="requestService" ref="handsetService" />
</bean>
</blueprint>
當我安裝bundle(在Apache Felix中)時,拋出以下異常:
Unable to create application context for [example.handset], unsatisfied dependencies:
none
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor] for bean with name 'org.springframework.context.annotation.internalAsyncAnnotationProcessor' defined in null; nested
exception is java.lang.ClassNotFoundException: org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor not found from bundle [example.handset]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1262) ~[na:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576) ~[na:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1331) ~[na:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:897) ~[na:na]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:566) ~[na:na]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) ~[na:na]
at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:60) ~[na:na]
at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:325) ~[na:na]
at org.eclipse.gemini.blueprint.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85) ~[na:na]
at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:290) ~[na:na]
at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:137) ~[na:na]
at java.lang.Thread.run(Unknown Source) [na:1.7.0_67]
Caused by: java.lang.ClassNotFoundException: org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor not found from bundle [example.handset]
at org.eclipse.gemini.blueprint.util.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:101) ~[na:na]
at org.eclipse.gemini.blueprint.util.BundleDelegatingClassLoader.loadClass(BundleDelegatingClassLoader.java:155) ~[na:na]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.7.0_67]
at org.springframework.util.ClassUtils.forName(ClassUtils.java:257) ~[na:na]
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:417) ~[na:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1283) ~[na:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1254) ~[na:na]
... 11 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor not found by example.handset [443]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1499) ~[felix.jar:na]
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
~[felix.jar:na]
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1882) ~[felix.jar:na]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.7.0_67]
at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1793) ~[felix.jar:na]
at org.apache.felix.framework.BundleImpl.loadClass(BundleImpl.java:929) ~[felix.jar:na]
at org.eclipse.gemini.blueprint.util.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:97) ~[na:na]
... 17 common frames omitted
如果我在bundle B中添加一個只有@Scheduled
注釋的空類,一切正常並且RequestProcessorJob被正確調度(不使用空類,但它不會發生錯誤)。
public class MockJob {
@Scheduled(fixedRate = 10000)
public void process() { }
}
我試圖在pom.xml
中將模塊A包含在<scope>provided</scope>
以及<scope>compile</scope>
,結果是一樣的。
使用reduntant類來使其工作並不是真正的解決方案。 你有什么想法嗎? 這是一個錯誤,或者可能以某種方式它應該如此奇怪地工作?
好的,我只是缺少pom.xml中<Import-Package>部分中的org.springframework.scheduling.annotation。 畢竟相當明顯,但春天的行為在這里仍然很奇怪。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.