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
29ba18af
Commit
29ba18af
authored
Mar 10, 2021
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.4.x'
Closes gh-25584 Fixes gh-25367 in 2.5.x
parents
4b0600b5
952ac7b8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
0 deletions
+56
-0
build.gradle
spring-boot-project/spring-boot-devtools/build.gradle
+1
-0
RestartClassLoader.java
...boot/devtools/restart/classloader/RestartClassLoader.java
+5
-0
RestartClassLoaderTests.java
...devtools/restart/classloader/RestartClassLoaderTests.java
+50
-0
No files found.
spring-boot-project/spring-boot-devtools/build.gradle
View file @
29ba18af
...
...
@@ -70,6 +70,7 @@ dependencies {
testImplementation
(
"org.thymeleaf:thymeleaf-spring5"
)
testImplementation
(
"nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect"
)
testRuntimeOnly
(
"org.aspectj:aspectjweaver"
)
testRuntimeOnly
(
"org.yaml:snakeyaml"
)
}
...
...
spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/classloader/RestartClassLoader.java
View file @
29ba18af
...
...
@@ -173,6 +173,11 @@ public class RestartClassLoader extends URLClassLoader implements SmartClassLoad
return
defineClass
(
name
,
b
,
0
,
b
.
length
,
protectionDomain
);
}
@Override
public
ClassLoader
getOriginalClassLoader
()
{
return
getParent
();
}
private
URL
createFileUrl
(
String
name
,
ClassLoaderFile
file
)
{
try
{
return
new
URL
(
"reloaded"
,
null
,
-
1
,
"/"
+
name
,
new
ClassLoaderFileURLStreamHandler
(
file
));
...
...
spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/classloader/RestartClassLoaderTests.java
View file @
29ba18af
...
...
@@ -20,6 +20,7 @@ import java.io.File;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.nio.charset.StandardCharsets
;
...
...
@@ -36,7 +37,14 @@ import org.junit.jupiter.api.Test;
import
org.junit.jupiter.api.io.TempDir
;
import
org.springframework.aop.framework.ProxyFactory
;
import
org.springframework.aop.support.AopUtils
;
import
org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kind
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.EnableAspectJAutoProxy
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.FileCopyUtils
;
import
org.springframework.util.StreamUtils
;
...
...
@@ -210,6 +218,20 @@ class RestartClassLoaderTests {
// Warning would happen outside the boundary of the test
}
@Test
void
packagePrivateClassLoadedByParentClassLoaderCanBeProxied
()
throws
MalformedURLException
{
new
ApplicationContextRunner
()
.
withClassLoader
(
new
RestartClassLoader
(
ExampleTransactional
.
class
.
getClassLoader
(),
new
URL
[]
{
this
.
sampleJarFile
.
toURI
().
toURL
()
},
this
.
updatedFiles
))
.
withUserConfiguration
(
ProxyConfiguration
.
class
).
run
((
context
)
->
{
assertThat
(
context
).
hasNotFailed
();
ExampleTransactional
transactional
=
context
.
getBean
(
ExampleTransactional
.
class
);
assertThat
(
AopUtils
.
isCglibProxy
(
transactional
)).
isTrue
();
assertThat
(
transactional
.
getClass
().
getClassLoader
())
.
isEqualTo
(
ExampleTransactional
.
class
.
getClassLoader
());
});
}
private
String
readString
(
InputStream
in
)
throws
IOException
{
return
new
String
(
FileCopyUtils
.
copyToByteArray
(
in
));
}
...
...
@@ -218,4 +240,32 @@ class RestartClassLoaderTests {
return
(
enumeration
!=
null
)
?
Collections
.
list
(
enumeration
)
:
Collections
.
emptyList
();
}
@Configuration
(
proxyBeanMethods
=
false
)
@EnableAspectJAutoProxy
(
proxyTargetClass
=
true
)
@EnableTransactionManagement
static
class
ProxyConfiguration
{
@Bean
ExampleTransactional
exampleTransactional
()
{
return
new
ExampleTransactional
();
}
}
static
class
ExampleTransactional
implements
ExampleInterface
{
@Override
@Transactional
public
String
doIt
()
{
return
"hello"
;
}
}
interface
ExampleInterface
{
String
doIt
();
}
}
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