Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-boot-admin
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-boot-admin
Commits
fef76a64
Commit
fef76a64
authored
Dec 24, 2016
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract core- from web-config
parent
d49f16a0
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
162 additions
and
133 deletions
+162
-133
TurbineAutoConfigurationTest.java
...ot/admin/turbine/config/TurbineAutoConfigurationTest.java
+2
-0
AdminServerCoreConfiguration.java
...ntric/boot/admin/config/AdminServerCoreConfiguration.java
+130
-0
AdminServerImportSelector.java
...ecentric/boot/admin/config/AdminServerImportSelector.java
+1
-0
AdminServerWebConfiguration.java
...entric/boot/admin/config/AdminServerWebConfiguration.java
+23
-131
AdminServerWebConfigurationTest.java
...ic/boot/admin/config/AdminServerWebConfigurationTest.java
+5
-2
DiscoveryClientConfigurationTest.java
...c/boot/admin/config/DiscoveryClientConfigurationTest.java
+1
-0
No files found.
spring-boot-admin-server-ui-turbine/src/test/java/spring/boot/admin/turbine/config/TurbineAutoConfigurationTest.java
View file @
fef76a64
...
...
@@ -12,6 +12,7 @@ import org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration.Res
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
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.RevereseZuulProxyConfiguration
;
import
spring.boot.admin.turbine.web.TurbineController
;
...
...
@@ -51,6 +52,7 @@ public class TurbineAutoConfigurationTest {
applicationContext
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
);
applicationContext
.
register
(
RestTemplateConfiguration
.
class
);
applicationContext
.
register
(
ServerPropertiesAutoConfiguration
.
class
);
applicationContext
.
register
(
AdminServerCoreConfiguration
.
class
);
applicationContext
.
register
(
AdminServerWebConfiguration
.
class
);
applicationContext
.
register
(
RevereseZuulProxyConfiguration
.
class
);
applicationContext
.
register
(
TurbineAutoConfiguration
.
class
);
...
...
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/config/AdminServerCoreConfiguration.java
0 → 100644
View file @
fef76a64
/*
* 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
();
}
}
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/config/AdminServerImportSelector.java
View file @
fef76a64
...
...
@@ -30,6 +30,7 @@ public class AdminServerImportSelector implements DeferredImportSelector {
public
String
[]
selectImports
(
AnnotationMetadata
importingClassMetadata
)
{
return
new
String
[]
{
NotifierConfiguration
.
class
.
getCanonicalName
(),
HazelcastStoreConfiguration
.
class
.
getCanonicalName
(),
AdminServerCoreConfiguration
.
class
.
getCanonicalName
(),
AdminServerWebConfiguration
.
class
.
getCanonicalName
(),
DiscoveryClientConfiguration
.
class
.
getCanonicalName
(),
RevereseZuulProxyConfiguration
.
class
.
getCanonicalName
()
};
...
...
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/config/AdminServerWebConfiguration.java
View file @
fef76a64
...
...
@@ -18,12 +18,8 @@ package de.codecentric.boot.admin.config;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.web.ServerProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.context.ApplicationEventPublisher
;
...
...
@@ -31,14 +27,10 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.event.EventListener
;
import
org.springframework.core.io.support.ResourcePatternResolver
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
org.springframework.scheduling.TaskScheduler
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.client.DefaultResponseErrorHandler
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.ViewControllerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
...
...
@@ -49,51 +41,31 @@ import de.codecentric.boot.admin.event.ClientApplicationDeregisteredEvent;
import
de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent
;
import
de.codecentric.boot.admin.event.RoutesOutdatedEvent
;
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.journal.web.JournalController
;
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.registry.web.RegistryController
;
import
de.codecentric.boot.admin.web.AdminController
;
import
de.codecentric.boot.admin.web.PrefixHandlerMapping
;
import
de.codecentric.boot.admin.web.client.BasicAuthHttpHeaderProvider
;
import
de.codecentric.boot.admin.web.client.HttpHeadersProvider
;
import
de.codecentric.boot.admin.web.servlet.resource.ConcatenatingResourceResolver
;
import
de.codecentric.boot.admin.web.servlet.resource.PreferMinifiedFilteringResourceResolver
;
import
de.codecentric.boot.admin.web.servlet.resource.ResourcePatternResolvingResourceResolver
;
@Configuration
@EnableConfigurationProperties
public
class
AdminServerWebConfiguration
extends
WebMvcConfigurerAdapter
implements
ApplicationContextAware
{
private
final
ApplicationEventPublisher
publisher
;
private
final
ServerProperties
server
;
private
final
ResourcePatternResolver
resourcePatternResolver
;
private
final
AdminServerProperties
adminServerProperties
;
private
ApplicationContext
applicationContext
;
@Autowired
private
ApplicationEventPublisher
publisher
;
@Autowired
private
ApplicationStore
applicationStore
;
@Autowired
private
ServerProperties
server
;
@Autowired
private
ResourcePatternResolver
resourcePatternResolver
;
@Autowired
private
RestTemplateBuilder
restTemplBuilder
;
@Bean
@ConditionalOnMissingBean
public
AdminServerProperties
adminServerProperties
()
{
return
new
AdminServerProperties
();
public
AdminServerWebConfiguration
(
ApplicationEventPublisher
publisher
,
ServerProperties
server
,
ResourcePatternResolver
resourcePatternResolver
,
AdminServerProperties
adminServerProperties
)
{
this
.
publisher
=
publisher
;
this
.
server
=
server
;
this
.
resourcePatternResolver
=
resourcePatternResolver
;
this
.
adminServerProperties
=
adminServerProperties
;
}
@Override
...
...
@@ -122,18 +94,18 @@ public class AdminServerWebConfiguration extends WebMvcConfigurerAdapter
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
registry
.
addResourceHandler
(
adminServerProperties
()
.
getContextPath
()
+
"/**"
)
registry
.
addResourceHandler
(
adminServerProperties
.
getContextPath
()
+
"/**"
)
.
addResourceLocations
(
"classpath:/META-INF/spring-boot-admin-server-ui/"
)
.
resourceChain
(
true
)
.
addResolver
(
new
PreferMinifiedFilteringResourceResolver
(
".min"
));
registry
.
addResourceHandler
(
adminServerProperties
()
.
getContextPath
()
+
"/all-modules.css"
)
registry
.
addResourceHandler
(
adminServerProperties
.
getContextPath
()
+
"/all-modules.css"
)
.
resourceChain
(
true
)
.
addResolver
(
new
ResourcePatternResolvingResourceResolver
(
resourcePatternResolver
,
"classpath*:/META-INF/spring-boot-admin-server-ui/*/module.css"
))
.
addResolver
(
new
ConcatenatingResourceResolver
(
"\n"
.
getBytes
()));
registry
.
addResourceHandler
(
adminServerProperties
()
.
getContextPath
()
+
"/all-modules.js"
)
registry
.
addResourceHandler
(
adminServerProperties
.
getContextPath
()
+
"/all-modules.js"
)
.
resourceChain
(
true
)
.
addResolver
(
new
ResourcePatternResolvingResourceResolver
(
resourcePatternResolver
,
"classpath*:/META-INF/spring-boot-admin-server-ui/*/module.js"
))
...
...
@@ -143,12 +115,11 @@ public class AdminServerWebConfiguration extends WebMvcConfigurerAdapter
@Override
public
void
addViewControllers
(
ViewControllerRegistry
registry
)
{
if
(
StringUtils
.
hasText
(
adminServerProperties
().
getContextPath
()))
{
registry
.
addRedirectViewController
(
adminServerProperties
().
getContextPath
(),
server
.
getPath
(
adminServerProperties
().
getContextPath
()
)
+
"/"
);
String
contextPath
=
adminServerProperties
.
getContextPath
();
if
(
StringUtils
.
hasText
(
contextPath
))
{
registry
.
addRedirectViewController
(
contextPath
,
server
.
getPath
(
contextPath
)
+
"/"
);
}
registry
.
addViewController
(
adminServerProperties
().
getContextPath
()
+
"/"
)
.
setViewName
(
"forward:index.html"
);
registry
.
addViewController
(
contextPath
+
"/"
).
setViewName
(
"forward:index.html"
);
}
@Bean
...
...
@@ -157,75 +128,20 @@ public class AdminServerWebConfiguration extends WebMvcConfigurerAdapter
.
getBeansWithAnnotation
(
AdminController
.
class
);
PrefixHandlerMapping
prefixHandlerMapping
=
new
PrefixHandlerMapping
(
beans
.
values
().
toArray
(
new
Object
[
beans
.
size
()]));
prefixHandlerMapping
.
setPrefix
(
adminServerProperties
()
.
getContextPath
());
prefixHandlerMapping
.
setPrefix
(
adminServerProperties
.
getContextPath
());
return
prefixHandlerMapping
;
}
/**
* @return Controller with REST-API for spring-boot applications to register itself.
*/
@Bean
public
RegistryController
registryController
()
{
return
new
RegistryController
(
applicationRegistry
());
}
/**
* @return Default registry for all registered application.
*/
@Bean
public
ApplicationRegistry
applicationRegistry
()
{
return
new
ApplicationRegistry
(
applicationStore
,
applicationIdGenerator
());
}
/**
* @return Default applicationId Generator
*/
@Bean
@ConditionalOnMissingBean
public
ApplicationIdGenerator
applicationIdGenerator
()
{
return
new
HashingApplicationUrlIdGenerator
();
}
@Bean
@ConditionalOnMissingBean
public
HttpHeadersProvider
httpHeadersProvider
(
)
{
return
new
BasicAuthHttpHeaderProvider
(
);
public
RegistryController
registryController
(
ApplicationRegistry
applicationRegistry
)
{
return
new
RegistryController
(
applicationRegistry
);
}
@Bean
@ConditionalOnMissingBean
public
StatusUpdater
statusUpdater
()
{
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
public
StatusUpdateApplicationListener
statusUpdateApplicationListener
()
{
StatusUpdateApplicationListener
listener
=
new
StatusUpdateApplicationListener
(
statusUpdater
(),
updateTaskScheduler
());
listener
.
setUpdatePeriod
(
adminServerProperties
().
getMonitor
().
getPeriod
());
return
listener
;
public
JournalController
journalController
(
ApplicationEventJournal
applicationEventJournal
)
{
return
new
JournalController
(
applicationEventJournal
);
}
@EventListener
...
...
@@ -238,28 +154,4 @@ public class AdminServerWebConfiguration extends WebMvcConfigurerAdapter
publisher
.
publishEvent
(
new
RoutesOutdatedEvent
());
}
@Bean
@ConditionalOnMissingBean
public
ApplicationEventJournal
applicationEventJournal
()
{
return
new
ApplicationEventJournal
(
journaledEventStore
());
}
@Bean
@ConditionalOnMissingBean
public
JournaledEventStore
journaledEventStore
()
{
return
new
SimpleJournaledEventStore
();
}
@Bean
@ConditionalOnMissingBean
public
JournalController
journalController
()
{
return
new
JournalController
(
applicationEventJournal
());
}
@Bean
@ConditionalOnMissingBean
public
ApplicationStore
applicationStore
()
{
return
new
SimpleApplicationStore
();
}
}
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/config/AdminServerWebConfigurationTest.java
View file @
fef76a64
...
...
@@ -63,7 +63,8 @@ public class AdminServerWebConfigurationTest {
@Test
public
void
jacksonMapperPresentFromDefault
()
{
AdminServerWebConfiguration
config
=
new
AdminServerWebConfiguration
();
AdminServerWebConfiguration
config
=
new
AdminServerWebConfiguration
(
null
,
null
,
null
,
null
);
List
<
HttpMessageConverter
<?>>
converters
=
new
ArrayList
<>();
converters
.
add
(
new
MappingJackson2HttpMessageConverter
());
...
...
@@ -76,7 +77,8 @@ public class AdminServerWebConfigurationTest {
@Test
public
void
jacksonMapperPresentNeedExtend
()
{
AdminServerWebConfiguration
config
=
new
AdminServerWebConfiguration
();
AdminServerWebConfiguration
config
=
new
AdminServerWebConfiguration
(
null
,
null
,
null
,
null
);
List
<
HttpMessageConverter
<?>>
converters
=
new
ArrayList
<>();
config
.
extendMessageConverters
(
converters
);
...
...
@@ -137,6 +139,7 @@ public class AdminServerWebConfigurationTest {
applicationContext
.
register
(
HazelcastAutoConfiguration
.
class
);
applicationContext
.
register
(
HazelcastStoreConfiguration
.
class
);
applicationContext
.
register
(
DiscoveryClientConfiguration
.
class
);
applicationContext
.
register
(
AdminServerCoreConfiguration
.
class
);
applicationContext
.
register
(
AdminServerWebConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
applicationContext
,
environment
);
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/config/DiscoveryClientConfigurationTest.java
View file @
fef76a64
...
...
@@ -94,6 +94,7 @@ public class DiscoveryClientConfigurationTest {
applicationContext
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
);
applicationContext
.
register
(
RestTemplateConfiguration
.
class
);
applicationContext
.
register
(
ServerPropertiesAutoConfiguration
.
class
);
applicationContext
.
register
(
AdminServerCoreConfiguration
.
class
);
applicationContext
.
register
(
AdminServerWebConfiguration
.
class
);
applicationContext
.
register
(
DiscoveryClientConfiguration
.
class
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment