Is there a way (any annotation of base class) using which i can mark a class such that spring throws an error on context initialization? Basically i have a class which is not thread safe by design and i do not want anybody to use it with spring as singleton bean. I know it can be used as prototype bean but can i prohibit, it being used as spring bean altogether?
Make its post-initialisation method throw.
Either implement InitializingBean
public final void afterPropertiesSet() {
throw new UnsupportedOperationException();
}
Or use a JEE annotation
@PostConstruct
public final void forbidDependencyInjection() {
throw new UnsupportedOperationException();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With