错误信息
***************************
APPLICATION FAILED TO START
***************************
Description:
A component required a bean named 'MyFirstJob' that could not be found.
Action:
Consider defining a bean named 'MyFirstJob' in your configuration.
类
@Component
public class MyFirstJob {
public void sayHello()
{
System.out.println("MyFirstJob:sayHello"+new Date());
}
}
调用方法
@Configuration
public class QuratzConfig {
@Bean
MethodInvokingJobDetailFactoryBean jobDetail1()
{
MethodInvokingJobDetailFactoryBean bean = new MethodInvokingJobDetailFactoryBean();
bean.setTargetBeanName("MyFirstJob");
bean.setTargetMethod("sayHello");
return bean;
}
}
解决办法1:将首字母 改为小写
@Bean
MethodInvokingJobDetailFactoryBean jobDetail1()
{
MethodInvokingJobDetailFactoryBean bean = new MethodInvokingJobDetailFactoryBean();
bean.setTargetBeanName("myFirstJob");
bean.setTargetMethod("sayHello");
return bean;
}
解决办法2:@Component注解加入value=“MyFirstJob”属性
@Component(value = "MyFirstJob")
public class MyFirstJob {
public void sayHello()
{
System.out.println("MyFirstJob:sayHello"+new Date());
}
}