AnoyiX/grpc-spring-boot-starter

客户端的Service无法注入

Closed this issue · 4 comments

服务端启动正常,客户端公共接口无法注入,@Autowired注解报红

@RunWith(SpringRunner.class)
@SpringBootTest
public class GrpcClientApplicationTests {

@Test
public void contextLoads() {
}


@Autowired
private CommonService commonService;


@Test
public void testRpc() throws Exception{
    System.out.println(this.commonService.say("123"));
}

}

换了,还是不行

服务端代码:
//公共接口
@GrpcService(server = "stringTest")
public interface StringTestService {
public String say(String msg);
}
//实现类
@service
public class StringTestServiceImpl implements StringTestService {
@OverRide
public String say(String msg) {
System.out.println("----");
return msg;
}
}
//配置文件
server.port=8080

properties 格式

spring.grpc.enable=true
spring.grpc.port=6565

客户端代码:
//公共接口
@GrpcService(server = "stringTest")
public interface StringTestService {
public String say(String msg);
}
//配置文件
server.port=8081
spring.grpc.remote-servers[0].server=stringTest
spring.grpc.remote-servers[0].host=127.0.0.1
spring.grpc.remote-servers[0].port=6565
//测试类调用
@RunWith(SpringRunner.class)
@SpringBootTest
public class GrpcClientApplicationTests {

@Test
public void contextLoads() {
}


@Autowired
private StringTestService stringTestService;


@Test
public void testRpc() throws Exception{
    System.out.println(this.stringTestService.say("123"));
}

}

//报错信息

CONDITIONS EVALUATION REPORT

Positive matches:

CodecsAutoConfiguration matched:
- @ConditionalOnClass found required class 'org.springframework.http.codec.CodecConfigurer' (OnClassCondition)

CodecsAutoConfiguration.JacksonCodecConfiguration matched:
- @ConditionalOnClass found required class 'com.fasterxml.jackson.databind.ObjectMapper' (OnClassCondition)

CodecsAutoConfiguration.JacksonCodecConfiguration#jacksonCodecCustomizer matched:
- @ConditionalOnBean (types: com.fasterxml.jackson.databind.ObjectMapper; SearchStrategy: all) found bean 'jacksonObjectMapper' (OnBeanCondition)

DispatcherServletAutoConfiguration matched:
- @ConditionalOnClass found required class 'org.springframework.web.servlet.DispatcherServlet' (OnClassCondition)
- found 'session' scope (OnWebApplicationCondition)

DispatcherServletAutoConfiguration.DispatcherServletConfiguration matched:
- @ConditionalOnClass found required class 'javax.servlet.ServletRegistration' (OnClassCondition)
- Default DispatcherServlet did not find dispatcher servlet beans (DispatcherServletAutoConfiguration.DefaultDispatcherServletCondition)

DispatcherServletAutoConfiguration.DispatcherServletRegistrationConfiguration matched:
- @ConditionalOnClass found required class 'javax.servlet.ServletRegistration' (OnClassCondition)
- DispatcherServlet Registration did not find servlet registration bean (DispatcherServletAutoConfiguration.DispatcherServletRegistrationCondition)

DispatcherServletAutoConfiguration.DispatcherServletRegistrationConfiguration#dispatcherServletRegistration matched:
- @ConditionalOnBean (names: dispatcherServlet; types: org.springframework.web.servlet.DispatcherServlet; SearchStrategy: all) found bean 'dispatcherServlet' (OnBeanCondition)

EmbeddedWebServerFactoryCustomizerAutoConfiguration matched:
- @ConditionalOnWebApplication (required) found 'session' scope (OnWebApplicationCondition)

EmbeddedWebServerFactoryCustomizerAutoConfiguration.TomcatWebServerFactoryCustomizerConfiguration matched:
- @ConditionalOnClass found required classes 'org.apache.catalina.startup.Tomcat', 'org.apache.coyote.UpgradeProtocol' (OnClassCondition)

ErrorMvcAutoConfiguration matched:
- @ConditionalOnClass found required classes 'javax.servlet.Servlet', 'org.springframework.web.servlet.DispatcherServlet' (OnClassCondition)
- found 'session' scope (OnWebApplicationCondition)

可以