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
97cb7f09
Commit
97cb7f09
authored
Oct 23, 2013
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure ClassLoader is set in BeanFactory
parent
04986174
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
4 deletions
+53
-4
SpringApplication.java
...main/java/org/springframework/boot/SpringApplication.java
+10
-2
SpringApplicationBuilderTests.java
...framework/boot/builder/SpringApplicationBuilderTests.java
+43
-2
No files found.
spring-boot/src/main/java/org/springframework/boot/SpringApplication.java
View file @
97cb7f09
...
...
@@ -53,6 +53,7 @@ import org.springframework.core.env.MapPropertySource;
import
org.springframework.core.env.PropertySource
;
import
org.springframework.core.env.SimpleCommandLinePropertySource
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.core.io.DefaultResourceLoader
;
import
org.springframework.core.io.Resource
;
import
org.springframework.core.io.ResourceLoader
;
import
org.springframework.core.io.support.SpringFactoriesLoader
;
...
...
@@ -442,8 +443,15 @@ public class SpringApplication {
}
}
if
(
context
instanceof
GenericApplicationContext
&&
this
.
resourceLoader
!=
null
)
{
((
GenericApplicationContext
)
context
).
setResourceLoader
(
this
.
resourceLoader
);
if
(
this
.
resourceLoader
!=
null
)
{
if
(
context
instanceof
GenericApplicationContext
)
{
((
GenericApplicationContext
)
context
)
.
setResourceLoader
(
this
.
resourceLoader
);
}
if
(
context
instanceof
DefaultResourceLoader
)
{
((
DefaultResourceLoader
)
context
).
setClassLoader
(
this
.
resourceLoader
.
getClassLoader
());
}
}
}
...
...
spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java
View file @
97cb7f09
...
...
@@ -16,6 +16,9 @@
package
org
.
springframework
.
boot
.
builder
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.springframework.context.ApplicationContext
;
...
...
@@ -23,6 +26,8 @@ import org.springframework.context.ConfigurableApplicationContext;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.support.StaticApplicationContext
;
import
org.springframework.core.io.DefaultResourceLoader
;
import
org.springframework.core.io.ResourceLoader
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
instanceOf
;
...
...
@@ -77,6 +82,31 @@ public class SpringApplicationBuilderTests {
any
(
ApplicationContext
.
class
));
}
@Test
public
void
contextWithClassLoader
()
throws
Exception
{
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
ExampleConfig
.
class
).
contextClass
(
SpyApplicationContext
.
class
);
ClassLoader
classLoader
=
new
URLClassLoader
(
new
URL
[
0
],
getClass
()
.
getClassLoader
());
application
.
resourceLoader
(
new
DefaultResourceLoader
(
classLoader
));
this
.
context
=
application
.
run
();
assertThat
(((
SpyApplicationContext
)
this
.
context
).
getClassLoader
(),
is
(
equalTo
(
classLoader
)));
}
@Test
public
void
parentContextWithClassLoader
()
throws
Exception
{
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
ChildConfig
.
class
).
contextClass
(
SpyApplicationContext
.
class
);
ClassLoader
classLoader
=
new
URLClassLoader
(
new
URL
[
0
],
getClass
()
.
getClassLoader
());
application
.
resourceLoader
(
new
DefaultResourceLoader
(
classLoader
));
application
.
parent
(
ExampleConfig
.
class
);
this
.
context
=
application
.
run
();
assertThat
(((
SpyApplicationContext
)
this
.
context
).
getResourceLoader
()
.
getClassLoader
(),
is
(
equalTo
(
classLoader
)));
}
@Test
public
void
parentFirstCreation
()
throws
Exception
{
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
...
...
@@ -127,7 +157,8 @@ public class SpringApplicationBuilderTests {
public
static
class
SpyApplicationContext
extends
AnnotationConfigApplicationContext
{
ConfigurableApplicationContext
applicationContext
=
spy
(
new
AnnotationConfigApplicationContext
());
private
ConfigurableApplicationContext
applicationContext
=
spy
(
new
AnnotationConfigApplicationContext
());
private
ResourceLoader
resourceLoader
;
@Override
public
void
setParent
(
ApplicationContext
parent
)
{
...
...
@@ -138,5 +169,15 @@ public class SpringApplicationBuilderTests {
return
this
.
applicationContext
;
}
@Override
public
void
setResourceLoader
(
ResourceLoader
resourceLoader
)
{
super
.
setResourceLoader
(
resourceLoader
);
this
.
resourceLoader
=
resourceLoader
;
}
public
ResourceLoader
getResourceLoader
()
{
return
this
.
resourceLoader
;
}
}
}
}
\ No newline at end of file
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