Replace obsolete @PostConstruct annotation or implement InitializingBean
onyn opened this issue · comments
The problem
Some autoconfiguration classes uses obsolete javax.annotation.PostConstruct
annotation (e.g. GrpcMetadataConsulConfiguration).
Spring boot 3 still supports it, but doesn't include corresponding dependency. And because of this, configuration classes won't load. So I need to include javax.annotation:javax.annotation-api:1.3.2
dependency explicitly in my project to make this work. This is tedious and human factor prone.
The solution
Two solutions available:
- Remove annotation entirely and implement
org.springframework.beans.factory.InitializingBean
interface. - Replace
javax.annotation.PostConstruct
withjakarta.annotation.PostConstruct
. Spring boot includesjakarta.annotation
dependency since release 2.2 and dropsjavax.annotation
since 3.0.
Additional context
This ticket relates to #778.
I could make PR. But one of proposed solutions should be chosen first. I personally prefer option 1. IMHO it's more reliable since annotations have been already broken once and I never heard that spring broke InitializingBean in some way.