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
5c43a5b7
Commit
5c43a5b7
authored
Jun 15, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Honour custom bean name generator for non-web applications
Closes gh-6160
parent
ed2586d3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
10 deletions
+20
-10
SpringApplication.java
...main/java/org/springframework/boot/SpringApplication.java
+4
-10
SpringApplicationTests.java
...java/org/springframework/boot/SpringApplicationTests.java
+16
-0
No files found.
spring-boot/src/main/java/org/springframework/boot/SpringApplication.java
View file @
5c43a5b7
...
@@ -72,7 +72,6 @@ import org.springframework.util.ObjectUtils;
...
@@ -72,7 +72,6 @@ import org.springframework.util.ObjectUtils;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.util.StopWatch
;
import
org.springframework.util.StopWatch
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.context.ConfigurableWebApplicationContext
;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.context.support.StandardServletEnvironment
;
import
org.springframework.web.context.support.StandardServletEnvironment
;
...
@@ -603,15 +602,10 @@ public class SpringApplication {
...
@@ -603,15 +602,10 @@ public class SpringApplication {
* @param context the application context
* @param context the application context
*/
*/
protected
void
postProcessApplicationContext
(
ConfigurableApplicationContext
context
)
{
protected
void
postProcessApplicationContext
(
ConfigurableApplicationContext
context
)
{
if
(
this
.
webEnvironment
)
{
if
(
this
.
beanNameGenerator
!=
null
)
{
if
(
context
instanceof
ConfigurableWebApplicationContext
)
{
context
.
getBeanFactory
().
registerSingleton
(
ConfigurableWebApplicationContext
configurableContext
=
(
ConfigurableWebApplicationContext
)
context
;
AnnotationConfigUtils
.
CONFIGURATION_BEAN_NAME_GENERATOR
,
if
(
this
.
beanNameGenerator
!=
null
)
{
this
.
beanNameGenerator
);
configurableContext
.
getBeanFactory
().
registerSingleton
(
AnnotationConfigUtils
.
CONFIGURATION_BEAN_NAME_GENERATOR
,
this
.
beanNameGenerator
);
}
}
}
}
if
(
this
.
resourceLoader
!=
null
)
{
if
(
this
.
resourceLoader
!=
null
)
{
if
(
context
instanceof
GenericApplicationContext
)
{
if
(
context
instanceof
GenericApplicationContext
)
{
...
...
spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java
View file @
5c43a5b7
...
@@ -53,6 +53,7 @@ import org.springframework.context.ConfigurableApplicationContext;
...
@@ -53,6 +53,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigUtils
;
import
org.springframework.context.annotation.AnnotationConfigUtils
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
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.SimpleApplicationEventMulticaster
;
import
org.springframework.context.event.SimpleApplicationEventMulticaster
;
...
@@ -403,6 +404,21 @@ public class SpringApplicationTests {
...
@@ -403,6 +404,21 @@ public class SpringApplicationTests {
sameInstance
((
Object
)
beanNameGenerator
));
sameInstance
((
Object
)
beanNameGenerator
));
}
}
@Test
public
void
customBeanNameGeneratorWithNonWebApplication
()
throws
Exception
{
TestSpringApplication
application
=
new
TestSpringApplication
(
ExampleWebConfig
.
class
);
application
.
setWebEnvironment
(
false
);
BeanNameGenerator
beanNameGenerator
=
new
DefaultBeanNameGenerator
();
application
.
setBeanNameGenerator
(
beanNameGenerator
);
this
.
context
=
application
.
run
();
verify
(
application
.
getLoader
()).
setBeanNameGenerator
(
beanNameGenerator
);
assertThat
(
this
.
context
.
getBean
(
AnnotationConfigUtils
.
CONFIGURATION_BEAN_NAME_GENERATOR
),
sameInstance
((
Object
)
beanNameGenerator
));
}
@Test
@Test
public
void
commandLinePropertySource
()
throws
Exception
{
public
void
commandLinePropertySource
()
throws
Exception
{
SpringApplication
application
=
new
SpringApplication
(
ExampleConfig
.
class
);
SpringApplication
application
=
new
SpringApplication
(
ExampleConfig
.
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