I have the following class that is in a library:
public class TaskExecutor {
@PostConstruct
public void postConstruct() {
// should fail if <task:annotation-driven /> is not set,
// because execute() needs to run
}
@Scheduled(fixedDelay = 1000)
public void execute() {
// do stuff that always needs to run
}
}
I want to fail the PostConstruct if task:annotation-driven is not set in the spring context. The idea is that a developer using this library will fail hard on spring start if the setting is missing, instead of soft after deployment.
I’d advise against that because you’re tying your app to Spring more than necessary, but:
I think you can do it by injecting the ApplicationContext and asking it for the existence of a bean that is always set by
<task:annotation-driven />, e.g.AsyncAnnotationBeanPostProcessor