Commit 9c666b67 by Johannes Stelzer

Merge pull request #85 from steve-oakey/master

Logfile endpoint available when not using spring.boot.admin.url
parents 5f1be530 460753af
...@@ -34,63 +34,67 @@ import de.codecentric.boot.admin.services.RegistrationApplicationListener; ...@@ -34,63 +34,67 @@ import de.codecentric.boot.admin.services.RegistrationApplicationListener;
import de.codecentric.boot.admin.web.BasicAuthHttpRequestInterceptor; import de.codecentric.boot.admin.web.BasicAuthHttpRequestInterceptor;
/** /**
* This configuration adds a registrator bean to the spring context. This bean checks periodicaly, if the using * This configuration adds a registrator bean to the spring context. This bean
* application is registered at the spring-boot-admin application. If not, it registers itself. * checks periodicaly, if the using application is registered at the
* spring-boot-admin application. If not, it registers itself.
*/ */
@Configuration @Configuration
@ConditionalOnProperty("spring.boot.admin.url")
@EnableConfigurationProperties({ AdminProperties.class, AdminClientProperties.class }) @EnableConfigurationProperties({ AdminProperties.class, AdminClientProperties.class })
public class SpringBootAdminClientAutoConfiguration { public class SpringBootAdminClientAutoConfiguration {
/** @ConditionalOnProperty("spring.boot.admin.url")
* Task that registers the application at the spring-boot-admin application. public static class AdminClientRegistrationConfig {
*/ /**
@Bean * Task that registers the application at the spring-boot-admin
@ConditionalOnMissingBean * application.
public ApplicationRegistrator registrator(AdminProperties admin, */
AdminClientProperties client) { @Bean
return new ApplicationRegistrator(createRestTemplate(admin), admin, client); @ConditionalOnMissingBean
} public ApplicationRegistrator registrator(AdminProperties admin, AdminClientProperties client) {
return new ApplicationRegistrator(createRestTemplate(admin), admin, client);
}
protected RestTemplate createRestTemplate(AdminProperties admin) { protected RestTemplate createRestTemplate(AdminProperties admin) {
RestTemplate template = new RestTemplate(); RestTemplate template = new RestTemplate();
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
if (admin.getUsername() != null) { if (admin.getUsername() != null) {
template.setInterceptors(Arrays.<ClientHttpRequestInterceptor> asList(new BasicAuthHttpRequestInterceptor( template.setInterceptors(Arrays.<ClientHttpRequestInterceptor> asList(
admin.getUsername(), admin.getPassword()))); new BasicAuthHttpRequestInterceptor(admin.getUsername(), admin.getPassword())));
} }
return template; return template;
} }
/** /**
* TaskRegistrar that triggers the RegistratorTask every ten seconds. * TaskRegistrar that triggers the RegistratorTask every ten seconds.
*/ */
@Bean @Bean
public ScheduledTaskRegistrar taskRegistrar(final ApplicationRegistrator registrator, public ScheduledTaskRegistrar taskRegistrar(final ApplicationRegistrator registrator, AdminProperties admin,
AdminProperties admin, final AdminClientProperties client) { final AdminClientProperties client) {
ScheduledTaskRegistrar registrar = new ScheduledTaskRegistrar(); ScheduledTaskRegistrar registrar = new ScheduledTaskRegistrar();
Runnable registratorTask = new Runnable() { Runnable registratorTask = new Runnable() {
@Override @Override
public void run() { public void run() {
if (client.isServerInitialized()) { if (client.isServerInitialized()) {
registrator.register(); registrator.register();
}
} }
} };
};
registrar.addFixedRateTask(registratorTask, admin.getPeriod()); registrar.addFixedRateTask(registratorTask, admin.getPeriod());
return registrar; 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 @Configuration
......
...@@ -27,6 +27,13 @@ public class SpringBootAdminClientAutoConfigurationTest { ...@@ -27,6 +27,13 @@ public class SpringBootAdminClientAutoConfigurationTest {
public void not_active() { public void not_active() {
load(); load();
assertTrue(context.getBeansOfType(ApplicationRegistrator.class).isEmpty()); 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 @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