Automatic injection cannot be used in spring boot scheduled tasks

in the method modified by @ schedule annotation, using automatic injection will report a null pointer
my solution is to get the spring container statically and then use the getBean () method to get it, which is successful. I would like to ask why automatic injection can not be used

Jul.15,2022

The Schedule of

Spring is implemented through Quartz, but ApplicationContext is not directly supported by default. You can configure it in the following ways

@Bean
public SpringBeanJobFactory springBeanJobFactory() {
    AutoWiringSpringBeanJobFactory jobFactory = new AutoWiringSpringBeanJobFactory();
    jobFactory.setApplicationContext(applicationContext);
    return jobFactory;
}

use @ Autowired static injection of the required dependencies in the class where the method is located, and then add @ Component annotations to the class in a format similar to the following:

@Component
@EnableScheduling
//@EnableScheduling
public class ScheduleTasks{

    @Autowired
    private SomeOtherClass someOtherClass;
    
    @Scheduled(...)
    public void go(){
      someOtherClass.do();
    }
}
After

has written @ Schedule , have you written @ Component ?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bc9472-30951.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bc9472-30951.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?