Details
We have a Spring Boot 2.0.1.RELEASE service that is using Eureka as a client. We get the below 401 error stack trace when it attempts to register the service with the service registry.
The service runs on PCF version 2.1 using Eureka as a PCF service tile. The tile is created by our Concourse pipeline and it is bound via a manifest.yml file.
We are at a loss as to why this error is occurring. Is it an issue with running Spring Boot 2.0?
build.gradle
buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
springCloudVersion = 'Finchley.RC1'
swaggerVersion = '2.7.0'
}
repositories {
mavenCentral()
maven {
name = 'spring-milestone'
url = 'https://repo.spring.io/milestone'
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
}
}
plugins {
id 'org.springframework.boot' version '2.0.1.RELEASE'
id 'io.franzbecker.gradle-lombok' version '1.12'
id 'net.researchgate.release' version '2.6.0'
id 'com.github.ben-manes.versions' version '0.17.0'
id "com.gorylenko.gradle-git-properties" version '1.4.17'
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.gaig.services'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-cloud-connectors')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
runtime('org.springframework.boot:spring-boot-devtools')
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
compile('io.pivotal.spring.cloud:cloudfoundry-certificate-truster:1.0.1.RELEASE')
compile('com.oracle:ojdbc8:12.2.0.1')
runtime('com.h2database:h2')
compile('org.projectlombok:lombok')
compile('com.google.code.gson:gson:2.8.2')
compile("io.springfox:springfox-swagger-ui:$swaggerVersion")
compile("io.springfox:springfox-swagger2:$swaggerVersion")
testCompile('org.springframework.boot:spring-boot-starter-test')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion"
}
}
springBoot {
buildInfo()
}
SpringBoot Application Class
@EnableEurekaClient
@SpringBootApplication
public class SearchApplication {
public static void main(String[] args) {
SpringApplication.run(SearchApplication.class, args);
}
}
manifest.yml
---
applications:
- name: search-service
buildpack: java_buildpack_offline
path: build/libs/search-service.jar
services:
- service-registry
env:
APP_LOG_LEVEL: INFO
TRUST_CERTS: OUR_COMPANY_PCF_UAA_ENDPOINT:443
EUREKA_ENABLED: false
application.yml
spring:
application:
name: search-service
management:
info:
git:
mode: full
cloudfoundry:
enabled: true
skip-ssl-validation: true
endpoint:
health:
show-details: always
eureka:
client:
enabled: ${EUREKA_ENABLED:false}
service-url:
defaultZone: ${vcap.services.service-registry.credentials.uri}/eureka/
Health Check
{
"status": "UP",
"details": {
"diskSpace": {
"status": "UP",
"details": {
"total": 1073741824,
"free": 876646400,
"threshold": 10485760
}
},
"refreshScope": {
"status": "UP"
},
"discoveryComposite": {
"status": "UP",
"details": {
"discoveryClient": {
"status": "UP",
"details": {
"services": []
}
},
"eureka": {
"description": "Remote status from Eureka server",
"status": "UNKNOWN",
"details": {
"applications": {}
}
}
}
},
"hystrix": {
"status": "UP"
}
}
}
Stack Trace
2018-05-08T08:54:17.944-04:00 [APP/PROC/WEB/0] [OUT] 2018-05-08 12:54:17.944 INFO 17 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_PIM-SUBMISSION-SEARCH/086b89b6-f68f-41e5-75bd-7667: registering service...
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] 2018-05-08 12:54:17.954 WARN 17 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failure with status code 401; retrying on another server if available
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] 2018-05-08 12:54:17.954 WARN 17 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_PIM-SUBMISSION-SEARCH/086b89b6-f68f-41e5-75bd-7667 - registration failed Cannot execute request on any known server
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:112) ~[eureka-client-1.8.7.jar!/:1.8.7]
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.8.7.jar!/:1.8.7]
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59) ~[eureka-client-1.8.7.jar!/:1.8.7]
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.8.7.jar!/:1.8.7]
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:829) ~[eureka-client-1.8.7.jar!/:1.8.7]
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:121) [eureka-client-1.8.7.jar!/:1.8.7]
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] at com.netflix.discovery.InstanceInfoReplicator$1.run(InstanceInfoReplicator.java:101) [eureka-client-1.8.7.jar!/:1.8.7]
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_162]
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_162]
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_162]
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_162]
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_162]
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_162]
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_162]
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] 2018-05-08 12:54:17.954 WARN 17 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator : There was a problem with the instance info replicator
2018-05-08T08:54:17.957-04:00 [APP/PROC/WEB/0] [OUT] at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:121) ~[eureka-client-1.8.7.jar!/:1.8.7]
2018-05-08T08:54:17.976-04:00 [APP/PROC/WEB/0] [OUT] 2018-05-08 12:54:17.971 INFO 17 --- [ Thread-26] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 2147483647
2018-05-08T08:54:17.976-04:00 [APP/PROC/WEB/0] [OUT] 2018-05-08 12:54:17.971 INFO 17 --- [ Thread-26] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 0
2018-05-08T08:54:17.976-04:00 [APP/PROC/WEB/0] [OUT] 2018-05-08 12:54:17.972 INFO 17 --- [ Thread-26] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2018-05-08T08:54:17.976-04:00 [APP/PROC/WEB/0] [OUT] 2018-05-08 12:54:17.973 INFO 17 --- [ Thread-26] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans
2018-05-08T08:54:17.977-04:00 [APP/PROC/WEB/0] [OUT] 2018-05-08 12:54:17.976 INFO 17 --- [ Thread-26] com.netflix.discovery.DiscoveryClient : Shutting down DiscoveryClient ...
Comment From: ryanjbaxter
I believe this is a duplicate of #2754.
Comment From: cjaehnen
@ryanjbaxter I tried various suggestions from the #2754 but cannot get this to work. There error in #2754 is a 403 error, whereas my error is a 401 error.
Are you certain these are the same problem? Perhaps I'm missing something.
Comment From: ryanjbaxter
Is the same problem reproducible outside of cloud foundry using open source spring cloud? If so can you provide a sample that reproduces the problem?
Comment From: vemmkof
Server WebSecurityConfigurerAdapter
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable() //
.authorizeRequests() //
.antMatchers(HttpMethod.GET, "/eureka/**").authenticated() // eureka client
.antMatchers(HttpMethod.POST, "/eureka/**").authenticated() // eureka client
.antMatchers(HttpMethod.DELETE, "/eureka/**").authenticated() // eureka client
.anyRequest().authenticated().and().httpBasic(); // dashboard authorization
}
Server side application.properties
server.port=8761
spring.application.name=eureka-server
spring.security.user.name=username
spring.security.user.password=password
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.service-url.defaultZone=http://username:password@localhost:8761/eureka
Client side application.properties
spring.application.name=eureka-client
eureka.client.service-url.defaultZone=http://username:password@localhost:8761/eureka
Comment From: SubhankarMukherjee
This is not working after all settings recommended. Please sugggest
Comment From: ryanjbaxter
Please open a separate issue
Comment From: GuilhermeMelo01
add this configuration in your aplication.yml
eureka.client.register-with-eureka=false eureka.client.fetch-registry=false