sfcodes / grpc-client-spring-boot

Spring Boot module for auto-configuring gRPC stubs
Apache License 2.0
19 stars 0 forks source link

Autowiring not working #2

Open clamey opened 4 years ago

clamey commented 4 years ago

Downloaded a new Springboot project from https://start.spring.io/ as Gradle, Java 8, Spring 2.2.1. Then configured as per the README, adding in implementation ("codes.sf:grpc-client-spring-boot:0.0.4") and @GrpcStubScan(basePackages = arrayOf("com.stackhawk.protostuff")) but am getting this on startup:

Field stub in com.stackhawk.nest.FooController required a bean of type 'com.stackhawk.nest.UserServiceGrpc$UserServiceBlockingStub' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)

If I leave out the @Autowired from my controller, the app starts and I can see my GRPC stub beans in the spring context with something like this:

        val byName = applicationContext.getBean("userServiceGrpc.UserServiceBlockingStub")
        val byClazz = applicationContext.getBean(UserServiceGrpc.UserServiceBlockingStub::class.java)

But that's not ideal.

Our GRPC services are in an external jar file to the project which might be relevant. I did copy everything locally to the project and got the same result, so it might not be a factor.

clamey commented 4 years ago

Also getting this in the output, not sure if it's relevant:

@Bean method GrpcStubScannerConfiguration.grpcStubScannerBeanFactoryPostProcessor is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details.