Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 弹簧数据和石英自动布线_Java_Spring_Spring Mvc_Quartz Scheduler - Fatal编程技术网

Java 弹簧数据和石英自动布线

Java 弹簧数据和石英自动布线,java,spring,spring-mvc,quartz-scheduler,Java,Spring,Spring Mvc,Quartz Scheduler,我使用下面的QuartzConfig配置类将spring数据与quartz自动关联,该配置类运行良好,并且在运行项目时无错误地触发作业,但我希望通过下面的spring控制器手动触发作业,但我得到了@autowire error with spring data 石英作业 @Service @Transactional public class JobOne implements Job { @Autowired TestrecordRepository testrecordRep

我使用下面的QuartzConfig配置类将spring数据与quartz自动关联,该配置类运行良好,并且在运行项目时无错误地触发作业,但我希望通过下面的spring控制器手动触发作业,但我得到了@autowire error with spring data

石英作业

@Service
@Transactional
public class JobOne implements Job {
    @Autowired
    TestrecordRepository testrecordRepository;
    @Autowired
    ScoreRepository scoreRepository;

    public void execute(JobExecutionContext context) throws JobExecutionException {
        System.out.println("Job one!"); 
        List<Testrecord> records=testrecordRepository.findAll();
        for (Testrecord t : records) {
            Testrecord testrecord = new Testrecord();
            testrecord.setValue_integer(t.getValue_integer());
            testrecord.setId(t.getId());
            RuleExecutor ruleExecutor = new RuleExecutor();
            Score score = ruleExecutor.processRules(testrecord);
            scoreRepository.save(score);    
        }
    }
}
弹簧控制器

@RequestMapping(value = "/test", method = RequestMethod.GET)
public void test(HttpServletRequest request) throws Exception {
    ApplicationContext context = new AnnotationConfigApplicationContext(
            QuartzConfig.class);
    Scheduler scheduler = (Scheduler)context.getBean("quartzSchedulerjobOne");

}
eclipse控制台

[ERROR] org.quartz.core.ErrorLogger - An error occured instantiating job to be executed. job= 'DEFAULT.processJobTwo'
org.quartz.SchedulerException: Job instantiation failed
    at org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(AdaptableJobFactory.java:45) ~[spring-context-support-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.quartz.core.JobRunShell.initialize(JobRunShell.java:134) ~[quartz-2.1.5.jar:na]
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:387) [quartz-2.1.5.jar:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.innvo.quartz.JobTwo': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.innvo.repository.TestrecordRepository com.innvo.quartz.JobTwo.testrecordRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.innvo.repository.TestrecordRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBean(AbstractAutowireCapableBeanFactory.java:302) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at com.innvo.quartz.AutowiringSpringBeanJobFactory.createJobInstance(AutowiringSpringBeanJobFactory.java:22) ~[classes/:na]
    at org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(AdaptableJobFactory.java:41) ~[spring-context-support-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    ... 2 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.innvo.repository.TestrecordRepository com.innvo.quartz.JobTwo.testrecordRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.innvo.repository.TestrecordRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    ... 6 common frames omitted
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.innvo.repository.TestrecordRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1301) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    ... 8 common frames omitted

从您发布的错误日志中可以清楚地看出,它正在寻找一个没有被spring包装的bean。第一个bean com.innvo.quartz.JobOne.testrecordRepository在哪里定义?你确定它在包扫描中吗?您希望从应用程序上下文中获取的bean名称quartzSchedulerjobOne在任何地方都已定义??
还有,为什么您试图从应用程序上下文获取调度程序,而不将其自动连接到控制器?调度员必须是单身,他将负责开始一项新工作

您可以添加TestrecordRepository类吗?日志清楚地表明,它不能自动连接QuartzConfig类中定义的itquartzSchedulerjobOne bean。一旦我部署并且所有autowire bean都工作,这个bean就会自动调用,但我想肯定地通过controllerwell调用这个bean,必须解决的第一个问题是自动连接com.innvo.quartz.JobOne.testrecordRepository类的问题。你能分享这个类使用的代码或剪贴吗?你确定它是由spring包装的吗?自动连接在QuartzConfig类配置bean中没有问题,我想知道为什么当我试图通过控制器调用QuartzConfig bean时它不起作用当你混淆了上下文或者没有正确加载它们时,你确定QuartzConfig已经加载了吗?而applicationContext正在被传递?
[ERROR] org.quartz.core.ErrorLogger - An error occured instantiating job to be executed. job= 'DEFAULT.processJobTwo'
org.quartz.SchedulerException: Job instantiation failed
    at org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(AdaptableJobFactory.java:45) ~[spring-context-support-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.quartz.core.JobRunShell.initialize(JobRunShell.java:134) ~[quartz-2.1.5.jar:na]
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:387) [quartz-2.1.5.jar:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.innvo.quartz.JobTwo': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.innvo.repository.TestrecordRepository com.innvo.quartz.JobTwo.testrecordRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.innvo.repository.TestrecordRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBean(AbstractAutowireCapableBeanFactory.java:302) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at com.innvo.quartz.AutowiringSpringBeanJobFactory.createJobInstance(AutowiringSpringBeanJobFactory.java:22) ~[classes/:na]
    at org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(AdaptableJobFactory.java:41) ~[spring-context-support-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    ... 2 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.innvo.repository.TestrecordRepository com.innvo.quartz.JobTwo.testrecordRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.innvo.repository.TestrecordRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    ... 6 common frames omitted
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.innvo.repository.TestrecordRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1301) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    ... 8 common frames omitted