Commit 275647ee by Johannes Edmeier

Defer the configuration-import

Due to our use of @Conditionals on our @Configuration-classes the import must be deferred, so that the classes are processed after all other @Configuration-classes
parent e364adfe
/*
* Copyright 2014 the original author or authors.
* Copyright 2013-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -15,20 +15,24 @@
*/
package de.codecentric.boot.admin.config;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DeferredImportSelector;
import org.springframework.core.type.AnnotationMetadata;
import de.codecentric.boot.admin.registry.store.ApplicationStore;
import de.codecentric.boot.admin.registry.store.SimpleApplicationStore;
/**
* Defers the imports for our {@code @Configuration}-classes, because the need to be processed after
* normal @Configuration-classes.
*
* @author Johannes Edmeier
*/
public class AdminServerImportSelector implements DeferredImportSelector {
@Configuration
@AutoConfigureAfter({ HazelcastStoreConfiguration.class })
public class SimpleStoreConfig {
@Bean
@ConditionalOnMissingBean
public ApplicationStore applicationStore() {
return new SimpleApplicationStore();
@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
return new String[] { MailNotifierConfiguration.class.getCanonicalName(),
HazelcastStoreConfiguration.class.getCanonicalName(),
AdminServerWebConfiguration.class.getCanonicalName(),
DiscoveryClientConfiguration.class.getCanonicalName(),
RevereseZuulProxyConfiguration.class.getCanonicalName() };
}
}
......@@ -49,11 +49,9 @@ import de.codecentric.boot.admin.registry.ApplicationRegistry;
import de.codecentric.boot.admin.registry.HashingApplicationUrlIdGenerator;
import de.codecentric.boot.admin.registry.StatusUpdater;
import de.codecentric.boot.admin.registry.store.ApplicationStore;
import de.codecentric.boot.admin.registry.store.SimpleApplicationStore;
@Configuration
@Import({ RevereseZuulProxyConfiguration.class, MailNotifierConfiguration.class,
HazelcastStoreConfiguration.class, SimpleStoreConfig.class,
DiscoveryClientConfiguration.class })
public class AdminServerWebConfiguration extends WebMvcConfigurerAdapter implements
ApplicationContextAware {
......@@ -166,4 +164,10 @@ public class AdminServerWebConfiguration extends WebMvcConfigurerAdapter impleme
return new JournalController(applicationEventJournal());
}
@Bean
@ConditionalOnMissingBean
public ApplicationStore applicationStore() {
return new SimpleApplicationStore();
}
}
......@@ -29,7 +29,7 @@ import org.springframework.context.annotation.Import;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import(AdminServerWebConfiguration.class)
@Import(AdminServerImportSelector.class)
public @interface EnableAdminServer {
}
......@@ -19,6 +19,7 @@ import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
......@@ -45,6 +46,7 @@ import de.codecentric.boot.admin.registry.store.HazelcastApplicationStore;
@Configuration
@ConditionalOnClass({ Hazelcast.class })
@ConditionalOnProperty(prefix = "spring.boot.admin.hazelcast", name = "enabled", matchIfMissing = true)
@AutoConfigureBefore(AdminServerWebConfiguration.class)
public class HazelcastStoreConfiguration {
@Value("${spring.boot.admin.hazelcast.map:spring-boot-admin-application-store}")
......@@ -83,16 +85,14 @@ public class HazelcastStoreConfiguration {
@Override
public void entryAdded(EntryEvent<String, Application> event) {
if (event.getValue() != null) {
publisher
.publishEvent(new ClientApplicationRegisteredEvent(event.getValue()));
publisher.publishEvent(new ClientApplicationRegisteredEvent(event.getValue()));
}
}
@Override
public void entryRemoved(EntryEvent<String, Application> event) {
if (event.getValue() != null) {
publisher.publishEvent(new ClientApplicationDeregisteredEvent(event
.getValue()));
publisher.publishEvent(new ClientApplicationDeregisteredEvent(event.getValue()));
}
}
......@@ -100,12 +100,11 @@ public class HazelcastStoreConfiguration {
public void entryUpdated(EntryEvent<String, Application> event) {
if (!Objects.equals(event.getOldValue(), event.getValue())) {
if (event.getOldValue() != null) {
publisher.publishEvent(new ClientApplicationDeregisteredEvent(event
.getOldValue()));
publisher.publishEvent(
new ClientApplicationDeregisteredEvent(event.getOldValue()));
}
if (event.getValue() != null) {
publisher.publishEvent(new ClientApplicationRegisteredEvent(event
.getValue()));
publisher.publishEvent(new ClientApplicationRegisteredEvent(event.getValue()));
}
} else {
StatusInfo from = event.getOldValue() != null ? event.getOldValue().getStatusInfo()
......@@ -113,8 +112,8 @@ public class HazelcastStoreConfiguration {
StatusInfo to = event.getValue() != null ? event.getValue().getStatusInfo()
: StatusInfo.ofUnknown();
if (!from.equals(to)) {
publisher.publishEvent(new ClientApplicationStatusChangedEvent(event
.getValue(), from, to));
publisher.publishEvent(
new ClientApplicationStatusChangedEvent(event.getValue(), from, to));
}
}
}
......@@ -122,8 +121,7 @@ public class HazelcastStoreConfiguration {
@Override
public void entryEvicted(EntryEvent<String, Application> event) {
if (event.getValue() != null) {
publisher.publishEvent(new ClientApplicationDeregisteredEvent(event
.getValue()));
publisher.publishEvent(new ClientApplicationDeregisteredEvent(event.getValue()));
}
}
......
......@@ -99,6 +99,9 @@ public class AdminServerWebConfigurationTest {
applicationContext.register(ServerPropertiesAutoConfiguration.class);
applicationContext.register(NoopDiscoveryClientAutoConfiguration.class);
applicationContext.register(MailSenderAutoConfiguration.class);
applicationContext.register(MailNotifierConfiguration.class);
applicationContext.register(HazelcastStoreConfiguration.class);
applicationContext.register(DiscoveryClientConfiguration.class);
applicationContext.register(AdminServerWebConfiguration.class);
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
......
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