grpc-ecosystem / grpc-spring

Spring Boot starter module for gRPC framework.
https://grpc-ecosystem.github.io/grpc-spring/
Apache License 2.0
3.43k stars 809 forks source link

Replace obsolete @PostConstruct annotation or implement InitializingBean #1044

Closed onyn closed 5 months ago

onyn commented 5 months ago

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:

  1. Remove annotation entirely and implement org.springframework.beans.factory.InitializingBean interface.
  2. Replace javax.annotation.PostConstruct with jakarta.annotation.PostConstruct. Spring boot includes jakarta.annotation dependency since release 2.2 and drops javax.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.

onyn commented 5 months ago

Oh, I see it's already done in 98f29e4e.