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
7b0ba350
Commit
7b0ba350
authored
May 28, 2021
by
Jamin Hitchcock
Committed by
Stephane Nicoll
Jun 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow SpringApplicationBuilder to specify a ResourceLoader
See gh-26690
parent
41e00e11
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
1 deletion
+32
-1
SpringApplicationBuilder.java
...pringframework/boot/builder/SpringApplicationBuilder.java
+22
-1
SpringApplicationBuilderTests.java
...framework/boot/builder/SpringApplicationBuilderTests.java
+10
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java
View file @
7b0ba350
...
@@ -94,7 +94,11 @@ public class SpringApplicationBuilder {
...
@@ -94,7 +94,11 @@ public class SpringApplicationBuilder {
private
boolean
configuredAsChild
=
false
;
private
boolean
configuredAsChild
=
false
;
public
SpringApplicationBuilder
(
Class
<?>...
sources
)
{
public
SpringApplicationBuilder
(
Class
<?>...
sources
)
{
this
.
application
=
createSpringApplication
(
sources
);
this
.
application
=
createSpringApplication
(
null
,
sources
);
}
public
SpringApplicationBuilder
(
ResourceLoader
resourceLoader
,
Class
<?>...
sources
)
{
this
.
application
=
createSpringApplication
(
resourceLoader
,
sources
);
}
}
/**
/**
...
@@ -104,11 +108,28 @@ public class SpringApplicationBuilder {
...
@@ -104,11 +108,28 @@ public class SpringApplicationBuilder {
* @param sources the sources
* @param sources the sources
* @return the {@link org.springframework.boot.SpringApplication} instance
* @return the {@link org.springframework.boot.SpringApplication} instance
* @since 1.1.0
* @since 1.1.0
* @deprecated Use {@link #createSpringApplication(ResourceLoader, Class...)} with
* null resource loader
*/
*/
protected
SpringApplication
createSpringApplication
(
Class
<?>...
sources
)
{
protected
SpringApplication
createSpringApplication
(
Class
<?>...
sources
)
{
return
new
SpringApplication
(
sources
);
return
new
SpringApplication
(
sources
);
}
}
/**
* Creates a new {@link org.springframework.boot.SpringApplication} instances from the
* given sources. Subclasses may override in order to provide a custom subclass of
* {@link org.springframework.boot.SpringApplication}
* @param resourceLoader the resource loader, can be null to use default resource
* loader (see
* {@link org.springframework.boot.SpringApplication#SpringApplication(ResourceLoader, Class...)})
* @param sources the sources
* @return the {@link org.springframework.boot.SpringApplication} instance
* @since 2.5.0
*/
protected
SpringApplication
createSpringApplication
(
ResourceLoader
resourceLoader
,
Class
<?>...
sources
)
{
return
new
SpringApplication
(
resourceLoader
,
sources
);
}
/**
/**
* Accessor for the current application context.
* Accessor for the current application context.
* @return the current application context (or null if not yet running)
* @return the current application context (or null if not yet running)
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java
View file @
7b0ba350
...
@@ -309,6 +309,16 @@ class SpringApplicationBuilderTests {
...
@@ -309,6 +309,16 @@ class SpringApplicationBuilderTests {
assertThat
(
builder
.
application
().
getEnvironmentPrefix
()).
isEqualTo
(
"test"
);
assertThat
(
builder
.
application
().
getEnvironmentPrefix
()).
isEqualTo
(
"test"
);
}
}
@Test
void
createWithResourceLoader
()
{
ClassLoader
classLoader
=
new
URLClassLoader
(
new
URL
[
0
],
getClass
().
getClassLoader
());
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
new
DefaultResourceLoader
(
classLoader
),
ExampleConfig
.
class
)
.
contextFactory
(
ApplicationContextFactory
.
ofContextClass
(
SpyApplicationContext
.
class
));
this
.
context
=
application
.
run
();
assertThat
(
this
.
context
.
getClassLoader
()).
isEqualTo
(
classLoader
);
}
@Configuration
(
proxyBeanMethods
=
false
)
@Configuration
(
proxyBeanMethods
=
false
)
static
class
ExampleConfig
{
static
class
ExampleConfig
{
...
...
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