Spring-boot-admin: Application failed to registered itself as Application

Created on 2 Jun 2017  路  5Comments  路  Source: codecentric/spring-boot-admin

Hello,
I'm trying to test spring-boot-admin in my spring-boot application.

The admin page is loaded but with no informations inside.
In the console, I have this error message :

2017-06-02 12:42:30.803  WARN 8164 --- [gistrationTask1] d.c.b.a.c.r.ApplicationRegistrator       
: Application failed to registered itself as Application [name=spring-boot-application, 
managementUrl=http://DESKTOP-KEUAJ1V.home:8080, healthUrl=http://DESKTOP-KEUAJ1V.home:8080/health, 
serviceUrl=http://DESKTOP-KEUAJ1V.home:8080]. Response: <302 Found,{X-Content-Type-Options=[nosniff],
 X-XSS-Protection=[1; mode=block], Cache-Control=[no-cache, no-store, max-age=0, must-revalidate],
 Pragma=[no-cache], Expires=[0], Location=[http://localhost:8080/login], Content-Length=[0], Date=[Fri, 02 Jun 2017 10:42:30 GMT]}>

I use gradle and not maven..

My build.gradle add this dependencies :聽

    // spring-boot-admin
    compile "de.codecentric:spring-boot-admin-server:1.5.0"
    compile "de.codecentric:spring-boot-admin-server-ui:1.5.0"
    compile 'de.codecentric:spring-boot-admin-server-ui-login:1.5.0'
    compile "de.codecentric:spring-boot-admin-starter-client:1.5.0"

    runtime("org.springframework.boot:spring-boot-starter-actuator")

and before I activate the spring-boot-plugin :聽

buildscript {

    repositories {
        jcenter()
    }

    // to let gradle to use kotlin, spring boot, and kotlin-allopen
    // kotlin-allopen let spring use kotlin classes without the need to add the keyword 'open'
    // see https://blog.jetbrains.com/kotlin/2016/12/kotlin-1-0-6-is-here/
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version"
        classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
    }
}

plugins {
    id 'org.springframework.boot' version '1.5.3.RELEASE'
}
````

my Application class look like that : 

@SpringBootApplication
@EnableAdminServer
class Application
fun main(args: Array) {

SpringApplication.run(Application::class.java, *args)

}

I'm using the Kotlin language instead of java.

I aslo add a spring security configuration.

And my applications.properties have this content : 

management.security.enabled=false
spring.boot.admin.url=http://localhost:8080
spring.boot.admin.context-path=/admin

Maybe the problem come from spring-security.
my security-config look like that : 

@Configuration
@EnableWebSecurity
class SecurityConfig(val userDetailsService: AuthenticationService, var env: Environment)
: WebSecurityConfigurerAdapter() {

@Throws(Exception::class)
override fun configure(http: HttpSecurity) {
    http
            .authorizeRequests()
            .antMatchers("/css/**", "/js/**", "/images/**",
                    "/api/rest/**", "/login", "/signup", "/logout", "/myconsole/**").permitAll()
            .antMatchers("/", "/**").hasRole("USER")
            .and()
            .formLogin()
            .loginPage("/login")
            .defaultSuccessUrl("/", true)

    if (!env.activeProfiles.contains("production")) {
        // we are not in a production environment
        println("we are not in production mode")
        http.csrf().disable()
        http.headers().frameOptions().disable()
    }

}

@Throws(Exception::class)
override fun configure(auth: AuthenticationManagerBuilder) {
    auth.authenticationProvider(authProvider())
    auth.inMemoryAuthentication()
            .withUser("user").password("password").roles("USER")
}

@Bean
fun authProvider(): DaoAuthenticationProvider {
    val authProvider = DaoAuthenticationProvider()
    authProvider.setUserDetailsService(userDetailsService)
    authProvider.setPasswordEncoder(passwordEncoder())
    return authProvider
}


@Bean
fun passwordEncoder(): PasswordEncoder {
    return BCryptPasswordEncoder()
}

}
```
For testing, i am not in production profile, so the csrf security is disabled.

Do you have any ideas ?

Thank you :)

Most helpful comment

Exactly.
You got it: It is because of spring security: when spring-admin look to the url /healh, it is redirected to /login.
So I have to find a way to manage with spring-security

All 5 comments

Looks like spring security is doing a redirect for the POST to /api/applications. So you should tell the SBA client the username and password (using spring.boot.admin.username and spring.boot.admin.password) for this http endpoint or allow requests without credentials for this endpoint.

Thanks.
To try I allow request without credentials for this endpoints.
Now I have this error :

org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [interface java.util.Map] and content type [text/html;charset=UTF-8]
        at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:109) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:917) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:901) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:655) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:628) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:549) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at de.codecentric.boot.admin.web.client.ApplicationOperations.doGet(ApplicationOperations.java:74) ~[spring-boot-admin-server-1.5.0.jar:1.5.0]
        at de.codecentric.boot.admin.web.client.ApplicationOperations.getHealth(ApplicationOperations.java:64) ~[spring-boot-admin-server-1.5.0.jar:1.5.0]
        at de.codecentric.boot.admin.registry.StatusUpdater.queryStatus(StatusUpdater.java:111) [spring-boot-admin-server-1.5.0.jar:1.5.0]
        at de.codecentric.boot.admin.registry.StatusUpdater.updateStatus(StatusUpdater.java:65) [spring-boot-admin-server-1.5.0.jar:1.5.0]
        at de.codecentric.boot.admin.registry.StatusUpdateApplicationListener$1.run(StatusUpdateApplicationListener.java:47) [spring-boot-admin-server-1.5.0.jar:1.5.0]
        at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_131]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_131]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_131]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_131]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_131]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_131]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]

And when I go to the url : 'http://localhost:8080/api/applications' I have this answer :

[{"id":"c21b008a","name":"spring-boot-application","managementUrl":"http://DESKTOP-KEUAJ1V.home:8080","healthUrl":"http://DESKTOP-KEUAJ1V.home:8080/health","serviceUrl":"http://DESKTOP-KEUAJ1V.home:8080","statusInfo":{"status":"OFFLINE","timestamp":1496594013380,"details":{"exception":"org.springframework.web.client.RestClientException","message":"Could not extract response: no suitable HttpMessageConverter found for response type [interface java.util.Map] and content type [text/html;charset=UTF-8]"}},"source":"http-api","metadata":{},"info":{}}]

I guess it can not convert a java.util.map. I have some rest endpoints in my applications. I also add some jackson dependencies as 'databind', 'core', and 'mapper' just in case. No change.

Do you have any idea of what can I do to fix it ?

Thank you

It looks like your /heatlh endpoint is responding html instead of json. You'll need to fix this.

Exactly.
You got it: It is because of spring security: when spring-admin look to the url /healh, it is redirected to /login.
So I have to find a way to manage with spring-security

if possible please make one client and server integration using SPRING BOOT ADMIN with spring security.

Was this page helpful?
0 / 5 - 0 ratings