-
Notifications
You must be signed in to change notification settings - Fork 434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LocalRunningGrpcPort annotation does not work in main code #353
Comments
I found out the cause of the problem. The annotation is a wrapper @value("#{@gRpcServerProperties.getRunningPort()}"). GRpcServerProperties is autowired in this case. All of this works, but the procedure how GRpcServerProperties runningPort is instantiated changed. Version 4 instantiated the member inside the getter if it is null before returning it. Version 5 however instantiates the value using an EventListener annotated method listening for GRpcServerInitializedEvent. This event occurs after the value is injected by LocalRunningGrpcPort, which causes the getter to return null. I don't know a solution for this. Maybe it is possible to wait for a specific event (GRpcServerInitializedEvent in this case) before the value is injected? |
This is about when you instantiate the instance of class that has this field. If you make this bean be dependent on grpc beans, it will be propagated correctly. |
I don't understand. Can you give an example? For context, my class looks like this:
To explain the Order annotation, I use this because I listen for the ContextStartedEvent on multiple places and want to execute the register method first. Maybe you can help me to pimp my code to not run into this problem. |
Ah,ok, for your use case it's better to use the event listener on started grpc server, you can get the port from there https://github.com/LogNet/grpc-spring-boot-starter#5-events |
I changed my implementation to simply listen to the GRpcServerInitializedEvent instead of ContextStartedEvent and get the port from the event. This works for me. Still I would consider this a workaround. The original issue, the LocalRunningGrpcPort annotation not working, is not resolved. Everyone using this annotation can/will run into trouble. So let's not close this issue until a solution is found. In the meantime everyone can use this workaround: Change
to
|
Using the LocalRunningGrpcPort annotation in test code works, the port is injected.
When using the annotation in main code, the injection does not work, null is returned.
The annotation worked in main code in version 4.x with Spring Boot 2.7.x.
The annotation does not work anymore in main code with version 5.1.1 with Spring Boot 3.0.6.
The text was updated successfully, but these errors were encountered: