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
ec470fbe
Commit
ec470fbe
authored
Oct 30, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Call Application and CommandLine Runners after ready event
Closes gh-7656
parent
27f550b8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
1 deletion
+46
-1
SpringApplication.java
...main/java/org/springframework/boot/SpringApplication.java
+1
-1
SpringApplicationTests.java
...java/org/springframework/boot/SpringApplicationTests.java
+45
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java
View file @
ec470fbe
...
...
@@ -332,6 +332,7 @@ public class SpringApplication {
new
StartupInfoLogger
(
this
.
mainApplicationClass
)
.
logStarted
(
getApplicationLog
(),
stopWatch
);
}
callRunners
(
context
,
applicationArguments
);
return
context
;
}
catch
(
Throwable
ex
)
{
...
...
@@ -757,7 +758,6 @@ public class SpringApplication {
*/
protected
void
afterRefresh
(
ConfigurableApplicationContext
context
,
ApplicationArguments
args
)
{
callRunners
(
context
,
args
);
}
private
void
callRunners
(
ApplicationContext
context
,
ApplicationArguments
args
)
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java
View file @
ec470fbe
...
...
@@ -38,6 +38,9 @@ import org.junit.Rule;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentMatchers
;
import
org.mockito.InOrder
;
import
org.mockito.Mockito
;
import
reactor.core.publisher.Mono
;
import
org.springframework.beans.BeansException
;
...
...
@@ -582,6 +585,33 @@ public class SpringApplicationTests {
assertThat
(
this
.
context
).
has
(
runTestRunnerBean
(
"runnerC"
));
}
@Test
@SuppressWarnings
(
"unchecked"
)
public
void
runnersAreCalledAfterApplicationReadyEventIsPublished
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
MockRunnerConfiguration
.
class
);
application
.
setWebApplicationType
(
WebApplicationType
.
NONE
);
ApplicationListener
<
ApplicationReadyEvent
>
eventListener
=
mock
(
ApplicationListener
.
class
);
application
.
addListeners
(
eventListener
);
this
.
context
=
application
.
run
();
ApplicationRunner
applicationRunner
=
this
.
context
.
getBean
(
ApplicationRunner
.
class
);
CommandLineRunner
commandLineRunner
=
this
.
context
.
getBean
(
CommandLineRunner
.
class
);
InOrder
applicationRunnerOrder
=
Mockito
.
inOrder
(
eventListener
,
applicationRunner
);
applicationRunnerOrder
.
verify
(
eventListener
)
.
onApplicationEvent
(
ArgumentMatchers
.
any
(
ApplicationReadyEvent
.
class
));
applicationRunnerOrder
.
verify
(
applicationRunner
)
.
run
(
ArgumentMatchers
.
any
(
ApplicationArguments
.
class
));
InOrder
commandLineRunnerOrder
=
Mockito
.
inOrder
(
eventListener
,
commandLineRunner
);
commandLineRunnerOrder
.
verify
(
eventListener
)
.
onApplicationEvent
(
ArgumentMatchers
.
any
(
ApplicationReadyEvent
.
class
));
commandLineRunnerOrder
.
verify
(
commandLineRunner
).
run
();
}
@Test
public
void
loadSources
()
throws
Exception
{
Class
<?>[]
sources
=
{
ExampleConfig
.
class
,
TestCommandLineRunner
.
class
};
...
...
@@ -1217,6 +1247,21 @@ public class SpringApplicationTests {
}
@Configuration
static
class
MockRunnerConfiguration
{
@Bean
public
CommandLineRunner
commandLineRunner
()
{
return
mock
(
CommandLineRunner
.
class
);
}
@Bean
public
ApplicationRunner
applicationRunner
()
{
return
mock
(
ApplicationRunner
.
class
);
}
}
static
class
ExitStatusException
extends
RuntimeException
implements
ExitCodeGenerator
{
...
...
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