Commit fef76a64 by Johannes Edmeier

Extract core- from web-config

parent d49f16a0
...@@ -12,6 +12,7 @@ import org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration.Res ...@@ -12,6 +12,7 @@ import org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration.Res
import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import de.codecentric.boot.admin.config.AdminServerCoreConfiguration;
import de.codecentric.boot.admin.config.AdminServerWebConfiguration; import de.codecentric.boot.admin.config.AdminServerWebConfiguration;
import de.codecentric.boot.admin.config.RevereseZuulProxyConfiguration; import de.codecentric.boot.admin.config.RevereseZuulProxyConfiguration;
import spring.boot.admin.turbine.web.TurbineController; import spring.boot.admin.turbine.web.TurbineController;
...@@ -51,6 +52,7 @@ public class TurbineAutoConfigurationTest { ...@@ -51,6 +52,7 @@ public class TurbineAutoConfigurationTest {
applicationContext.register(PropertyPlaceholderAutoConfiguration.class); applicationContext.register(PropertyPlaceholderAutoConfiguration.class);
applicationContext.register(RestTemplateConfiguration.class); applicationContext.register(RestTemplateConfiguration.class);
applicationContext.register(ServerPropertiesAutoConfiguration.class); applicationContext.register(ServerPropertiesAutoConfiguration.class);
applicationContext.register(AdminServerCoreConfiguration.class);
applicationContext.register(AdminServerWebConfiguration.class); applicationContext.register(AdminServerWebConfiguration.class);
applicationContext.register(RevereseZuulProxyConfiguration.class); applicationContext.register(RevereseZuulProxyConfiguration.class);
applicationContext.register(TurbineAutoConfiguration.class); applicationContext.register(TurbineAutoConfiguration.class);
......
/*
* Copyright 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.codecentric.boot.admin.config;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.web.client.DefaultResponseErrorHandler;
import de.codecentric.boot.admin.journal.ApplicationEventJournal;
import de.codecentric.boot.admin.journal.store.JournaledEventStore;
import de.codecentric.boot.admin.journal.store.SimpleJournaledEventStore;
import de.codecentric.boot.admin.registry.ApplicationIdGenerator;
import de.codecentric.boot.admin.registry.ApplicationRegistry;
import de.codecentric.boot.admin.registry.HashingApplicationUrlIdGenerator;
import de.codecentric.boot.admin.registry.StatusUpdateApplicationListener;
import de.codecentric.boot.admin.registry.StatusUpdater;
import de.codecentric.boot.admin.registry.store.ApplicationStore;
import de.codecentric.boot.admin.registry.store.SimpleApplicationStore;
import de.codecentric.boot.admin.web.client.BasicAuthHttpHeaderProvider;
import de.codecentric.boot.admin.web.client.HttpHeadersProvider;
@Configuration
@EnableConfigurationProperties(AdminServerProperties.class)
public class AdminServerCoreConfiguration {
private final AdminServerProperties adminServerProperties;
public AdminServerCoreConfiguration(AdminServerProperties adminServerProperties) {
this.adminServerProperties = adminServerProperties;
}
@Bean
@ConditionalOnMissingBean
public ApplicationRegistry applicationRegistry(ApplicationStore applicationStore,
ApplicationIdGenerator applicationIdGenerator) {
return new ApplicationRegistry(applicationStore, applicationIdGenerator);
}
@Bean
@ConditionalOnMissingBean
public ApplicationIdGenerator applicationIdGenerator() {
return new HashingApplicationUrlIdGenerator();
}
@Bean
@ConditionalOnMissingBean
public HttpHeadersProvider httpHeadersProvider() {
return new BasicAuthHttpHeaderProvider();
}
@Bean
@ConditionalOnMissingBean
public StatusUpdater statusUpdater(RestTemplateBuilder restTemplBuilder,
ApplicationStore applicationStore) {
RestTemplateBuilder builder = restTemplBuilder
.messageConverters(new MappingJackson2HttpMessageConverter())
.errorHandler(new DefaultResponseErrorHandler() {
@Override
protected boolean hasError(HttpStatus statusCode) {
return false;
}
});
StatusUpdater statusUpdater = new StatusUpdater(builder.build(), applicationStore,
httpHeadersProvider());
statusUpdater.setStatusLifetime(adminServerProperties.getMonitor().getStatusLifetime());
return statusUpdater;
}
@Bean
@Qualifier("updateTaskScheduler")
public TaskScheduler updateTaskScheduler() {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(1);
taskScheduler.setRemoveOnCancelPolicy(true);
taskScheduler.setThreadNamePrefix("updateTask");
return taskScheduler;
}
@Bean
@ConditionalOnMissingBean
public StatusUpdateApplicationListener statusUpdateApplicationListener(
StatusUpdater statusUpdater,
@Qualifier("updateTaskScheduler") TaskScheduler taskScheduler) {
StatusUpdateApplicationListener listener = new StatusUpdateApplicationListener(
statusUpdater, taskScheduler);
listener.setUpdatePeriod(adminServerProperties.getMonitor().getPeriod());
return listener;
}
@Bean
@ConditionalOnMissingBean
public ApplicationEventJournal applicationEventJournal(
JournaledEventStore journaledEventStore) {
return new ApplicationEventJournal(journaledEventStore);
}
@Bean
@ConditionalOnMissingBean
public JournaledEventStore journaledEventStore() {
return new SimpleJournaledEventStore();
}
@Bean
@ConditionalOnMissingBean
public ApplicationStore applicationStore() {
return new SimpleApplicationStore();
}
}
...@@ -30,6 +30,7 @@ public class AdminServerImportSelector implements DeferredImportSelector { ...@@ -30,6 +30,7 @@ public class AdminServerImportSelector implements DeferredImportSelector {
public String[] selectImports(AnnotationMetadata importingClassMetadata) { public String[] selectImports(AnnotationMetadata importingClassMetadata) {
return new String[] { NotifierConfiguration.class.getCanonicalName(), return new String[] { NotifierConfiguration.class.getCanonicalName(),
HazelcastStoreConfiguration.class.getCanonicalName(), HazelcastStoreConfiguration.class.getCanonicalName(),
AdminServerCoreConfiguration.class.getCanonicalName(),
AdminServerWebConfiguration.class.getCanonicalName(), AdminServerWebConfiguration.class.getCanonicalName(),
DiscoveryClientConfiguration.class.getCanonicalName(), DiscoveryClientConfiguration.class.getCanonicalName(),
RevereseZuulProxyConfiguration.class.getCanonicalName() }; RevereseZuulProxyConfiguration.class.getCanonicalName() };
......
...@@ -63,7 +63,8 @@ public class AdminServerWebConfigurationTest { ...@@ -63,7 +63,8 @@ public class AdminServerWebConfigurationTest {
@Test @Test
public void jacksonMapperPresentFromDefault() { public void jacksonMapperPresentFromDefault() {
AdminServerWebConfiguration config = new AdminServerWebConfiguration(); AdminServerWebConfiguration config = new AdminServerWebConfiguration(null, null, null,
null);
List<HttpMessageConverter<?>> converters = new ArrayList<>(); List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter()); converters.add(new MappingJackson2HttpMessageConverter());
...@@ -76,7 +77,8 @@ public class AdminServerWebConfigurationTest { ...@@ -76,7 +77,8 @@ public class AdminServerWebConfigurationTest {
@Test @Test
public void jacksonMapperPresentNeedExtend() { public void jacksonMapperPresentNeedExtend() {
AdminServerWebConfiguration config = new AdminServerWebConfiguration(); AdminServerWebConfiguration config = new AdminServerWebConfiguration(null, null, null,
null);
List<HttpMessageConverter<?>> converters = new ArrayList<>(); List<HttpMessageConverter<?>> converters = new ArrayList<>();
config.extendMessageConverters(converters); config.extendMessageConverters(converters);
...@@ -137,6 +139,7 @@ public class AdminServerWebConfigurationTest { ...@@ -137,6 +139,7 @@ public class AdminServerWebConfigurationTest {
applicationContext.register(HazelcastAutoConfiguration.class); applicationContext.register(HazelcastAutoConfiguration.class);
applicationContext.register(HazelcastStoreConfiguration.class); applicationContext.register(HazelcastStoreConfiguration.class);
applicationContext.register(DiscoveryClientConfiguration.class); applicationContext.register(DiscoveryClientConfiguration.class);
applicationContext.register(AdminServerCoreConfiguration.class);
applicationContext.register(AdminServerWebConfiguration.class); applicationContext.register(AdminServerWebConfiguration.class);
EnvironmentTestUtils.addEnvironment(applicationContext, environment); EnvironmentTestUtils.addEnvironment(applicationContext, environment);
......
...@@ -94,6 +94,7 @@ public class DiscoveryClientConfigurationTest { ...@@ -94,6 +94,7 @@ public class DiscoveryClientConfigurationTest {
applicationContext.register(PropertyPlaceholderAutoConfiguration.class); applicationContext.register(PropertyPlaceholderAutoConfiguration.class);
applicationContext.register(RestTemplateConfiguration.class); applicationContext.register(RestTemplateConfiguration.class);
applicationContext.register(ServerPropertiesAutoConfiguration.class); applicationContext.register(ServerPropertiesAutoConfiguration.class);
applicationContext.register(AdminServerCoreConfiguration.class);
applicationContext.register(AdminServerWebConfiguration.class); applicationContext.register(AdminServerWebConfiguration.class);
applicationContext.register(DiscoveryClientConfiguration.class); applicationContext.register(DiscoveryClientConfiguration.class);
......
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