Support for @LocalGrpcPort in @Lazy beans
This commit is contained in:
@@ -10,13 +10,15 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.grpc.client.GrpcChannelFactory;
|
||||
import org.springframework.grpc.sample.proto.HelloReply;
|
||||
import org.springframework.grpc.sample.proto.HelloRequest;
|
||||
import org.springframework.grpc.sample.proto.SimpleGrpc;
|
||||
import org.springframework.grpc.test.LocalGrpcPort;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
@SpringBootTest
|
||||
@SpringBootTest(properties = "spring.grpc.server.port=0")
|
||||
public class GrpcServerApplicationTests {
|
||||
|
||||
private static Log log = LogFactory.getLog(GrpcServerApplicationTests.class);
|
||||
@@ -45,8 +47,9 @@ public class GrpcServerApplicationTests {
|
||||
static class ExtraConfiguration {
|
||||
|
||||
@Bean
|
||||
SimpleGrpc.SimpleBlockingStub stub(GrpcChannelFactory channels) {
|
||||
return SimpleGrpc.newBlockingStub(channels.createChannel("0.0.0.0:9090").build());
|
||||
@Lazy
|
||||
SimpleGrpc.SimpleBlockingStub stub(GrpcChannelFactory channels, @LocalGrpcPort int port) {
|
||||
return SimpleGrpc.newBlockingStub(channels.createChannel("0.0.0.0:" + port).build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user