Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
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
DEMO
spring-boot
Commits
0d04d7ad
Commit
0d04d7ad
authored
Aug 10, 2018
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate @EventListener to ApplicationListener
Closes gh-14041
parent
9d40df9a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
22 deletions
+80
-22
LocalDevToolsAutoConfiguration.java
...evtools/autoconfigure/LocalDevToolsAutoConfiguration.java
+36
-11
RemoteClientConfiguration.java
...oot/devtools/remote/client/RemoteClientConfiguration.java
+5
-4
SpringApplicationAdminMXBeanRegistrar.java
...ork/boot/admin/SpringApplicationAdminMXBeanRegistrar.java
+39
-7
No files found.
spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java
View file @
0d04d7ad
...
@@ -35,10 +35,14 @@ import org.springframework.boot.devtools.livereload.LiveReloadServer;
...
@@ -35,10 +35,14 @@ import org.springframework.boot.devtools.livereload.LiveReloadServer;
import
org.springframework.boot.devtools.restart.ConditionalOnInitializedRestarter
;
import
org.springframework.boot.devtools.restart.ConditionalOnInitializedRestarter
;
import
org.springframework.boot.devtools.restart.RestartScope
;
import
org.springframework.boot.devtools.restart.RestartScope
;
import
org.springframework.boot.devtools.restart.Restarter
;
import
org.springframework.boot.devtools.restart.Restarter
;
import
org.springframework.context.ApplicationEvent
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.context.event.EventListener
;
import
org.springframework.context.event.GenericApplicationListener
;
import
org.springframework.core.ResolvableType
;
import
org.springframework.lang.Nullable
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
/**
/**
...
@@ -94,7 +98,8 @@ public class LocalDevToolsAutoConfiguration {
...
@@ -94,7 +98,8 @@ public class LocalDevToolsAutoConfiguration {
*/
*/
@Configuration
@Configuration
@ConditionalOnProperty
(
prefix
=
"spring.devtools.restart"
,
name
=
"enabled"
,
matchIfMissing
=
true
)
@ConditionalOnProperty
(
prefix
=
"spring.devtools.restart"
,
name
=
"enabled"
,
matchIfMissing
=
true
)
static
class
RestartConfiguration
{
static
class
RestartConfiguration
implements
ApplicationListener
<
ClassPathChangedEvent
>
{
private
final
DevToolsProperties
properties
;
private
final
DevToolsProperties
properties
;
...
@@ -102,8 +107,8 @@ public class LocalDevToolsAutoConfiguration {
...
@@ -102,8 +107,8 @@ public class LocalDevToolsAutoConfiguration {
this
.
properties
=
properties
;
this
.
properties
=
properties
;
}
}
@
EventListener
@
Override
public
void
on
ClassPathChanged
(
ClassPathChangedEvent
event
)
{
public
void
on
ApplicationEvent
(
ClassPathChangedEvent
event
)
{
if
(
event
.
isRestartRequired
())
{
if
(
event
.
isRestartRequired
())
{
Restarter
.
getInstance
().
restart
(
Restarter
.
getInstance
().
restart
(
new
FileWatchingFailureHandler
(
fileSystemWatcherFactory
()));
new
FileWatchingFailureHandler
(
fileSystemWatcherFactory
()));
...
@@ -161,7 +166,7 @@ public class LocalDevToolsAutoConfiguration {
...
@@ -161,7 +166,7 @@ public class LocalDevToolsAutoConfiguration {
}
}
static
class
LiveReloadServerEventListener
{
static
class
LiveReloadServerEventListener
implements
GenericApplicationListener
{
private
final
OptionalLiveReloadServer
liveReloadServer
;
private
final
OptionalLiveReloadServer
liveReloadServer
;
...
@@ -169,16 +174,36 @@ public class LocalDevToolsAutoConfiguration {
...
@@ -169,16 +174,36 @@ public class LocalDevToolsAutoConfiguration {
this
.
liveReloadServer
=
liveReloadServer
;
this
.
liveReloadServer
=
liveReloadServer
;
}
}
@EventListener
@Override
public
void
onContextRefreshed
(
ContextRefreshedEvent
event
)
{
public
boolean
supportsEventType
(
ResolvableType
eventType
)
{
this
.
liveReloadServer
.
triggerReload
();
Class
<?>
type
=
eventType
.
getRawClass
();
if
(
type
==
null
)
{
return
false
;
}
return
ContextRefreshedEvent
.
class
.
isAssignableFrom
(
type
)
||
ClassPathChangedEvent
.
class
.
isAssignableFrom
(
type
);
}
@Override
public
boolean
supportsSourceType
(
@Nullable
Class
<?>
sourceType
)
{
return
true
;
}
}
@
EventListener
@
Override
public
void
on
ClassPathChanged
(
ClassPathChanged
Event
event
)
{
public
void
on
ApplicationEvent
(
Application
Event
event
)
{
if
(
!
event
.
isRestartRequired
()
)
{
if
(
event
instanceof
ContextRefreshedEvent
)
{
this
.
liveReloadServer
.
triggerReload
();
this
.
liveReloadServer
.
triggerReload
();
}
}
if
(
event
instanceof
ClassPathChangedEvent
)
{
if
(!((
ClassPathChangedEvent
)
event
).
isRestartRequired
())
{
this
.
liveReloadServer
.
triggerReload
();
}
}
}
@Override
public
int
getOrder
()
{
return
0
;
}
}
}
}
...
...
spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/RemoteClientConfiguration.java
View file @
0d04d7ad
...
@@ -49,9 +49,9 @@ import org.springframework.boot.devtools.livereload.LiveReloadServer;
...
@@ -49,9 +49,9 @@ import org.springframework.boot.devtools.livereload.LiveReloadServer;
import
org.springframework.boot.devtools.restart.DefaultRestartInitializer
;
import
org.springframework.boot.devtools.restart.DefaultRestartInitializer
;
import
org.springframework.boot.devtools.restart.RestartScope
;
import
org.springframework.boot.devtools.restart.RestartScope
;
import
org.springframework.boot.devtools.restart.Restarter
;
import
org.springframework.boot.devtools.restart.Restarter
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.event.EventListener
;
import
org.springframework.context.support.PropertySourcesPlaceholderConfigurer
;
import
org.springframework.context.support.PropertySourcesPlaceholderConfigurer
;
import
org.springframework.http.client.ClientHttpRequestFactory
;
import
org.springframework.http.client.ClientHttpRequestFactory
;
import
org.springframework.http.client.ClientHttpRequestInterceptor
;
import
org.springframework.http.client.ClientHttpRequestInterceptor
;
...
@@ -131,7 +131,8 @@ public class RemoteClientConfiguration implements InitializingBean {
...
@@ -131,7 +131,8 @@ public class RemoteClientConfiguration implements InitializingBean {
*/
*/
@Configuration
@Configuration
@ConditionalOnProperty
(
prefix
=
"spring.devtools.livereload"
,
name
=
"enabled"
,
matchIfMissing
=
true
)
@ConditionalOnProperty
(
prefix
=
"spring.devtools.livereload"
,
name
=
"enabled"
,
matchIfMissing
=
true
)
static
class
LiveReloadConfiguration
{
static
class
LiveReloadConfiguration
implements
ApplicationListener
<
ClassPathChangedEvent
>
{
@Autowired
@Autowired
private
DevToolsProperties
properties
;
private
DevToolsProperties
properties
;
...
@@ -155,8 +156,8 @@ public class RemoteClientConfiguration implements InitializingBean {
...
@@ -155,8 +156,8 @@ public class RemoteClientConfiguration implements InitializingBean {
Restarter
.
getInstance
().
getThreadFactory
());
Restarter
.
getInstance
().
getThreadFactory
());
}
}
@
EventListener
@
Override
public
void
on
ClassPathChanged
(
ClassPathChangedEvent
event
)
{
public
void
on
ApplicationEvent
(
ClassPathChangedEvent
event
)
{
String
url
=
this
.
remoteUrl
+
this
.
properties
.
getRemote
().
getContextPath
();
String
url
=
this
.
remoteUrl
+
this
.
properties
.
getRemote
().
getContextPath
();
this
.
executor
.
execute
(
new
DelayedLiveReloadTrigger
(
optionalLiveReloadServer
(),
this
.
executor
.
execute
(
new
DelayedLiveReloadTrigger
(
optionalLiveReloadServer
(),
this
.
clientHttpRequestFactory
,
url
));
this
.
clientHttpRequestFactory
,
url
));
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/admin/SpringApplicationAdminMXBeanRegistrar.java
View file @
0d04d7ad
/*
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -32,11 +32,15 @@ import org.springframework.boot.context.event.ApplicationReadyEvent;
...
@@ -32,11 +32,15 @@ import org.springframework.boot.context.event.ApplicationReadyEvent;
import
org.springframework.boot.web.context.WebServerInitializedEvent
;
import
org.springframework.boot.web.context.WebServerInitializedEvent
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.context.ApplicationEvent
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.EnvironmentAware
;
import
org.springframework.context.EnvironmentAware
;
import
org.springframework.context.event.EventListener
;
import
org.springframework.context.event.GenericApplicationListener
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.ResolvableType
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.lang.Nullable
;
import
org.springframework.util.Assert
;
import
org.springframework.util.Assert
;
/**
/**
...
@@ -48,7 +52,7 @@ import org.springframework.util.Assert;
...
@@ -48,7 +52,7 @@ import org.springframework.util.Assert;
* @since 1.3.0
* @since 1.3.0
*/
*/
public
class
SpringApplicationAdminMXBeanRegistrar
implements
ApplicationContextAware
,
public
class
SpringApplicationAdminMXBeanRegistrar
implements
ApplicationContextAware
,
EnvironmentAware
,
InitializingBean
,
DisposableBean
{
GenericApplicationListener
,
EnvironmentAware
,
InitializingBean
,
DisposableBean
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
SpringApplicationAdmin
.
class
);
private
static
final
Log
logger
=
LogFactory
.
getLog
(
SpringApplicationAdmin
.
class
);
...
@@ -80,15 +84,43 @@ public class SpringApplicationAdminMXBeanRegistrar implements ApplicationContext
...
@@ -80,15 +84,43 @@ public class SpringApplicationAdminMXBeanRegistrar implements ApplicationContext
this
.
environment
=
environment
;
this
.
environment
=
environment
;
}
}
@EventListener
@Override
public
void
onApplicationReadyEvent
(
ApplicationReadyEvent
event
)
{
public
boolean
supportsEventType
(
ResolvableType
eventType
)
{
Class
<?>
type
=
eventType
.
getRawClass
();
if
(
type
==
null
)
{
return
false
;
}
return
ApplicationReadyEvent
.
class
.
isAssignableFrom
(
type
)
||
WebServerInitializedEvent
.
class
.
isAssignableFrom
(
type
);
}
@Override
public
boolean
supportsSourceType
(
@Nullable
Class
<?>
sourceType
)
{
return
true
;
}
@Override
public
void
onApplicationEvent
(
ApplicationEvent
event
)
{
if
(
event
instanceof
ApplicationReadyEvent
)
{
onApplicationReadyEvent
((
ApplicationReadyEvent
)
event
);
}
if
(
event
instanceof
WebServerInitializedEvent
)
{
onWebServerInitializedEvent
((
WebServerInitializedEvent
)
event
);
}
}
@Override
public
int
getOrder
()
{
return
Ordered
.
HIGHEST_PRECEDENCE
;
}
void
onApplicationReadyEvent
(
ApplicationReadyEvent
event
)
{
if
(
this
.
applicationContext
.
equals
(
event
.
getApplicationContext
()))
{
if
(
this
.
applicationContext
.
equals
(
event
.
getApplicationContext
()))
{
this
.
ready
=
true
;
this
.
ready
=
true
;
}
}
}
}
@EventListener
void
onWebServerInitializedEvent
(
WebServerInitializedEvent
event
)
{
public
void
onWebServerInitializedEvent
(
WebServerInitializedEvent
event
)
{
if
(
this
.
applicationContext
.
equals
(
event
.
getApplicationContext
()))
{
if
(
this
.
applicationContext
.
equals
(
event
.
getApplicationContext
()))
{
this
.
embeddedWebApplication
=
true
;
this
.
embeddedWebApplication
=
true
;
}
}
...
...
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