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

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;
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Java语录精选

你的鼓励是我坚持下去的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值