我得到一个"非致命"错误两次,一次"没有定义[org.springframework.scheduling.TaskScheduler]类型的限定bean"在我运行java -jar myApp.jar后imediatly。在主线程完成并且线程从线轴开始之后,没有更多错误并且我的应用程序按预期运行(即应用程序按计划触发作业并相应地运行)。我注意到前两个非致命错误发生在搜索某些属性之后但在pool1-thread期间从未发生过。 我完全陷入困境,我必须将它部署到服务器进行首次测试,而且我不知道为什么导致根本原因我猜是否有可能进行调查。 我注意到一些奇怪的东西(至少对于我所知的人来说很奇怪):为什么在三个地方搜索所有属性:SystemProperty,SystemEnvironment和我的config.properties?我清楚地只指定了config.properties!也许它与我的问题无关,因为在同一个config.property文件中很少有其他属性以相同的方式设置并且在相同的类中使用而没有错误但顺便说一句,我注意到非致命错误总是发生在" STAT"财产被搜查。
弹簧批量配置
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.PlatformTransactionManager;
@Configuration
@ComponentScan("com.example")
@EnableBatchProcessing
@EnableAutoConfiguration
@EnableScheduling
@PropertySource("config.properties")
public class BatchConfiguration {
... just a simple spring batch with a very simple job containing a very simple read, process and writer methods
最相关的类,我的意思是调度程序
@Component
public class QueueScheduler {
private Job job;
private JobLauncher jobLauncher;
@Autowired
public QueueScheduler(JobLauncher jobLauncher, @Qualifier("job") Job job){
this.job = job;
this.jobLauncher = jobLauncher;
}
@Scheduled(fixedRate=60000)
public void runJob(){
try{
jobLauncher.run(job, new JobParameters());
}catch(Exception ex){
log.info(ex.getMessage());
}
}
}
的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring.batch.version>3.0.6.RELEASE</spring.batch.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.example.DemoAppNoBoot</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<goals>install</goals>
<preparationGoals>install</preparationGoals>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.example.DemoAppNoBoot</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
使用stat变量的唯一地方
@Component
public class Queue {
@Autowired
private Environment env;
...
env.getProperty("stat")
我运行java -jar myApp.jar后立即发出三条错误消息。注意前两个是&#34;非致命错误,但某些注释元数据可能不可用&#34;。
13:24:57.528 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'hours-add-servertime' in [systemProperties]
13:24:57.528 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching fo
r key 'hours-add-servertime' in [systemEnvironment]
13:24:57.529 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching fo
r key 'hours-add-servertime' in [class path resource [config.properties]]
13:24:57.529 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Found key 'h
ours-add-servertime' in [class path resource [config.properties]] with type [Str
ing] and value '-7'
13:24:57.531 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching fo
r key 'stat' in [systemProperties]
13:24:57.531 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching fo
r key 'stat' in [systemEnvironment]
13:24:57.532 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching fo
r key 'stat' in [class path resource [config.properties]]
13:24:57.533 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Found key 's
tat' in [class path resource [config.properties]] with type [String] and value '
C:/MYAPP/Configurations/stat.xml'
13:24:57.884 [main] DEBUG o.s.c.t.c.AnnotationAttributesReadingVisitor - Failed
to class-load type while reading annotation metadata. This is a non-fatal error,
but certain annotation metadata may be unavailable.
java.lang.ClassNotFoundException: org.springframework.data.web.config.EnableSpri
ngDataWebSupport
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0
_65]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_65]
at org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(La
unchedURLClassLoader.java:178) ~[demo-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(Laun
chedURLClassLoader.java:142) ~[demo-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_65]
at org.springframework.core.type.classreading.RecursiveAnnotationAttribu
tesVisitor.visitEnd(RecursiveAnnotationAttributesVisitor.java:47) ~[spring-core-
4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.asm.ClassReader.readAnnotationValues(ClassReader.
java:1802) [spring-core-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.asm.ClassReader.accept(ClassReader.java:642) [spr
ing-core-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.asm.ClassReader.accept(ClassReader.java:508) [spr
ing-core-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.core.type.classreading.SimpleMetadataReader.<init
>(SimpleMetadataReader.java:64) [spring-core-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.core.type.classreading.SimpleMetadataReaderFactor
y.getMetadataReader(SimpleMetadataReaderFactory.java:98) [spring-core-4.2.4.RELE
ASE.jar!/:4.2.4.RELEASE]
at org.springframework.core.type.classreading.CachingMetadataReaderFacto
ry.getMetadataReader(CachingMetadataReaderFactory.java:102) [spring-core-4.2.4.R
ELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.core.type.classreading.SimpleMetadataReaderFactor
y.getMetadataReader(SimpleMetadataReaderFactory.java:93) [spring-core-4.2.4.RELE
ASE.jar!/:4.2.4.RELEASE]
at org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoCo
nfigurationClasses.<init>(AutoConfigurationSorter.java:112) [spring-boot-autocon
figure-1.3.1.RELEASE.jar!/:1.3.1.RELEASE]
at org.springframework.boot.autoconfigure.AutoConfigurationSorter.getInP
riorityOrder(AutoConfigurationSorter.java:56) [spring-boot-autoconfigure-1.3.1.R
ELEASE.jar!/:1.3.1.RELEASE]
at org.springframework.boot.autoconfigure.EnableAutoConfigurationImportS
elector.sort(EnableAutoConfigurationImportSelector.java:173) [spring-boot-autoco
nfigure-1.3.1.RELEASE.jar!/:1.3.1.RELEASE]
at org.springframework.boot.autoconfigure.EnableAutoConfigurationImportS
elector.selectImports(EnableAutoConfigurationImportSelector.java:82) [spring-boo
t-autoconfigure-1.3.1.RELEASE.jar!/:1.3.1.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.proce
ssDeferredImportSelectors(ConfigurationClassParser.java:453) [spring-context-4.2
.4.RELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse
(ConfigurationClassParser.java:185) [spring-context-4.2.4.RELEASE.jar!/:4.2.4.RE
LEASE]
.... (I took out the lines to make more easy to read)...
text.<init>(AnnotationConfigApplicationContext.java:84) [spring-context-4.2.4.RE
LEASE.jar!/:4.2.4.RELEASE]
at com.example.DemoAppNoBoot.main(DemoAppNoBoot.java:12) [demo-0.0.1-SNA
PSHOT.jar!/:0.0.1-SNAPSHOT]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.
0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62) ~[na:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43) ~[na:1.8.0_65]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner
.java:53) [demo-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_65]
13:24:58.830 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching fo
r key 'spring.messages.basename' in [systemProperties]
13:24:58.835 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching fo
r key 'spring.messages.basename' in [systemEnvironment]
13:24:58.836 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching fo
r key 'spring.messages.basename' in [class path resource [config.properties]]
13:24:58.837 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Could not fi
nd key 'spring.messages.basename' in any property source. Returning [null]
…
13:25:01.353 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching fo
r key 'hours-add-servertime' in [systemProperties]
13:25:01.354 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching fo
r key 'hours-add-servertime' in [systemEnvironment]
13:25:01.354 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching fo
r key 'hours-add-servertime' in [class path resource [config.properties]]
13:25:01.355 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Found key 'h
ours-add-servertime' in [class path resource [config.properties]] with type [Str
ing] and value '-7'
13:25:01.356 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching fo
r key 'stat' in [systemProperties]
13:25:01.357 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching fo
r key 'stat' in [systemEnvironment]
13:25:01.358 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching fo
r key 'stat' in [class path resource [config.properties]]
13:25:01.358 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Found key 's
tat' in [class path resource [config.properties]] with type [String] and value '
C:/MYAPP/Configurations/stat.xml'
13:25:01.473 [main] DEBUG o.s.c.t.c.AnnotationAttributesReadingVisitor - Failed
to class-load type while reading annotation metadata. This is a non-fatal error,
but certain annotation metadata may be unavailable
java.lang.ClassNotFoundException: org.springframework.data.web.config.EnableSpri
ngDataWebSupport
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0
_65]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_65]
at org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(La
unchedURLClassLoader.java:178) ~[demo-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(Laun
chedURLClassLoader.java:142) ~[demo-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_65]
at org.springframework.core.type.classreading.RecursiveAnnotationAttribu
tesVisitor.visitEnd(RecursiveAnnotationAttributesVisitor.java:47) ~[spring-core-
4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.asm.ClassReader.readAnnotationValues(ClassReader.
java:1802) [spring-core-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.asm.ClassReader.accept(ClassReader.java:642) [spr
ing-core-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
.... (I took out the lines to make more easy to read)...
at org.springframework.context.annotation.ConfigurationClassPostProcesso
r.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243) [s
pring-context-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate
.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.ja
va:273) [spring-context-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate
.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98) [spr
ing-context-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invoke
BeanFactoryPostProcessors(AbstractApplicationContext.java:678) [spring-context-4
.2.4.RELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:520) [spring-context-4.2.4.RELEASE.jar!/:4.2.4
.RELEASE]
at org.springframework.context.annotation.AnnotationConfigApplicationCon
text.<init>(AnnotationConfigApplicationContext.java:84) [spring-context-4.2.4.RE
LEASE.jar!/:4.2.4.RELEASE]
at com.example.DemoAppNoBoot.main(DemoAppNoBoot.java:12) [demo-0.0.1-SNA
PSHOT.jar!/:0.0.1-SNAPSHOT]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.
0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62) ~[na:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43) ~[na:1.8.0_65]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner
.java:53) [demo-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_65]
13:25:04.089 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cache
d instance of singleton bean 'autoConfigurationReport'
第三个错误是:
13:25:09.756 [main] DEBUG o.s.c.a.AnnotationConfigApplicationContext - Unable to
locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.sp
ringframework.context.support.DefaultLifecycleProcessor@6b1cff9f]
13:25:09.759 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cache
d instance of singleton bean 'lifecycleProcessor'
13:25:09.763 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cache
d instance of singleton bean 'org.springframework.context.annotation.internalSch
eduledAnnotationProcessor'
13:25:09.764 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cache
d instance of singleton bean 'org.springframework.boot.context.properties.Config
urationPropertiesBindingPostProcessor'
13:25:09.766 [main] DEBUG o.s.s.a.ScheduledAnnotationBeanPostProcessor - Could n
ot find default TaskScheduler bean
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying b
ean of type [org.springframework.scheduling.TaskScheduler] is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.
getBean(DefaultListableBeanFactory.java:372) ~[spring-beans-4.2.4.RELEASE.jar!/:
4.2.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.
getBean(DefaultListableBeanFactory.java:332) ~[spring-beans-4.2.4.RELEASE.jar!/:
4.2.4.RELEASE]
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPost
Processor.finishRegistration(ScheduledAnnotationBeanPostProcessor.java:192) [spr
ing-context-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPost
Processor.onApplicationEvent(ScheduledAnnotationBeanPostProcessor.java:171) [spr
ing-context-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPost
Processor.onApplicationEvent(ScheduledAnnotationBeanPostProcessor.java:86) [spri
ng-context-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.i
nvokeListener(SimpleApplicationEventMulticaster.java:163) [spring-context-4.2.4.
RELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.m
ulticastEvent(SimpleApplicationEventMulticaster.java:136) [spring-context-4.2.4.
RELEASE.jar!/:4.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publis
hEvent(AbstractApplicationContext.java:381) [spring-context-4.2.4.RELEASE.jar!/:
4.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publis
hEvent(AbstractApplicationContext.java:335) [spring-context-4.2.4.RELEASE.jar!/:
4.2.4.RELEASE]
... I took out several lines to make easy for reading ...
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner
.java:53) [demo-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_65]
13:25:09.795 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching fo
r key 'spring.liveBeansView.mbeanDomain' in [systemProperties]
13:25:09.797 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching fo
r key 'spring.liveBeansView.mbeanDomain' in [systemEnvironment]
13:25:09.797 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching fo
r key 'spring.liveBeansView.mbeanDomain' in [class path resource [config.propert
ies]]
13:25:09.798 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Could not fi
nd key 'spring.liveBeansView.mbeanDomain' in any property source. Returning [nul
l]
13:25:09.802 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cache
d instance of singleton bean 'jobLauncher'
在主线程完成并且线轴开始的线程
之后完全没有错误13:44:11.047 [pool-1-thread-1] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'stat' in [systemProperties]
13:44:11.048 [pool-1-thread-1] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'stat' in [systemEnvironment]
13:44:11.048 [pool-1-thread-1] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'stat' in [class path resource [config.properties]]
13:44:11.049 [pool-1-thread-1] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Found key 'stat' in [class path resource [config.properties]] with type [String] and value 'C:/ICTT/Configurations/stat.xml'
答案 0 :(得分:2)
这三个错误中没有一个实际上是错误。它们都只是关于Spring Boot和Spring Framework内部工作的调试日志消息。
Spring Boot的自动配置包含在将某些库添加到该类路径时自动打开的配置。作为处理配置和决定应该打开什么的一部分,可能会尝试加载不在类路径上的类。这样做的方式是它不会阻止应用程序启动。您已识别的前两个调试消息是此过程的副作用。它们都发生,因为TaskScheduler
不在类路径上。这意味着Spring Data的Web支持不会自动配置。
第三条消息是Spring Framework如何确定使用哪个任务调度程序的实现细节。它正在寻找一个实现ScheduledExecutorService
的bean。调试消息告诉您它没有找到。然后它查找实现{{1}}的bean。如果它没有找到其中一个,则它会回退到使用默认实现。
您只能在主线程上看到这些调试消息,因为它们在您的应用程序启动时发生,并且所有启动处理都在主线程上执行。