Commit 460753af by Stephen Oakey

Logfile endpoint available when not using spring.boot.admin.url

Added inner-class for admin client registration configuration which is conditional on spring.boot.admin.url. Logfile endpoint is now available when just using Spring Cloud Discovery.
parent 5f1be530
......@@ -34,63 +34,67 @@ import de.codecentric.boot.admin.services.RegistrationApplicationListener;
import de.codecentric.boot.admin.web.BasicAuthHttpRequestInterceptor;
/**
* This configuration adds a registrator bean to the spring context. This bean checks periodicaly, if the using
* application is registered at the spring-boot-admin application. If not, it registers itself.
* This configuration adds a registrator bean to the spring context. This bean
* checks periodicaly, if the using application is registered at the
* spring-boot-admin application. If not, it registers itself.
*/
@Configuration
@ConditionalOnProperty("spring.boot.admin.url")
@EnableConfigurationProperties({ AdminProperties.class, AdminClientProperties.class })
public class SpringBootAdminClientAutoConfiguration {
/**
* Task that registers the application at the spring-boot-admin application.
*/
@Bean
@ConditionalOnMissingBean
public ApplicationRegistrator registrator(AdminProperties admin,
AdminClientProperties client) {
return new ApplicationRegistrator(createRestTemplate(admin), admin, client);
}
@ConditionalOnProperty("spring.boot.admin.url")
public static class AdminClientRegistrationConfig {
/**
* Task that registers the application at the spring-boot-admin
* application.
*/
@Bean
@ConditionalOnMissingBean
public ApplicationRegistrator registrator(AdminProperties admin, AdminClientProperties client) {
return new ApplicationRegistrator(createRestTemplate(admin), admin, client);
}
protected RestTemplate createRestTemplate(AdminProperties admin) {
RestTemplate template = new RestTemplate();
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
protected RestTemplate createRestTemplate(AdminProperties admin) {
RestTemplate template = new RestTemplate();
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
if (admin.getUsername() != null) {
template.setInterceptors(Arrays.<ClientHttpRequestInterceptor> asList(new BasicAuthHttpRequestInterceptor(
admin.getUsername(), admin.getPassword())));
}
if (admin.getUsername() != null) {
template.setInterceptors(Arrays.<ClientHttpRequestInterceptor> asList(
new BasicAuthHttpRequestInterceptor(admin.getUsername(), admin.getPassword())));
}
return template;
}
return template;
}
/**
* TaskRegistrar that triggers the RegistratorTask every ten seconds.
*/
@Bean
public ScheduledTaskRegistrar taskRegistrar(final ApplicationRegistrator registrator,
AdminProperties admin, final AdminClientProperties client) {
ScheduledTaskRegistrar registrar = new ScheduledTaskRegistrar();
Runnable registratorTask = new Runnable() {
@Override
public void run() {
if (client.isServerInitialized()) {
registrator.register();
/**
* TaskRegistrar that triggers the RegistratorTask every ten seconds.
*/
@Bean
public ScheduledTaskRegistrar taskRegistrar(final ApplicationRegistrator registrator, AdminProperties admin,
final AdminClientProperties client) {
ScheduledTaskRegistrar registrar = new ScheduledTaskRegistrar();
Runnable registratorTask = new Runnable() {
@Override
public void run() {
if (client.isServerInitialized()) {
registrator.register();
}
}
}
};
};
registrar.addFixedRateTask(registratorTask, admin.getPeriod());
return registrar;
}
registrar.addFixedRateTask(registratorTask, admin.getPeriod());
return registrar;
}
/**
* ApplicationListener triggering registration after refresh/shutdown
*/
@Bean
public RegistrationApplicationListener registrationListener(final ApplicationRegistrator registrator,
final AdminProperties admin) {
return new RegistrationApplicationListener(admin, registrator);
}
/**
* ApplicationListener triggering registration after refresh/shutdown
*/
@Bean
public RegistrationApplicationListener registrationListener(
final ApplicationRegistrator registrator, final AdminProperties admin) {
return new RegistrationApplicationListener(admin, registrator);
}
@Configuration
......
......@@ -27,6 +27,13 @@ public class SpringBootAdminClientAutoConfigurationTest {
public void not_active() {
load();
assertTrue(context.getBeansOfType(ApplicationRegistrator.class).isEmpty());
assertTrue(context.getBeansOfType(LogfileMvcEndpoint.class).isEmpty());
}
public void not_active_logfile() {
load();
assertTrue(context.getBeansOfType(ApplicationRegistrator.class).isEmpty());
context.getBean(LogfileMvcEndpoint.class);
}
@Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment