Skip to content
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

"this.simpleStub" is null #11920

Open
SeanTan7150 opened this issue Feb 22, 2025 · 1 comment
Open

"this.simpleStub" is null #11920

SeanTan7150 opened this issue Feb 22, 2025 · 1 comment
Labels

Comments

@SeanTan7150
Copy link

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?

@kannanjgithub
Copy link
Contributor

This isn't really a gRPC specific question but about spring boot auto configuration not working. You should check for things like component base scan whether it includes the package where you are trying to use the auto-configure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants