spring-cloud/spring-cloud-netflix

Spring guide for starting Eureka Server results in NullPointerException

ljnelson opened this issue · 2 comments

I went here: https://spring.io/guides/gs/service-registration-and-discovery

I followed the instructions, generating my project via this provided link: https://start.spring.io/#!type=maven-project&language=java&packaging=jar&groupId=com.example&artifactId=eureka-server&name=eureka-server&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.eureka-server&dependencies=cloud-eureka-server

I added the YAML as the instructions indicated to eureka-server/src/main/resources/application.yml:

spring:
  application:
    name: eureka-server
server:
  port: 8761
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
logging:
  level:
    com.netflix.eureka: OFF
    com.netflix.discovery: OFF

The instructions said I could now run ./mvn spring-boot:run. So I did.

This resulted in:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'scopedTarget.eurekaClient' defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.class]: Unsatisfied dependency expressed through method 'eurekaClient' parameter 3: No qualifying bean of type 'com.netflix.discovery.shared.transport.jersey.TransportClientFactories<?>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

and

Caused by: java.lang.NullPointerException: Cannot invoke "org.springframework.cloud.netflix.eureka.CloudEurekaClient.getApplications()" because the return value of "org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getEurekaClient()" is null

I found this similar (closed) issue: #3953 but I think this is a new problem.

For posterity: this happens if, like me, a new user just trying to follow instructions, you run the generated project without first adding the @EnableEurekaServer annotation.

Yes, this is included in the information in the guide and the provided code snippet.