Skip to content

"this.simpleStub" is null #11920

Closed
Closed
@SeanTan7150

Description

@SeanTan7150

tmaccount

@GrpcService
public class HelloService extends SimpleGrpc.SimpleImplBase {

    private static final Logger log = LoggerFactory.getLogger(AuthenticationService.class);

    @Override
    public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) {
        log.info("Hello " + req.getName());
        if (req.getName().startsWith("error")) {
            throw new IllegalArgumentException("Bad name: " + req.getName());
        }
        if (req.getName().startsWith("internal")) {
            throw new RuntimeException();
        }
        HelloReply reply = HelloReply.newBuilder().setMessage("Hello ==> " + req.getName()).build();
        responseObserver.onNext(reply);
        responseObserver.onCompleted();
    }
}

tmcore

@Service
public class HelloService {

    private static final Logger log = LoggerFactory.getLogger(AuthenticationService.class);

    @GrpcClient("tmaccount")
    private SimpleGrpc.SimpleBlockingStub simpleStub;

    public String sendMessage(String name) {
        HelloRequest request = HelloRequest.newBuilder().setName(name).build();
        HelloReply response = simpleStub.sayHello(request);
        return response.getMessage();
    }
}

tmcore application.properties

spring.application.name=tmcore
server.port=8081

# Configuration for MySQL Database
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/tmcore
spring.datasource.username=${DB_USERNAME}
spring.datasource.password=${DB_PASSWORD}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql:true

grpc.client.tmaccount.address=static://localhost:9090
grpc.client.tmaccount.negotiationType=plaintext

When I tried to run helloService.sendMessage("demo"), it shows error below:

java.lang.NullPointerException: Cannot invoke "org.springframework.grpc.sample.proto.SimpleGrpc$SimpleBlockingStub.sayHello(org.springframework.grpc.sample.proto.HelloRequest)" because "this.simpleStub" is null

Is there any configuration I've done wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions