Using global timing task cronutil in hutool tool class

The original address: https://www.cnblogs.com/xiaolong1996/p/9571645.html
Use the global timing task-cronutil in the Hutool utility class
Spring’s @Autowired annotation is used to inject the required service. When the add method in the service is called, the program raises a null pointer exception. In the thread, it is thread-safe, injection-resistant, and is resolved by the context object instance
 
package com.backstage.config;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/
* * * @ ProjectName:
* @ Package: com. Runs backstage. Config
* @ the ClassName: ApplicationContextProvider
* @ Description: get bean object tools
* @ Author: wangzhilong @ CreateDate
* :
* @version: 1.0
/
Author: * *
* ZhuShangJin Date:
* 2018/7/3/

* @ Component
public class ApplicationContextProvider implements ApplicationContextAware {

/* * *
the context object instance */
private static ApplicationContext ApplicationContext;
@Override
public void setApplicationContext(ApplicationContext) throws BeansException {
is.ApplicationContext = ApplicationContext;
}
/**
* @return
@return
* @return
publ>tatic ApplicationContext getApplicationContext() {
}

/* * * by the name for the Bean.

* * * @ @ param name
the return/

* public static Object getBean (String name) {
the return getApplicationContext().getBean(name);
}
/
* * * by class get beans.

* * @ param clazz
* @ param & lt; T>
* @ return/

* public static & lt; T> T getBean(Class< T> Clazz) {
return getApplicationContext () getBean (clazz);
}
/ * *
* by name, and the return of the Clazz specified Bean

* * @ param name
* @ param Clazz
* @ param & lt; T>
* @ return/

* public static & lt; T> T getBean(String name, Class< T> Clazz) {
return getApplicationContext().getBean(name, clazz);
}
 
Public TimingMonitoring () {//new injection need bean enclosing detailedDataService = ApplicationContextProvider. GetBean (detailedDataService. Class); }
}
 


Read More: