您的位置:首页 > 编程语言 > Java开发

Spring boot 定时任务Quartz的注册问题解决

2019-04-16 18:33 731 查看

2019-04-15 15:04:34.146 INFO 11196 — [ main] org.javaboy.quartz.QuartzApplication : Starting QuartzApplication on PC with PID 11196 (E:\bao\quartz\target\classes started by Administrator in E:\bao\quartz)
2019-04-15 15:04:34.155 INFO 11196 — [ main] org.javaboy.quartz.QuartzApplication : No active profile set, falling back to default profiles: default
2019-04-15 15:04:35.842 INFO 11196 — [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-04-15 15:04:35.867 INFO 11196 — [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-04-15 15:04:35.867 INFO 11196 — [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.17]
2019-04-15 15:04:36.024 INFO 11196 — [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-04-15 15:04:36.024 INFO 11196 — [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1787 ms
2019-04-15 15:04:36.095 WARN 11196 — [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘methodInvokingJobDetailFactoryBean’ defined in class path resource [org/javaboy/quartz/QuartzConfig.class]: Invocation of init method failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘MyJob1’ available
2019-04-15 15:04:36.098 INFO 11196 — [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-04-15 15:04:36.113 INFO 11196 — [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2019-04-15 15:04:36.191 ERROR 11196 — [ main] o.s.b.d.LoggingFailureAnalysisReporter :

APPLICATION FAILED TO START

Description:

A component required a bean named ‘MyJob1’ that could not be found.

Action:

Consider defining a bean named ‘MyJob1’ in your configuration.

Process finished with exit code 1

1.错误分析:

Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.

该语句是以下意思
(启动ApplicationContext时出错。若要显示条件报告,请在启用“调试”的情况下重新运行应用程序。)

Description:
A component required a bean named ‘MyJob1’ that could not be found.

重点是这句错误,只要出现类似‘ ’的错误根据上面这句错误推理,找注册类@Bean下的
错误是(名为“MyJob1”的bean无法找到)

2.解决问题 :

错误解决:看提示是’MyJob1’ 找不到,大写开头报错误,那就是注册目标类名字开头必须要小写myJob1,这样才能把这方法注册到容器里面

@Bean
MethodInvokingJobDetailFactoryBean methodInvokingJobDetailFactoryBean() {
MethodInvokingJobDetailFactoryBean bean = new MethodInvokingJobDetailFactoryBean();
bean.setTargetBeanName("myJob1");  //目标类MyJob1的名字
bean.setTargetMethod("sayHello");   // 类中的方法名

return bean;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: