mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Compare commits
367 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 35d1a8b6b2 | |||
| c8e320019f | |||
| 973eb5deb6 | |||
| b89cb20b1d | |||
| 52ed4226bd | |||
| b0433810da | |||
| db2c807515 | |||
| a45bce1369 | |||
| 8d1499e168 | |||
| ff0afcff06 | |||
| 53430760f3 | |||
| d61a7ed1f0 | |||
| ca0ce7d631 | |||
| fc2f3ecf44 | |||
| d551710c32 | |||
| 6fe8cb949f | |||
| 842297699d | |||
| d90d65bad2 | |||
| a21ce42558 | |||
| e54eb56cb9 | |||
| f5e6c707ae | |||
| c0b0ee6db7 | |||
| 4642c32c0f | |||
| a55261f82d | |||
| 5ca2c56cf0 | |||
| 702d533e6f | |||
| 1535f985be | |||
| 94ae933122 | |||
| 952315c333 | |||
| a00607348c | |||
| 1d58fac54d | |||
| 658bd7a686 | |||
| 717e6dd2d9 | |||
| 7f82c192f5 | |||
| dcdd08c432 | |||
| 06ed818f4c | |||
| ad5447253c | |||
| 7653762240 | |||
| 89fca1b949 | |||
| 92bb76f3cd | |||
| 4b6a5fbd13 | |||
| b17e7c321a | |||
| ee559bb2c8 | |||
| 1371cfe301 | |||
| 04814e604e | |||
| e332e32a88 | |||
| 648fa60f48 | |||
| 4004f92e3f | |||
| 6189e17d7c | |||
| 1e8cb5fc59 | |||
| b5270a9cff | |||
| a44fe4cbe4 | |||
| abb92b6966 | |||
| 68cf18f4a3 | |||
| 92228f9e64 | |||
| fb083a3776 | |||
| f532de5a8a | |||
| 6b3dd0779f | |||
| bf7fa39a48 | |||
| 37db3ba834 | |||
| 4b2a0471e1 | |||
| 7894ecf445 | |||
| 0e3f23eeb7 | |||
| e306d3e83a | |||
| f23496ae32 | |||
| 1d8e5f4d85 | |||
| d8aecd8c87 | |||
| 6ed03c24ac | |||
| 9c1cbbb689 | |||
| 67d0c69a95 | |||
| 951b39cc7a | |||
| 1695ef7e87 | |||
| 6f41d4ec4d | |||
| 42dbc39032 | |||
| 1d45e326b7 | |||
| 7737175140 | |||
| e00fd52dc6 | |||
| a159dd5993 | |||
| d8d04d82c1 | |||
| f3184a0878 | |||
| 688ef9ad46 | |||
| 9580bbd59f | |||
| a9305dbe8b | |||
| a80f4caf37 | |||
| eaafcee077 | |||
| a45ef35b38 | |||
| b87ee4ca32 | |||
| 737ece71ca | |||
| a938f528e2 | |||
| 2b593b0b06 | |||
| 4042c1d578 | |||
| 34052945de | |||
| c814f5821a | |||
| 6562e3047f | |||
| 0d0a0a2d08 | |||
| 08b5921fff | |||
| f9307897b6 | |||
| f4c0421a7d | |||
| ecf6c381be | |||
| 55e8aea2a3 | |||
| 77e75fdf87 | |||
| 8c1290084d | |||
| 4133355b72 | |||
| 7476c5d5db | |||
| fd75600c26 | |||
| a4be54d760 | |||
| f791b827ec | |||
| a65c7ef780 | |||
| 2a32c6cf57 | |||
| 91fa2ed0d4 | |||
| 006db06d11 | |||
| 6839570187 | |||
| 5f96d7c46c | |||
| cca8968a44 | |||
| b6a049a088 | |||
| 2d83051ce1 | |||
| f9ff6d4192 | |||
| 514c28b7c0 | |||
| 5da58393c1 | |||
| 79936d98de | |||
| 7dff7bb7a4 | |||
| d7cf2c869c | |||
| c89fb745f7 | |||
| e214ee5c85 | |||
| 93ef169c5c | |||
| 407bd96cf3 | |||
| 0b5c099de2 | |||
| 4f9a18f5aa | |||
| 9b3d80c5e4 | |||
| dc066b0530 | |||
| 0c44b5224f | |||
| 207e8c2409 | |||
| 2329588856 | |||
| f677d684e7 | |||
| 3878db2e8c | |||
| 24a113fb27 | |||
| e21db2619b | |||
| f5dd4d2c02 | |||
| 192113de60 | |||
| f89511e7fe | |||
| c3f6403f61 | |||
| 5007d01c17 | |||
| f1c55a3b4a | |||
| 34a0cdfc33 | |||
| 1cd0135195 | |||
| 0c5c3103c6 | |||
| c66f9d8880 | |||
| 4d3a899a53 | |||
| 11fc086309 | |||
| ed54895e53 | |||
| b72594d799 | |||
| 4341838a21 | |||
| 58f58e404e | |||
| c0040a5508 | |||
| 55563c16b5 | |||
| ae1d500bc3 | |||
| 9134588a82 | |||
| d283424c82 | |||
| 6e019f9ed0 | |||
| d9d41b4398 | |||
| eac0ddce13 | |||
| a363a229eb | |||
| 2bf7c18203 | |||
| 9458186e83 | |||
| d81ec55a60 | |||
| 4c8d81bcb4 | |||
| 6218db9831 | |||
| 7ea8ecb6ab | |||
| 8c1bc63c9d | |||
| f179181b40 | |||
| eb3254d2a9 | |||
| 6cae0650e6 | |||
| 43868d2b72 | |||
| a8b747c21c | |||
| 490b78a3d3 | |||
| 1ab9e2ceda | |||
| a1d35c23aa | |||
| 99534a31ba | |||
| c6dbfe42d3 | |||
| acf9ea097a | |||
| decbb43757 | |||
| 0480e75785 | |||
| ac1e2879e5 | |||
| ce0323fa8c | |||
| 0052c899bd | |||
| 8c07c6d099 | |||
| 214fa9c2a0 | |||
| ea534b6820 | |||
| 5a111125c1 | |||
| ac48c64b1a | |||
| 9a20ec9284 | |||
| 03beee7b68 | |||
| 4be6bcae74 | |||
| 6d0f8bf145 | |||
| a631af80c1 | |||
| 3e64388b20 | |||
| d3b06a15f2 | |||
| 75f26eec98 | |||
| 4402336c44 | |||
| e388ddfdde | |||
| f83a01e573 | |||
| d1c9401dc2 | |||
| 60838dcd03 | |||
| 3526766635 | |||
| 425c311d3c | |||
| 24acae1195 | |||
| 49f21ac3ac | |||
| 8339e7ade5 | |||
| 4560f096b9 | |||
| 4ec9f5df5c | |||
| 224fcc1712 | |||
| 96eba8b997 | |||
| be5229949c | |||
| 516937cfc5 | |||
| dac97f1b7d | |||
| f2694a8ed9 | |||
| 82f421bff8 | |||
| a2765c009e | |||
| 78d3164543 | |||
| afcc430481 | |||
| 062a15fbd7 | |||
| c04c8a2472 | |||
| f39adcf865 | |||
| da049f480b | |||
| 455d8ac7b9 | |||
| b80c13b722 | |||
| 7bfd683816 | |||
| fe01e5114d | |||
| b5595c3904 | |||
| 76678e9c6a | |||
| b3a34f8397 | |||
| 79adffd214 | |||
| af0a82931e | |||
| bbe5124556 | |||
| 5935b7aefe | |||
| a2d7cc7a69 | |||
| 8a56db6e4e | |||
| 50d6d90ed8 | |||
| a7ffe092ab | |||
| 6407cb9baf | |||
| 0bc0762577 | |||
| 051ab05d32 | |||
| 9d36fd0b68 | |||
| f078e057ce | |||
| 941186a359 | |||
| 27fc4d6053 | |||
| 1943a1f5bd | |||
| a158ff4c3d | |||
| a71bd7c03f | |||
| 1fefe2ab0c | |||
| 0b36c9437e | |||
| 72e7687b80 | |||
| e87355b29c | |||
| 1dc8201df1 | |||
| e3e975d7f9 | |||
| b385ff1d9f | |||
| 3c88029dd3 | |||
| c7adf28f61 | |||
| c555fef6f2 | |||
| ab0b0b31fd | |||
| d24546ad18 | |||
| 2818051aff | |||
| a3bcdbe371 | |||
| 3978d5500d | |||
| 416dee7226 | |||
| 4d69ec48b1 | |||
| 14a9d291e1 | |||
| 5183f71a78 | |||
| fd36af6fcf | |||
| 9179a4fa30 | |||
| 98335b41f7 | |||
| e9f4dec08c | |||
| 4ec695b4d9 | |||
| 2da02ccbd0 | |||
| f2cc70ecf9 | |||
| e2115594c0 | |||
| 2008e04354 | |||
| b4f83dbdc3 | |||
| 0795ae5c6a | |||
| 41ab177b6c | |||
| 8848ec73ab | |||
| 9f9481ec7b | |||
| f6275e009b | |||
| ed44262a71 | |||
| a0d37ac29e | |||
| a39938d251 | |||
| edb33331ed | |||
| a63f04df09 | |||
| 5a98516f6c | |||
| 30363c84bd | |||
| fa27130b82 | |||
| be4c07fc32 | |||
| 22f421cc51 | |||
| 9dc538a7c6 | |||
| d74a2730ec | |||
| 3e47f4564d | |||
| a9548f93e4 | |||
| f2e77c292d | |||
| 8b051ab06e | |||
| 5a1d7f9c4b | |||
| b55f69deb1 | |||
| de1eb343e7 | |||
| 417bb302c3 | |||
| b0aa08a671 | |||
| 9dc79982e2 | |||
| 43f2334e82 | |||
| 6c6e44b58e | |||
| c6b60f0c00 | |||
| 7aba6ca9d6 | |||
| dca77c0666 | |||
| df6e690e33 | |||
| a702ef8074 | |||
| f7376bdde3 | |||
| f9e31b503c | |||
| 3551dd92fb | |||
| c23297fe76 | |||
| a5622d0dd2 | |||
| 72cfe41f30 | |||
| 4ff595e2bc | |||
| 2c766b9501 | |||
| 2960a558d7 | |||
| d69a281e5c | |||
| d3ed7b624d | |||
| 66bd277671 | |||
| 881343e928 | |||
| 922fd1e785 | |||
| ea8317a1f9 | |||
| 053ffe808f | |||
| daa2d37ad4 | |||
| f800df12e3 | |||
| 26652a6b83 | |||
| 4cd43dc793 | |||
| 91c8b62817 | |||
| 9d37c099a8 | |||
| eb573d8b9e | |||
| b312a62f64 | |||
| 567733d2a1 | |||
| 0f91f4b960 | |||
| c1385f52c2 | |||
| c3bc125093 | |||
| b5922f75bb | |||
| bbe850d33a | |||
| 295929cc16 | |||
| 4763154193 | |||
| 8f7e5e7c1a | |||
| cd79966c52 | |||
| 7631aa6062 | |||
| 02e09098e4 | |||
| 230c8f93e8 | |||
| c4296fa785 | |||
| ab78854f1b | |||
| 96a465a749 | |||
| 861b9dc938 | |||
| eda2720471 | |||
| 7fe28ce8b7 | |||
| de8c4179fb | |||
| 433877e5cb | |||
| ffa4f03fd4 | |||
| 7068282e1f | |||
| 3879179927 | |||
| 007da2a58d | |||
| 1be585562f | |||
| 7a896d7d80 | |||
| be1aaa06e7 | |||
| 2fa060f0e9 | |||
| 4d2d889142 | |||
| 4b9bc50fd0 |
+2
-2
@@ -38,7 +38,7 @@ it helps us to make a decision.
|
||||
Reporting an issue or making a feature request is a great way to contribute. Your feedback
|
||||
and the conversations that result from it provide a continuous flow of ideas.
|
||||
|
||||
Before you create a ticket, please take the time to [research first](#Discuss).
|
||||
Before you create a ticket, please take the time to [research first](#discuss).
|
||||
|
||||
If creating a ticket after a discussion on StackOverflow, please provide a self-sufficient description in the ticket, independent of the details on StackOverview. We understand this is extra work but the issue tracker is an important place of record for design discussions and decisions that can often be referenced long after the fix version, for example to revisit decisions, to understand the origin of a feature, and so on.
|
||||
|
||||
@@ -64,7 +64,7 @@ You can contribute a source code change by submitting a pull request.
|
||||
[Contributor License Agreement](https://cla.pivotal.io/sign/spring). You will also be reminded
|
||||
automatically when you submit a pull request.
|
||||
|
||||
1. For all but the most trivial of contributions, please [create a ticket](#Create-a-Ticket).
|
||||
1. For all but the most trivial of contributions, please [create a ticket](#create-a-ticket).
|
||||
The purpose of the ticket is to understand and discuss the underlying issue or feature.
|
||||
We use the JIRA issue tracker as the preferred place of record for conversations and
|
||||
conclusions. In that sense discussions directly under a PR are more implementation detail
|
||||
|
||||
+81
-75
@@ -14,26 +14,52 @@ buildscript {
|
||||
plugins {
|
||||
id "com.gradle.build-scan" version "1.8"
|
||||
id "io.spring.dependency-management" version "1.0.3.RELEASE" apply false
|
||||
id "org.jetbrains.kotlin.jvm" version "1.2.31" apply false
|
||||
id "org.jetbrains.dokka" version "0.9.16"
|
||||
id "org.jetbrains.kotlin.jvm" version "1.2.51" apply false
|
||||
id "org.jetbrains.dokka" version "0.9.17"
|
||||
id "org.asciidoctor.convert" version "1.5.6"
|
||||
}
|
||||
|
||||
buildScan {
|
||||
licenseAgreementUrl = 'https://gradle.com/terms-of-service'
|
||||
licenseAgree = 'yes'
|
||||
licenseAgreementUrl = "https://gradle.com/terms-of-service"
|
||||
licenseAgree = "yes"
|
||||
}
|
||||
|
||||
ext {
|
||||
linkHomepage = 'https://projects.spring.io/spring-framework'
|
||||
linkCi = 'https://build.spring.io/browse/SPR'
|
||||
linkIssue = 'https://jira.spring.io/browse/SPR'
|
||||
linkScmUrl = 'https://github.com/spring-projects/spring-framework'
|
||||
linkScmConnection = 'scm:git:git://github.com/spring-projects/spring-framework.git'
|
||||
linkScmDevConnection = 'scm:git:ssh://git@github.com:spring-projects/spring-framework.git'
|
||||
linkHomepage = "https://projects.spring.io/spring-framework"
|
||||
linkCi = "https://build.spring.io/browse/SPR"
|
||||
linkIssue = "https://jira.spring.io/browse/SPR"
|
||||
linkScmUrl = "https://github.com/spring-projects/spring-framework"
|
||||
linkScmConnection = "scm:git:git://github.com/spring-projects/spring-framework.git"
|
||||
linkScmDevConnection = "scm:git:ssh://git@github.com:spring-projects/spring-framework.git"
|
||||
|
||||
moduleProjects = subprojects.findAll {
|
||||
!it.name.equals('spring-build-src') && !it.name.equals('spring-framework-bom')
|
||||
!it.name.equals("spring-build-src") && !it.name.equals("spring-framework-bom")
|
||||
}
|
||||
|
||||
aspectjVersion = "1.8.13"
|
||||
freemarkerVersion = "2.3.27-incubating"
|
||||
groovyVersion = "2.4.15"
|
||||
hsqldbVersion = "2.4.1"
|
||||
jackson2Version = "2.9.6"
|
||||
jettyVersion = "9.4.12.v20180830"
|
||||
junitJupiterVersion = "5.0.3"
|
||||
junitPlatformVersion = "1.0.3"
|
||||
junitVintageVersion = "4.12.3"
|
||||
kotlinVersion = "1.2.51"
|
||||
log4jVersion = "2.11.1"
|
||||
nettyVersion = "4.1.29.Final"
|
||||
reactorVersion = "Bismuth-SR11"
|
||||
rxjavaVersion = "1.3.8"
|
||||
rxjavaAdapterVersion = "1.2.1"
|
||||
rxjava2Version = "2.1.17"
|
||||
slf4jVersion = "1.7.25" // spring-jcl + consistent 3rd party deps
|
||||
tiles3Version = "3.0.8"
|
||||
tomcatVersion = "8.5.33"
|
||||
undertowVersion = "1.4.25.Final"
|
||||
|
||||
gradleScriptDir = "${rootProject.projectDir}/gradle"
|
||||
withoutJclOverSlf4J = {
|
||||
exclude group: "org.slf4j", module: "jcl-over-slf4j"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,62 +67,33 @@ configure(allprojects) { project ->
|
||||
group = "org.springframework"
|
||||
version = qualifyVersionIfNecessary(version)
|
||||
|
||||
ext.aspectjVersion = "1.8.13"
|
||||
ext.freemarkerVersion = "2.3.27-incubating"
|
||||
ext.groovyVersion = "2.4.15"
|
||||
ext.hsqldbVersion = "2.4.0"
|
||||
ext.jackson2Version = "2.9.5"
|
||||
ext.jettyVersion = "9.4.9.v20180320"
|
||||
ext.junitJupiterVersion = "5.0.3"
|
||||
ext.junitPlatformVersion = "1.0.3"
|
||||
ext.junitVintageVersion = "4.12.3"
|
||||
ext.kotlinVersion = "1.2.31"
|
||||
ext.log4jVersion = "2.11.0"
|
||||
ext.nettyVersion = "4.1.22.Final"
|
||||
ext.reactorVersion = "Bismuth-SR8"
|
||||
ext.rxjavaVersion = "1.3.8"
|
||||
ext.rxjavaAdapterVersion = "1.2.1"
|
||||
ext.rxjava2Version = "2.1.12"
|
||||
ext.slf4jVersion = "1.7.25" // spring-jcl + consistent 3rd party deps
|
||||
ext.tiles3Version = "3.0.8"
|
||||
ext.tomcatVersion = "8.5.29"
|
||||
ext.undertowVersion = "1.4.23.Final"
|
||||
|
||||
ext.gradleScriptDir = "${rootProject.projectDir}/gradle"
|
||||
|
||||
apply plugin: "propdeps"
|
||||
apply plugin: "java"
|
||||
apply plugin: "kotlin"
|
||||
apply plugin: "propdeps"
|
||||
apply plugin: "test-source-set-dependencies"
|
||||
apply plugin: "io.spring.dependency-management"
|
||||
apply from: "${gradleScriptDir}/ide.gradle"
|
||||
|
||||
apply plugin: "kotlin"
|
||||
compileKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
freeCompilerArgs = ["-Xjsr305=strict"]
|
||||
apiVersion = "1.1"
|
||||
languageVersion = "1.1"
|
||||
dependencyManagement {
|
||||
resolutionStrategy {
|
||||
cacheChangingModulesFor 0, "seconds"
|
||||
}
|
||||
}
|
||||
compileTestKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
freeCompilerArgs = ["-Xjsr305=strict"]
|
||||
applyMavenExclusions = false
|
||||
generatedPomCustomization {
|
||||
enabled = false
|
||||
}
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
// Check for updates every build
|
||||
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
|
||||
resolutionStrategy.cacheChangingModulesFor 0, "seconds"
|
||||
|
||||
// Consistent slf4j version (e.g. clashes between slf4j versions)
|
||||
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
|
||||
if (details.requested.group == 'org.slf4j') {
|
||||
if (details.requested.group == "org.slf4j") {
|
||||
details.useVersion slf4jVersion
|
||||
}
|
||||
}
|
||||
|
||||
exclude group: "org.slf4j", module: "jcl-over-slf4j"
|
||||
}
|
||||
|
||||
def commonCompilerArgs =
|
||||
@@ -109,22 +106,38 @@ configure(allprojects) { project ->
|
||||
"-Xlint:deprecation", "-Xlint:unchecked", "-Werror"]
|
||||
|
||||
compileTestJava.options*.compilerArgs = commonCompilerArgs +
|
||||
["-Xlint:-varargs", "-Xlint:-fallthrough","-Xlint:-rawtypes",
|
||||
["-Xlint:-varargs", "-Xlint:-fallthrough", "-Xlint:-rawtypes",
|
||||
"-Xlint:-deprecation", "-Xlint:-unchecked"]
|
||||
|
||||
compileJava {
|
||||
sourceCompatibility = 1.8 // can be switched to 10 for testing
|
||||
targetCompatibility = 1.8
|
||||
options.encoding = 'UTF-8'
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
compileTestJava {
|
||||
sourceCompatibility = 1.8 // can be switched to 10 for testing
|
||||
targetCompatibility = 1.8
|
||||
options.encoding = 'UTF-8'
|
||||
options.encoding = "UTF-8"
|
||||
options.compilerArgs += "-parameters"
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
freeCompilerArgs = ["-Xjsr305=strict"]
|
||||
apiVersion = "1.1"
|
||||
languageVersion = "1.1"
|
||||
}
|
||||
}
|
||||
|
||||
compileTestKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
freeCompilerArgs = ["-Xjsr305=strict"]
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
systemProperty("java.awt.headless", "true")
|
||||
systemProperty("testGroups", project.properties.get("testGroups"))
|
||||
@@ -143,22 +156,21 @@ configure(allprojects) { project ->
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.12") {
|
||||
exclude group:'org.hamcrest', module:'hamcrest-core'
|
||||
exclude group: "org.hamcrest", module: "hamcrest-core"
|
||||
}
|
||||
testCompile("org.mockito:mockito-core:2.12.0") {
|
||||
exclude group:'org.hamcrest', module:'hamcrest-core'
|
||||
testCompile("org.mockito:mockito-core:2.19.1") {
|
||||
exclude group: "org.hamcrest", module: "hamcrest-core"
|
||||
}
|
||||
testCompile("com.nhaarman:mockito-kotlin:1.5.0") {
|
||||
exclude module:'kotlin-stdlib'
|
||||
exclude module:'kotlin-reflect'
|
||||
exclude module:'mockito-core'
|
||||
testCompile("com.nhaarman:mockito-kotlin:1.6.0") {
|
||||
exclude module: "kotlin-stdlib"
|
||||
exclude module: "kotlin-reflect"
|
||||
exclude module: "mockito-core"
|
||||
}
|
||||
testCompile("org.hamcrest:hamcrest-all:1.3")
|
||||
testCompile("org.xmlunit:xmlunit-matchers:2.3.0")
|
||||
testRuntime("org.apache.logging.log4j:log4j-core:${log4jVersion}")
|
||||
testRuntime("org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}")
|
||||
testRuntime("org.apache.logging.log4j:log4j-jul:${log4jVersion}")
|
||||
// JSR-305 only used for non-required meta-annotations
|
||||
// JSR-305 only used for non-required meta-annotations
|
||||
compileOnly("com.google.code.findbugs:jsr305:3.0.2")
|
||||
testCompileOnly("com.google.code.findbugs:jsr305:3.0.2")
|
||||
}
|
||||
@@ -209,7 +221,7 @@ configure(subprojects - project(":spring-build-src")) { subproject ->
|
||||
options.header = project.name
|
||||
options.use = true
|
||||
options.links(project.ext.javadocLinks)
|
||||
options.addStringOption('Xdoclint:none', '-quiet')
|
||||
options.addStringOption("Xdoclint:none", "-quiet")
|
||||
|
||||
// Suppress warnings due to cross-module @see and @link references.
|
||||
// Note that global 'api' task does display all warnings.
|
||||
@@ -219,7 +231,7 @@ configure(subprojects - project(":spring-build-src")) { subproject ->
|
||||
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
classifier = 'sources'
|
||||
classifier = "sources"
|
||||
from sourceSets.main.allSource
|
||||
// Don't include or exclude anything explicitly by default. See SPR-12085.
|
||||
}
|
||||
@@ -239,7 +251,6 @@ configure(rootProject) {
|
||||
description = "Spring Framework"
|
||||
|
||||
apply plugin: "groovy"
|
||||
apply plugin: "io.spring.dependency-management"
|
||||
apply from: "${gradleScriptDir}/jdiff.gradle"
|
||||
apply from: "${gradleScriptDir}/docs.gradle"
|
||||
|
||||
@@ -247,13 +258,9 @@ configure(rootProject) {
|
||||
imports {
|
||||
mavenBom "io.projectreactor:reactor-bom:${reactorVersion}"
|
||||
}
|
||||
resolutionStrategy {
|
||||
cacheChangingModulesFor 0, 'seconds'
|
||||
}
|
||||
applyMavenExclusions = false
|
||||
}
|
||||
|
||||
// don't publish the default jar for the root project
|
||||
// Don't publish the default jar for the root project
|
||||
configurations.archives.artifacts.clear()
|
||||
|
||||
dependencies { // for integration tests
|
||||
@@ -272,7 +279,7 @@ configure(rootProject) {
|
||||
testCompile("javax.servlet:javax.servlet-api:3.1.0")
|
||||
testCompile("org.aspectj:aspectjweaver:${aspectjVersion}")
|
||||
testCompile("org.hsqldb:hsqldb:${hsqldbVersion}")
|
||||
testCompile("org.hibernate:hibernate-core:5.1.13.Final")
|
||||
testCompile("org.hibernate:hibernate-core:5.1.14.Final")
|
||||
}
|
||||
|
||||
artifacts {
|
||||
@@ -283,7 +290,7 @@ configure(rootProject) {
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
description = "Generates gradlew[.bat] scripts"
|
||||
gradleVersion = '4.4.1'
|
||||
gradleVersion = "4.4.1"
|
||||
|
||||
doLast() {
|
||||
def gradleOpts = "-XX:MaxMetaspaceSize=1024m -Xmx1024m"
|
||||
@@ -296,7 +303,6 @@ configure(rootProject) {
|
||||
"set GRADLE_OPTS=$gradleBatOpts %GRADLE_OPTS%\nset DEFAULT_JVM_OPTS=")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -310,7 +316,7 @@ def qualifyVersionIfNecessary(version) {
|
||||
if (rootProject.hasProperty("BRANCH_NAME")) {
|
||||
def qualifier = rootProject.getProperty("BRANCH_NAME")
|
||||
if (qualifier.startsWith("SPR-")) {
|
||||
return version.replace('BUILD', qualifier)
|
||||
return version.replace("BUILD", qualifier)
|
||||
}
|
||||
}
|
||||
return version
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
version=5.0.5.BUILD-SNAPSHOT
|
||||
version=5.0.10.RELEASE
|
||||
|
||||
+11
-5
@@ -27,6 +27,7 @@ task api(type: Javadoc) {
|
||||
options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
|
||||
options.author = true
|
||||
options.header = rootProject.description
|
||||
options.use = true
|
||||
options.overview = "src/docs/api/overview.html"
|
||||
options.stylesheetFile = file("src/docs/api/stylesheet.css")
|
||||
options.splitIndex = true
|
||||
@@ -49,12 +50,9 @@ task api(type: Javadoc) {
|
||||
}
|
||||
}
|
||||
|
||||
// Need https://github.com/Kotlin/dokka/issues/184 to be fixed to avoid "Can't find node by signature" log spam
|
||||
dokka {
|
||||
dependsOn {
|
||||
subprojects.collect {
|
||||
it.tasks.getByName("jar")
|
||||
}
|
||||
tasks.getByName("api")
|
||||
}
|
||||
doFirst {
|
||||
classpath = subprojects.collect { project -> project.jar.outputs.files.getFiles() }.flatten()
|
||||
@@ -69,6 +67,10 @@ dokka {
|
||||
def kotlinDirs = project.sourceSets.main.kotlin.srcDirs.collect()
|
||||
kotlinDirs -= project.sourceSets.main.java.srcDirs
|
||||
})
|
||||
externalDocumentationLink {
|
||||
url = new URL("https://docs.spring.io/spring-framework/docs/$version/javadoc-api/")
|
||||
packageListUrl = new File(buildDir, "api/package-list").toURI().toURL()
|
||||
}
|
||||
externalDocumentationLink {
|
||||
url = new URL("http://projectreactor.io/docs/core/release/api/")
|
||||
}
|
||||
@@ -122,10 +124,14 @@ task docsZip(type: Zip, dependsOn: ['api', 'asciidoctor', 'dokka']) {
|
||||
into "javadoc-api"
|
||||
}
|
||||
|
||||
from (asciidoctor) {
|
||||
from ("$asciidoctor.outputDir/html5") {
|
||||
into "spring-framework-reference"
|
||||
}
|
||||
|
||||
from ("$asciidoctor.outputDir/pdf") {
|
||||
into "spring-framework-reference/pdf"
|
||||
}
|
||||
|
||||
from (dokka) {
|
||||
into "kdoc-api"
|
||||
}
|
||||
|
||||
@@ -18,6 +18,11 @@ def customizePom(pom, gradleProject) {
|
||||
"$dep.scope:$dep.groupId:$dep.artifactId"
|
||||
}
|
||||
|
||||
def managedVersions = dependencyManagement.managedVersions
|
||||
generatedPom.dependencies.findAll{dep -> !dep.version }.each { dep ->
|
||||
dep.version = managedVersions["${dep.groupId}:${dep.artifactId}"]
|
||||
}
|
||||
|
||||
// add all items necessary for maven central publication
|
||||
generatedPom.project {
|
||||
name = gradleProject.description
|
||||
|
||||
+1
-20
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
pluginManagement {
|
||||
repositories {
|
||||
maven {
|
||||
url "https://dl.bintray.com/kotlin/kotlin-eap-1.1"
|
||||
}
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Workaround for https://github.com/Kotlin/dokka/issues/146
|
||||
pluginManagement {
|
||||
repositories {
|
||||
jcenter()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
include "spring-aop"
|
||||
include "spring-aspects"
|
||||
include "spring-beans"
|
||||
@@ -44,7 +25,7 @@ include "spring-framework-bom"
|
||||
include "buildSrc"
|
||||
rootProject.children.find{ it.name == "buildSrc" }.name = "spring-build-src"
|
||||
|
||||
rootProject.name = 'spring'
|
||||
rootProject.name = "spring"
|
||||
rootProject.children.each {project ->
|
||||
project.buildFileName = "${project.name}.gradle"
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ description = "Spring AOP"
|
||||
|
||||
dependencies {
|
||||
compile(project(":spring-beans"))
|
||||
compile(project(':spring-core'))
|
||||
compile(project(":spring-core"))
|
||||
optional("org.aspectj:aspectjweaver:${aspectjVersion}")
|
||||
optional("org.apache.commons:commons-pool2:2.5.0")
|
||||
optional("com.jamonapi:jamon:2.81")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -50,10 +50,11 @@ import org.springframework.lang.Nullable;
|
||||
public interface MethodMatcher {
|
||||
|
||||
/**
|
||||
* Perform static checking whether the given method matches. If this
|
||||
* returns {@code false} or if the {@link #isRuntime()} method
|
||||
* returns {@code false}, no runtime check (i.e. no.
|
||||
* {@link #matches(java.lang.reflect.Method, Class, Object[])} call) will be made.
|
||||
* Perform static checking whether the given method matches.
|
||||
* <p>If this returns {@code false} or if the {@link #isRuntime()}
|
||||
* method returns {@code false}, no runtime check (i.e. no
|
||||
* {@link #matches(java.lang.reflect.Method, Class, Object[])} call)
|
||||
* will be made.
|
||||
* @param method the candidate method
|
||||
* @param targetClass the target class (may be {@code null}, in which case
|
||||
* the candidate class must be taken to be the method's declaring class)
|
||||
|
||||
+50
-26
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,6 +19,7 @@ package org.springframework.aop.aspectj;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@@ -289,10 +290,9 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Method method, @Nullable Class<?> targetClass, boolean beanHasIntroductions) {
|
||||
public boolean matches(Method method, @Nullable Class<?> targetClass, boolean hasIntroductions) {
|
||||
obtainPointcutExpression();
|
||||
Method targetMethod = AopUtils.getMostSpecificMethod(method, targetClass);
|
||||
ShadowMatch shadowMatch = getShadowMatch(targetMethod, method);
|
||||
ShadowMatch shadowMatch = getTargetShadowMatch(method, targetClass);
|
||||
|
||||
// Special handling for this, target, @this, @target, @annotation
|
||||
// in Spring - we can optimize since we know we have exactly this class,
|
||||
@@ -305,7 +305,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
}
|
||||
else {
|
||||
// the maybe case
|
||||
if (beanHasIntroductions) {
|
||||
if (hasIntroductions) {
|
||||
return true;
|
||||
}
|
||||
// A match test returned maybe - if there are any subtype sensitive variables
|
||||
@@ -331,8 +331,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
@Override
|
||||
public boolean matches(Method method, @Nullable Class<?> targetClass, Object... args) {
|
||||
obtainPointcutExpression();
|
||||
ShadowMatch shadowMatch = getShadowMatch(AopUtils.getMostSpecificMethod(method, targetClass), method);
|
||||
ShadowMatch originalShadowMatch = getShadowMatch(method, method);
|
||||
ShadowMatch shadowMatch = getTargetShadowMatch(method, targetClass);
|
||||
|
||||
// Bind Spring AOP proxy to AspectJ "this" and Spring AOP target to AspectJ target,
|
||||
// consistent with return of MethodInvocationProceedingJoinPoint
|
||||
@@ -367,7 +366,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
* <p>See SPR-2979 for the original bug.
|
||||
*/
|
||||
if (pmi != null && thisObject != null) { // there is a current invocation
|
||||
RuntimeTestWalker originalMethodResidueTest = getRuntimeTestWalker(originalShadowMatch);
|
||||
RuntimeTestWalker originalMethodResidueTest = getRuntimeTestWalker(getShadowMatch(method, method));
|
||||
if (!originalMethodResidueTest.testThisInstanceOfResidue(thisObject.getClass())) {
|
||||
return false;
|
||||
}
|
||||
@@ -427,6 +426,28 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
invocation.setUserAttribute(resolveExpression(), jpm);
|
||||
}
|
||||
|
||||
private ShadowMatch getTargetShadowMatch(Method method, @Nullable Class<?> targetClass) {
|
||||
Method targetMethod = AopUtils.getMostSpecificMethod(method, targetClass);
|
||||
if (targetClass != null && targetMethod.getDeclaringClass().isInterface()) {
|
||||
// Try to build the most specific interface possible for inherited methods to be
|
||||
// considered for sub-interface matches as well, in particular for proxy classes.
|
||||
// Note: AspectJ is only going to take Method.getDeclaringClass() into account.
|
||||
Set<Class<?>> ifcs = ClassUtils.getAllInterfacesForClassAsSet(targetClass);
|
||||
if (ifcs.size() > 1) {
|
||||
try {
|
||||
Class<?> compositeInterface = ClassUtils.createCompositeInterface(
|
||||
ClassUtils.toClassArray(ifcs), targetClass.getClassLoader());
|
||||
targetMethod = ClassUtils.getMostSpecificMethod(targetMethod, compositeInterface);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// Implemented interfaces probably expose conflicting method signatures...
|
||||
// Proceed with original target method.
|
||||
}
|
||||
}
|
||||
}
|
||||
return getShadowMatch(targetMethod, method);
|
||||
}
|
||||
|
||||
private ShadowMatch getShadowMatch(Method targetMethod, Method originalMethod) {
|
||||
// Avoid lock contention for known Methods through concurrent access...
|
||||
ShadowMatch shadowMatch = this.shadowMatchCache.get(targetMethod);
|
||||
@@ -434,9 +455,9 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
synchronized (this.shadowMatchCache) {
|
||||
// Not found - now check again with full lock...
|
||||
PointcutExpression fallbackExpression = null;
|
||||
Method methodToMatch = targetMethod;
|
||||
shadowMatch = this.shadowMatchCache.get(targetMethod);
|
||||
if (shadowMatch == null) {
|
||||
Method methodToMatch = targetMethod;
|
||||
try {
|
||||
try {
|
||||
shadowMatch = obtainPointcutExpression().matchesMethodExecution(methodToMatch);
|
||||
@@ -454,12 +475,16 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
fallbackExpression = null;
|
||||
}
|
||||
}
|
||||
if (shadowMatch == null && targetMethod != originalMethod) {
|
||||
if (targetMethod != originalMethod && (shadowMatch == null ||
|
||||
(shadowMatch.neverMatches() && Proxy.isProxyClass(targetMethod.getDeclaringClass())))) {
|
||||
// Fall back to the plain original method in case of no resolvable match or a
|
||||
// negative match on a proxy class (which doesn't carry any annotations on its
|
||||
// redeclared methods).
|
||||
methodToMatch = originalMethod;
|
||||
try {
|
||||
shadowMatch = obtainPointcutExpression().matchesMethodExecution(methodToMatch);
|
||||
}
|
||||
catch (ReflectionWorldException ex3) {
|
||||
catch (ReflectionWorldException ex) {
|
||||
// Could neither introspect the target class nor the proxy class ->
|
||||
// let's try the original method's declaring class before we give up...
|
||||
try {
|
||||
@@ -468,7 +493,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
shadowMatch = fallbackExpression.matchesMethodExecution(methodToMatch);
|
||||
}
|
||||
}
|
||||
catch (ReflectionWorldException ex4) {
|
||||
catch (ReflectionWorldException ex2) {
|
||||
fallbackExpression = null;
|
||||
}
|
||||
}
|
||||
@@ -542,6 +567,19 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Serialization support
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
|
||||
// Rely on default serialization, just initialize state after deserialization.
|
||||
ois.defaultReadObject();
|
||||
|
||||
// Initialize transient fields.
|
||||
// pointcutExpression will be initialized lazily by checkReadyToMatch()
|
||||
this.shadowMatchCache = new ConcurrentHashMap<>(32);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handler for the Spring-specific {@code bean()} pointcut designator
|
||||
@@ -638,20 +676,6 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Serialization support
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
|
||||
// Rely on default serialization, just initialize state after deserialization.
|
||||
ois.defaultReadObject();
|
||||
|
||||
// Initialize transient fields.
|
||||
// pointcutExpression will be initialized lazily by checkReadyToMatch()
|
||||
this.shadowMatchCache = new ConcurrentHashMap<>(32);
|
||||
}
|
||||
|
||||
|
||||
private static class DefensiveShadowMatch implements ShadowMatch {
|
||||
|
||||
private final ShadowMatch primary;
|
||||
|
||||
+14
-17
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,17 +33,15 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Implementation of AspectJ ProceedingJoinPoint interface
|
||||
* wrapping an AOP Alliance MethodInvocation.
|
||||
* An implementation of the AspectJ {@link ProceedingJoinPoint} interface
|
||||
* wrapping an AOP Alliance {@link org.aopalliance.intercept.MethodInvocation}.
|
||||
*
|
||||
* <p><b>Note</b>: the {@code getThis()} method returns the current Spring AOP proxy.
|
||||
* <p><b>Note</b>: The {@code getThis()} method returns the current Spring AOP proxy.
|
||||
* The {@code getTarget()} method returns the current Spring AOP target (which may be
|
||||
* {@code null} if there is no target), and is a plain POJO without any advice.
|
||||
* <b>If you want to call the object and have the advice take effect, use
|
||||
* {@code getThis()}.</b> A common example is casting the object to an
|
||||
* introduced interface in the implementation of an introduction.
|
||||
*
|
||||
* <p>Of course there is no such distinction between target and proxy in AspectJ.
|
||||
* {@code null} if there is no target instance) as a plain POJO without any advice.
|
||||
* <b>If you want to call the object and have the advice take effect, use {@code getThis()}.</b>
|
||||
* A common example is casting the object to an introduced interface in the implementation of
|
||||
* an introduction. There is no such distinction between target and proxy in AspectJ itself.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
@@ -58,7 +56,7 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
|
||||
private final ProxyMethodInvocation methodInvocation;
|
||||
|
||||
@Nullable
|
||||
private Object[] defensiveCopyOfArgs;
|
||||
private Object[] args;
|
||||
|
||||
/** Lazily initialized signature object */
|
||||
@Nullable
|
||||
@@ -79,6 +77,7 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
|
||||
this.methodInvocation = methodInvocation;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void set$AroundClosure(AroundClosure aroundClosure) {
|
||||
throw new UnsupportedOperationException();
|
||||
@@ -120,12 +119,10 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
|
||||
|
||||
@Override
|
||||
public Object[] getArgs() {
|
||||
if (this.defensiveCopyOfArgs == null) {
|
||||
Object[] argsSource = this.methodInvocation.getArguments();
|
||||
this.defensiveCopyOfArgs = new Object[argsSource.length];
|
||||
System.arraycopy(argsSource, 0, this.defensiveCopyOfArgs, 0, argsSource.length);
|
||||
if (this.args == null) {
|
||||
this.args = this.methodInvocation.getArguments().clone();
|
||||
}
|
||||
return this.defensiveCopyOfArgs;
|
||||
return this.args;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -133,7 +130,7 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
|
||||
if (this.signature == null) {
|
||||
this.signature = new MethodSignatureImpl();
|
||||
}
|
||||
return signature;
|
||||
return this.signature;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+38
-47
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -42,7 +42,6 @@ import org.springframework.aop.framework.AopConfigException;
|
||||
import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Abstract base class for factories that can create Spring AOP Advisors
|
||||
@@ -60,6 +59,9 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||
|
||||
private static final String AJC_MAGIC = "ajc$";
|
||||
|
||||
private static final Class<?>[] ASPECTJ_ANNOTATION_CLASSES = new Class<?>[] {
|
||||
Pointcut.class, Around.class, Before.class, After.class, AfterReturning.class, AfterThrowing.class};
|
||||
|
||||
|
||||
/** Logger available to subclasses */
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
@@ -123,15 +125,13 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||
|
||||
/**
|
||||
* Find and return the first AspectJ annotation on the given method
|
||||
* (there <i>should</i> only be one anyway...)
|
||||
* (there <i>should</i> only be one anyway...).
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
protected static AspectJAnnotation<?> findAspectJAnnotationOnMethod(Method method) {
|
||||
Class<?>[] classesToLookFor = new Class<?>[] {
|
||||
Before.class, Around.class, After.class, AfterReturning.class, AfterThrowing.class, Pointcut.class};
|
||||
for (Class<?> c : classesToLookFor) {
|
||||
AspectJAnnotation<?> foundAnnotation = findAnnotation(method, (Class<Annotation>) c);
|
||||
for (Class<?> clazz : ASPECTJ_ANNOTATION_CLASSES) {
|
||||
AspectJAnnotation<?> foundAnnotation = findAnnotation(method, (Class<Annotation>) clazz);
|
||||
if (foundAnnotation != null) {
|
||||
return foundAnnotation;
|
||||
}
|
||||
@@ -151,14 +151,13 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enum for AspectJ annotation types.
|
||||
* @see AspectJAnnotation#getAnnotationType()
|
||||
*/
|
||||
protected enum AspectJAnnotationType {
|
||||
|
||||
AtPointcut,
|
||||
AtBefore,
|
||||
AtAfter,
|
||||
AtAfterReturning,
|
||||
AtAfterThrowing,
|
||||
AtAround
|
||||
AtPointcut, AtAround, AtBefore, AtAfter, AtAfterReturning, AtAfterThrowing
|
||||
}
|
||||
|
||||
|
||||
@@ -168,17 +167,17 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||
*/
|
||||
protected static class AspectJAnnotation<A extends Annotation> {
|
||||
|
||||
private static final String[] EXPRESSION_PROPERTIES = new String[] {"value", "pointcut"};
|
||||
private static final String[] EXPRESSION_ATTRIBUTES = new String[] {"pointcut", "value"};
|
||||
|
||||
private static Map<Class<?>, AspectJAnnotationType> annotationTypes = new HashMap<>();
|
||||
private static Map<Class<?>, AspectJAnnotationType> annotationTypeMap = new HashMap<>(8);
|
||||
|
||||
static {
|
||||
annotationTypes.put(Pointcut.class,AspectJAnnotationType.AtPointcut);
|
||||
annotationTypes.put(After.class,AspectJAnnotationType.AtAfter);
|
||||
annotationTypes.put(AfterReturning.class,AspectJAnnotationType.AtAfterReturning);
|
||||
annotationTypes.put(AfterThrowing.class,AspectJAnnotationType.AtAfterThrowing);
|
||||
annotationTypes.put(Around.class,AspectJAnnotationType.AtAround);
|
||||
annotationTypes.put(Before.class,AspectJAnnotationType.AtBefore);
|
||||
annotationTypeMap.put(Pointcut.class, AspectJAnnotationType.AtPointcut);
|
||||
annotationTypeMap.put(Around.class, AspectJAnnotationType.AtAround);
|
||||
annotationTypeMap.put(Before.class, AspectJAnnotationType.AtBefore);
|
||||
annotationTypeMap.put(After.class, AspectJAnnotationType.AtAfter);
|
||||
annotationTypeMap.put(AfterReturning.class, AspectJAnnotationType.AtAfterReturning);
|
||||
annotationTypeMap.put(AfterThrowing.class, AspectJAnnotationType.AtAfterThrowing);
|
||||
}
|
||||
|
||||
private final A annotation;
|
||||
@@ -192,39 +191,31 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||
public AspectJAnnotation(A annotation) {
|
||||
this.annotation = annotation;
|
||||
this.annotationType = determineAnnotationType(annotation);
|
||||
// We know these methods exist with the same name on each object,
|
||||
// but need to invoke them reflectively as there isn't a common interface.
|
||||
try {
|
||||
this.pointcutExpression = resolveExpression(annotation);
|
||||
this.argumentNames = (String) annotation.getClass().getMethod("argNames").invoke(annotation);
|
||||
Object argNames = AnnotationUtils.getValue(annotation, "argNames");
|
||||
this.argumentNames = (argNames instanceof String ? (String) argNames : "");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalArgumentException(annotation + " cannot be an AspectJ annotation", ex);
|
||||
throw new IllegalArgumentException(annotation + " is not a valid AspectJ annotation", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private AspectJAnnotationType determineAnnotationType(A annotation) {
|
||||
for (Class<?> type : annotationTypes.keySet()) {
|
||||
if (type.isInstance(annotation)) {
|
||||
return annotationTypes.get(type);
|
||||
}
|
||||
AspectJAnnotationType type = annotationTypeMap.get(annotation.annotationType());
|
||||
if (type != null) {
|
||||
return type;
|
||||
}
|
||||
throw new IllegalStateException("Unknown annotation type: " + annotation.toString());
|
||||
throw new IllegalStateException("Unknown annotation type: " + annotation);
|
||||
}
|
||||
|
||||
private String resolveExpression(A annotation) throws Exception {
|
||||
for (String methodName : EXPRESSION_PROPERTIES) {
|
||||
Method method;
|
||||
try {
|
||||
method = annotation.getClass().getDeclaredMethod(methodName);
|
||||
}
|
||||
catch (NoSuchMethodException ex) {
|
||||
method = null;
|
||||
}
|
||||
if (method != null) {
|
||||
String candidate = (String) method.invoke(annotation);
|
||||
if (StringUtils.hasText(candidate)) {
|
||||
return candidate;
|
||||
private String resolveExpression(A annotation) {
|
||||
for (String attributeName : EXPRESSION_ATTRIBUTES) {
|
||||
Object val = AnnotationUtils.getValue(annotation, attributeName);
|
||||
if (val instanceof String) {
|
||||
String str = (String) val;
|
||||
if (!str.isEmpty()) {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -270,11 +261,11 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||
if (annotation == null) {
|
||||
return null;
|
||||
}
|
||||
StringTokenizer strTok = new StringTokenizer(annotation.getArgumentNames(), ",");
|
||||
if (strTok.countTokens() > 0) {
|
||||
String[] names = new String[strTok.countTokens()];
|
||||
StringTokenizer nameTokens = new StringTokenizer(annotation.getArgumentNames(), ",");
|
||||
if (nameTokens.countTokens() > 0) {
|
||||
String[] names = new String[nameTokens.countTokens()];
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
names[i] = strTok.nextToken();
|
||||
names[i] = nameTokens.nextToken();
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.aop.aspectj.annotation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -87,8 +87,8 @@ public class BeanFactoryAspectJAdvisorsBuilder {
|
||||
synchronized (this) {
|
||||
aspectNames = this.aspectBeanNames;
|
||||
if (aspectNames == null) {
|
||||
List<Advisor> advisors = new LinkedList<>();
|
||||
aspectNames = new LinkedList<>();
|
||||
List<Advisor> advisors = new ArrayList<>();
|
||||
aspectNames = new ArrayList<>();
|
||||
String[] beanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
|
||||
this.beanFactory, Object.class, true, false);
|
||||
for (String beanName : beanNames) {
|
||||
@@ -138,7 +138,7 @@ public class BeanFactoryAspectJAdvisorsBuilder {
|
||||
if (aspectNames.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Advisor> advisors = new LinkedList<>();
|
||||
List<Advisor> advisors = new ArrayList<>();
|
||||
for (String aspectName : aspectNames) {
|
||||
List<Advisor> cachedAdvisors = this.advisorsCache.get(aspectName);
|
||||
if (cachedAdvisors != null) {
|
||||
|
||||
+52
-52
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -116,14 +116,41 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||
|
||||
|
||||
/**
|
||||
* The pointcut for Spring AOP to use. Actual behaviour of the pointcut will change
|
||||
* depending on the state of the advice.
|
||||
* The pointcut for Spring AOP to use.
|
||||
* Actual behaviour of the pointcut will change depending on the state of the advice.
|
||||
*/
|
||||
@Override
|
||||
public Pointcut getPointcut() {
|
||||
return this.pointcut;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLazy() {
|
||||
return this.lazy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isAdviceInstantiated() {
|
||||
return (this.instantiatedAdvice != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazily instantiate advice if necessary.
|
||||
*/
|
||||
@Override
|
||||
public synchronized Advice getAdvice() {
|
||||
if (this.instantiatedAdvice == null) {
|
||||
this.instantiatedAdvice = instantiateAdvice(this.declaredPointcut);
|
||||
}
|
||||
return this.instantiatedAdvice;
|
||||
}
|
||||
|
||||
private Advice instantiateAdvice(AspectJExpressionPointcut pointcut) {
|
||||
Advice advice = this.aspectJAdvisorFactory.getAdvice(this.aspectJAdviceMethod, pointcut,
|
||||
this.aspectInstanceFactory, this.declarationOrder, this.aspectName);
|
||||
return (advice != null ? advice : EMPTY_ADVICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is only of interest for Spring AOP: AspectJ instantiation semantics
|
||||
* are much richer. In AspectJ terminology, all a return of {@code true}
|
||||
@@ -141,34 +168,6 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||
return this.aspectInstanceFactory.getAspectMetadata();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazily instantiate advice if necessary.
|
||||
*/
|
||||
@Override
|
||||
public synchronized Advice getAdvice() {
|
||||
if (this.instantiatedAdvice == null) {
|
||||
this.instantiatedAdvice = instantiateAdvice(this.declaredPointcut);
|
||||
}
|
||||
return this.instantiatedAdvice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLazy() {
|
||||
return this.lazy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isAdviceInstantiated() {
|
||||
return (this.instantiatedAdvice != null);
|
||||
}
|
||||
|
||||
|
||||
private Advice instantiateAdvice(AspectJExpressionPointcut pointcut) {
|
||||
Advice advice = this.aspectJAdvisorFactory.getAdvice(this.aspectJAdviceMethod, pointcut,
|
||||
this.aspectInstanceFactory, this.declarationOrder, this.aspectName);
|
||||
return (advice != null ? advice : EMPTY_ADVICE);
|
||||
}
|
||||
|
||||
public MetadataAwareAspectInstanceFactory getAspectInstanceFactory() {
|
||||
return this.aspectInstanceFactory;
|
||||
}
|
||||
@@ -221,33 +220,26 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||
}
|
||||
else {
|
||||
switch (aspectJAnnotation.getAnnotationType()) {
|
||||
case AtPointcut:
|
||||
case AtAround:
|
||||
this.isBeforeAdvice = false;
|
||||
this.isAfterAdvice = false;
|
||||
break;
|
||||
case AtBefore:
|
||||
this.isBeforeAdvice = true;
|
||||
this.isAfterAdvice = false;
|
||||
break;
|
||||
case AtAfter:
|
||||
case AtAfterReturning:
|
||||
case AtAfterThrowing:
|
||||
this.isBeforeAdvice = false;
|
||||
this.isAfterAdvice = true;
|
||||
this.isBeforeAdvice = false;
|
||||
break;
|
||||
case AtAround:
|
||||
case AtPointcut:
|
||||
this.isAfterAdvice = false;
|
||||
this.isBeforeAdvice = false;
|
||||
break;
|
||||
case AtBefore:
|
||||
this.isAfterAdvice = false;
|
||||
this.isBeforeAdvice = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "InstantiationModelAwarePointcutAdvisor: expression [" + getDeclaredPointcut().getExpression() +
|
||||
"]; advice method [" + this.aspectJAdviceMethod + "]; perClauseKind=" +
|
||||
this.aspectInstanceFactory.getAspectMetadata().getAjType().getPerClause().getKind();
|
||||
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream inputStream) throws IOException, ClassNotFoundException {
|
||||
inputStream.defaultReadObject();
|
||||
try {
|
||||
@@ -258,11 +250,18 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "InstantiationModelAwarePointcutAdvisor: expression [" + getDeclaredPointcut().getExpression() +
|
||||
"]; advice method [" + this.aspectJAdviceMethod + "]; perClauseKind=" +
|
||||
this.aspectInstanceFactory.getAspectMetadata().getAjType().getPerClause().getKind();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pointcut implementation that changes its behaviour when the advice is instantiated.
|
||||
* Note that this is a <i>dynamic</i> pointcut. Otherwise it might
|
||||
* be optimized out if it does not at first match statically.
|
||||
* Note that this is a <i>dynamic</i> pointcut; otherwise it might be optimized out
|
||||
* if it does not at first match statically.
|
||||
*/
|
||||
private class PerTargetInstantiationModelPointcut extends DynamicMethodMatcherPointcut {
|
||||
|
||||
@@ -273,7 +272,7 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||
@Nullable
|
||||
private LazySingletonAspectInstanceFactoryDecorator aspectInstanceFactory;
|
||||
|
||||
private PerTargetInstantiationModelPointcut(AspectJExpressionPointcut declaredPointcut,
|
||||
public PerTargetInstantiationModelPointcut(AspectJExpressionPointcut declaredPointcut,
|
||||
Pointcut preInstantiationPointcut, MetadataAwareAspectInstanceFactory aspectInstanceFactory) {
|
||||
|
||||
this.declaredPointcut = declaredPointcut;
|
||||
@@ -285,7 +284,8 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||
|
||||
@Override
|
||||
public boolean matches(Method method, @Nullable Class<?> targetClass) {
|
||||
// We're either instantiated and matching on declared pointcut, or uninstantiated matching on either pointcut
|
||||
// We're either instantiated and matching on declared pointcut,
|
||||
// or uninstantiated matching on either pointcut...
|
||||
return (isAspectMaterialized() && this.declaredPointcut.matches(method, targetClass)) ||
|
||||
this.preInstantiationPointcut.getMethodMatcher().matches(method, targetClass);
|
||||
}
|
||||
|
||||
+12
-12
@@ -20,8 +20,8 @@ import java.io.Serializable;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.aopalliance.aop.Advice;
|
||||
@@ -121,7 +121,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
MetadataAwareAspectInstanceFactory lazySingletonAspectInstanceFactory =
|
||||
new LazySingletonAspectInstanceFactoryDecorator(aspectInstanceFactory);
|
||||
|
||||
List<Advisor> advisors = new LinkedList<>();
|
||||
List<Advisor> advisors = new ArrayList<>();
|
||||
for (Method method : getAdvisorMethods(aspectClass)) {
|
||||
Advisor advisor = getAdvisor(method, lazySingletonAspectInstanceFactory, advisors.size(), aspectName);
|
||||
if (advisor != null) {
|
||||
@@ -147,7 +147,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
}
|
||||
|
||||
private List<Method> getAdvisorMethods(Class<?> aspectClass) {
|
||||
final List<Method> methods = new LinkedList<>();
|
||||
final List<Method> methods = new ArrayList<>();
|
||||
ReflectionUtils.doWithMethods(aspectClass, method -> {
|
||||
// Exclude pointcuts
|
||||
if (AnnotationUtils.getAnnotation(method, Pointcut.class) == null) {
|
||||
@@ -246,6 +246,15 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
AbstractAspectJAdvice springAdvice;
|
||||
|
||||
switch (aspectJAnnotation.getAnnotationType()) {
|
||||
case AtPointcut:
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Processing pointcut '" + candidateAdviceMethod.getName() + "'");
|
||||
}
|
||||
return null;
|
||||
case AtAround:
|
||||
springAdvice = new AspectJAroundAdvice(
|
||||
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
|
||||
break;
|
||||
case AtBefore:
|
||||
springAdvice = new AspectJMethodBeforeAdvice(
|
||||
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
|
||||
@@ -270,15 +279,6 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
springAdvice.setThrowingName(afterThrowingAnnotation.throwing());
|
||||
}
|
||||
break;
|
||||
case AtAround:
|
||||
springAdvice = new AspectJAroundAdvice(
|
||||
candidateAdviceMethod, expressionPointcut, aspectInstanceFactory);
|
||||
break;
|
||||
case AtPointcut:
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Processing pointcut '" + candidateAdviceMethod.getName() + "'");
|
||||
}
|
||||
return null;
|
||||
default:
|
||||
throw new UnsupportedOperationException(
|
||||
"Unsupported advice type on method: " + candidateAdviceMethod);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,11 +32,10 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* Utility class for handling registration of AOP auto-proxy creators.
|
||||
*
|
||||
* <p>Only a single auto-proxy creator can be registered yet multiple concrete
|
||||
* implementations are available. Therefore this class wraps a simple escalation
|
||||
* protocol, allowing classes to request a particular auto-proxy creator and know
|
||||
* that class, {@code or a subclass thereof}, will eventually be resident
|
||||
* in the application context.
|
||||
* <p>Only a single auto-proxy creator should be registered yet multiple concrete
|
||||
* implementations are available. This class provides a simple escalation protocol,
|
||||
* allowing a caller to request a particular auto-proxy creator and know that creator,
|
||||
* <i>or a more capable variant thereof</i>, will be registered as a post-processor.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
@@ -55,12 +54,10 @@ public abstract class AopConfigUtils {
|
||||
/**
|
||||
* Stores the auto proxy creator classes in escalation order.
|
||||
*/
|
||||
private static final List<Class<?>> APC_PRIORITY_LIST = new ArrayList<>();
|
||||
private static final List<Class<?>> APC_PRIORITY_LIST = new ArrayList<>(3);
|
||||
|
||||
/**
|
||||
* Setup the escalation list.
|
||||
*/
|
||||
static {
|
||||
// Set up the escalation list...
|
||||
APC_PRIORITY_LIST.add(InfrastructureAdvisorAutoProxyCreator.class);
|
||||
APC_PRIORITY_LIST.add(AspectJAwareAdvisorAutoProxyCreator.class);
|
||||
APC_PRIORITY_LIST.add(AnnotationAwareAspectJAutoProxyCreator.class);
|
||||
@@ -73,8 +70,8 @@ public abstract class AopConfigUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static BeanDefinition registerAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry,
|
||||
@Nullable Object source) {
|
||||
public static BeanDefinition registerAutoProxyCreatorIfNecessary(
|
||||
BeanDefinitionRegistry registry, @Nullable Object source) {
|
||||
|
||||
return registerOrEscalateApcAsRequired(InfrastructureAdvisorAutoProxyCreator.class, registry, source);
|
||||
}
|
||||
@@ -85,8 +82,8 @@ public abstract class AopConfigUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static BeanDefinition registerAspectJAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry,
|
||||
@Nullable Object source) {
|
||||
public static BeanDefinition registerAspectJAutoProxyCreatorIfNecessary(
|
||||
BeanDefinitionRegistry registry, @Nullable Object source) {
|
||||
|
||||
return registerOrEscalateApcAsRequired(AspectJAwareAdvisorAutoProxyCreator.class, registry, source);
|
||||
}
|
||||
@@ -97,8 +94,8 @@ public abstract class AopConfigUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry,
|
||||
@Nullable Object source) {
|
||||
public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(
|
||||
BeanDefinitionRegistry registry, @Nullable Object source) {
|
||||
|
||||
return registerOrEscalateApcAsRequired(AnnotationAwareAspectJAutoProxyCreator.class, registry, source);
|
||||
}
|
||||
@@ -118,8 +115,8 @@ public abstract class AopConfigUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static BeanDefinition registerOrEscalateApcAsRequired(Class<?> cls, BeanDefinitionRegistry registry,
|
||||
@Nullable Object source) {
|
||||
private static BeanDefinition registerOrEscalateApcAsRequired(
|
||||
Class<?> cls, BeanDefinitionRegistry registry, @Nullable Object source) {
|
||||
|
||||
Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,11 +28,11 @@ import org.springframework.lang.Nullable;
|
||||
* Utility class for handling registration of auto-proxy creators used internally
|
||||
* by the '{@code aop}' namespace tags.
|
||||
*
|
||||
* <p>Only a single auto-proxy creator can be registered and multiple tags may wish
|
||||
* to register different concrete implementations. As such this class delegates to
|
||||
* {@link AopConfigUtils} which wraps a simple escalation protocol. Therefore classes
|
||||
* may request a particular auto-proxy creator and know that class, <i>or a subclass
|
||||
* thereof</i>, will eventually be resident in the application context.
|
||||
* <p>Only a single auto-proxy creator should be registered and multiple configuration
|
||||
* elements may wish to register different concrete implementations. As such this class
|
||||
* delegates to {@link AopConfigUtils} which provides a simple escalation protocol.
|
||||
* Callers may request a particular auto-proxy creator and know that creator,
|
||||
* <i>or a more capable variant thereof</i>, will be registered as a post-processor.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
@@ -95,9 +95,8 @@ public abstract class AopNamespaceUtils {
|
||||
|
||||
private static void registerComponentIfNecessary(@Nullable BeanDefinition beanDefinition, ParserContext parserContext) {
|
||||
if (beanDefinition != null) {
|
||||
BeanComponentDefinition componentDefinition =
|
||||
new BeanComponentDefinition(beanDefinition, AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
|
||||
parserContext.registerComponent(componentDefinition);
|
||||
parserContext.registerComponent(
|
||||
new BeanComponentDefinition(beanDefinition, AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -63,7 +63,7 @@ public abstract class AbstractAdvisingBeanPostProcessor extends ProxyProcessorSu
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) {
|
||||
if (bean instanceof AopInfrastructureBean || this.advisor == null) {
|
||||
if (this.advisor == null || bean instanceof AopInfrastructureBean) {
|
||||
// Ignore AOP infrastructure such as scoped proxies.
|
||||
return bean;
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public abstract class AbstractAdvisingBeanPostProcessor extends ProxyProcessorSu
|
||||
return proxyFactory.getProxy(getProxyClassLoader());
|
||||
}
|
||||
|
||||
// No async proxy needed.
|
||||
// No proxy needed.
|
||||
return bean;
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ public abstract class AbstractAdvisingBeanPostProcessor extends ProxyProcessorSu
|
||||
* Subclasses may choose to implement this: for example,
|
||||
* to change the interfaces exposed.
|
||||
* <p>The default implementation is empty.
|
||||
* @param proxyFactory ProxyFactory that is already configured with
|
||||
* @param proxyFactory the ProxyFactory that is already configured with
|
||||
* target, advisor and interfaces and will be used to create the proxy
|
||||
* immediately after this method returns
|
||||
* @since 4.2.3
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -94,7 +93,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
* List of Advisors. If an Advice is added, it will be wrapped
|
||||
* in an Advisor before being added to this List.
|
||||
*/
|
||||
private List<Advisor> advisors = new LinkedList<>();
|
||||
private List<Advisor> advisors = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Array updated on changes to the advisors list, which is easier
|
||||
@@ -153,11 +152,12 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
* @see #setTargetSource
|
||||
* @see #setTarget
|
||||
*/
|
||||
public void setTargetClass(Class<?> targetClass) {
|
||||
public void setTargetClass(@Nullable Class<?> targetClass) {
|
||||
this.targetSource = EmptyTargetSource.forClass(targetClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Class<?> getTargetClass() {
|
||||
return this.targetSource.getTargetClass();
|
||||
}
|
||||
@@ -474,7 +474,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
* for the given method, based on this configuration.
|
||||
* @param method the proxied method
|
||||
* @param targetClass the target class
|
||||
* @return List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
|
||||
* @return a List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
|
||||
*/
|
||||
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(Method method, @Nullable Class<?> targetClass) {
|
||||
MethodCacheKey cacheKey = new MethodCacheKey(method);
|
||||
@@ -528,7 +528,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
|
||||
/**
|
||||
* Build a configuration-only copy of this AdvisedSupport,
|
||||
* replacing the TargetSource
|
||||
* replacing the TargetSource.
|
||||
*/
|
||||
AdvisedSupport getConfigurationOnlyCopy() {
|
||||
AdvisedSupport copy = new AdvisedSupport();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -205,9 +205,8 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||
return createProxyClassAndInstance(enhancer, callbacks);
|
||||
}
|
||||
catch (CodeGenerationException | IllegalArgumentException ex) {
|
||||
throw new AopConfigException("Could not generate CGLIB subclass of class [" +
|
||||
this.advised.getTargetClass() + "]: " +
|
||||
"Common causes of this problem include using a final class or a non-visible class",
|
||||
throw new AopConfigException("Could not generate CGLIB subclass of " + this.advised.getTargetClass() +
|
||||
": Common causes of this problem include using a final class or a non-visible class",
|
||||
ex);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
@@ -292,20 +291,20 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||
// unadvised but can return this). May be required to expose the proxy.
|
||||
Callback targetInterceptor;
|
||||
if (exposeProxy) {
|
||||
targetInterceptor = isStatic ?
|
||||
targetInterceptor = (isStatic ?
|
||||
new StaticUnadvisedExposedInterceptor(this.advised.getTargetSource().getTarget()) :
|
||||
new DynamicUnadvisedExposedInterceptor(this.advised.getTargetSource());
|
||||
new DynamicUnadvisedExposedInterceptor(this.advised.getTargetSource()));
|
||||
}
|
||||
else {
|
||||
targetInterceptor = isStatic ?
|
||||
targetInterceptor = (isStatic ?
|
||||
new StaticUnadvisedInterceptor(this.advised.getTargetSource().getTarget()) :
|
||||
new DynamicUnadvisedInterceptor(this.advised.getTargetSource());
|
||||
new DynamicUnadvisedInterceptor(this.advised.getTargetSource()));
|
||||
}
|
||||
|
||||
// Choose a "direct to target" dispatcher (used for
|
||||
// unadvised calls to static targets that cannot return this).
|
||||
Callback targetDispatcher = isStatic ?
|
||||
new StaticDispatcher(this.advised.getTargetSource().getTarget()) : new SerializableNoOp();
|
||||
Callback targetDispatcher = (isStatic ?
|
||||
new StaticDispatcher(this.advised.getTargetSource().getTarget()) : new SerializableNoOp());
|
||||
|
||||
Callback[] mainCallbacks = new Callback[] {
|
||||
aopInterceptor, // for normal advice
|
||||
@@ -823,12 +822,16 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||
}
|
||||
// We must always proxy equals, to direct calls to this.
|
||||
if (AopUtils.isEqualsMethod(method)) {
|
||||
logger.debug("Found 'equals' method: " + method);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Found 'equals' method: " + method);
|
||||
}
|
||||
return INVOKE_EQUALS;
|
||||
}
|
||||
// We must always calculate hashCode based on the proxy.
|
||||
if (AopUtils.isHashCodeMethod(method)) {
|
||||
logger.debug("Found 'hashCode' method: " + method);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Found 'hashCode' method: " + method);
|
||||
}
|
||||
return INVOKE_HASHCODE;
|
||||
}
|
||||
Class<?> targetClass = this.advised.getTargetClass();
|
||||
|
||||
+4
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -53,7 +53,7 @@ public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializ
|
||||
|
||||
// This is somewhat tricky... We have to process introductions first,
|
||||
// but we need to preserve order in the ultimate list.
|
||||
List<Object> interceptorList = new ArrayList<>(config.getAdvisors().length);
|
||||
List<Object> interceptorList = new ArrayList<Object>(config.getAdvisors().length);
|
||||
Class<?> actualClass = (targetClass != null ? targetClass : method.getDeclaringClass());
|
||||
boolean hasIntroductions = hasMatchingIntroductions(config, actualClass);
|
||||
AdvisorAdapterRegistry registry = GlobalAdvisorAdapterRegistry.getInstance();
|
||||
@@ -63,9 +63,9 @@ public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializ
|
||||
// Add it conditionally.
|
||||
PointcutAdvisor pointcutAdvisor = (PointcutAdvisor) advisor;
|
||||
if (config.isPreFiltered() || pointcutAdvisor.getPointcut().getClassFilter().matches(actualClass)) {
|
||||
MethodInterceptor[] interceptors = registry.getInterceptors(advisor);
|
||||
MethodMatcher mm = pointcutAdvisor.getPointcut().getMethodMatcher();
|
||||
if (MethodMatchers.matches(mm, method, actualClass, hasIntroductions)) {
|
||||
MethodInterceptor[] interceptors = registry.getInterceptors(advisor);
|
||||
if (mm.isRuntime()) {
|
||||
// Creating a new object instance in the getInterceptors() method
|
||||
// isn't a problem as we normally cache created chains.
|
||||
@@ -99,8 +99,7 @@ public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializ
|
||||
* Determine whether the Advisors contain matching introductions.
|
||||
*/
|
||||
private static boolean hasMatchingIntroductions(Advised config, Class<?> actualClass) {
|
||||
for (int i = 0; i < config.getAdvisors().length; i++) {
|
||||
Advisor advisor = config.getAdvisors()[i];
|
||||
for (Advisor advisor : config.getAdvisors()) {
|
||||
if (advisor instanceof IntroductionAdvisor) {
|
||||
IntroductionAdvisor ia = (IntroductionAdvisor) advisor;
|
||||
if (ia.getClassFilter().matches(actualClass)) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,7 +34,7 @@ public class ProxyCreatorSupport extends AdvisedSupport {
|
||||
|
||||
private AopProxyFactory aopProxyFactory;
|
||||
|
||||
private List<AdvisedSupportListener> listeners = new LinkedList<>();
|
||||
private final List<AdvisedSupportListener> listeners = new LinkedList<>();
|
||||
|
||||
/** Set to true when the first AOP proxy has been created */
|
||||
private boolean active = false;
|
||||
|
||||
@@ -651,7 +651,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||
}
|
||||
|
||||
public String getBeanName() {
|
||||
return beanName;
|
||||
return this.beanName;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+10
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,15 +31,15 @@ import org.springframework.aop.Advisor;
|
||||
public interface AdvisorAdapterRegistry {
|
||||
|
||||
/**
|
||||
* Return an Advisor wrapping the given advice.
|
||||
* Return an {@link Advisor} wrapping the given advice.
|
||||
* <p>Should by default at least support
|
||||
* {@link org.aopalliance.intercept.MethodInterceptor},
|
||||
* {@link org.springframework.aop.MethodBeforeAdvice},
|
||||
* {@link org.springframework.aop.AfterReturningAdvice},
|
||||
* {@link org.springframework.aop.ThrowsAdvice}.
|
||||
* @param advice object that should be an advice
|
||||
* @return an Advisor wrapping the given advice. Never returns {@code null}.
|
||||
* If the advice parameter is an Advisor, return it.
|
||||
* @return an Advisor wrapping the given advice (never {@code null};
|
||||
* if the advice parameter is an Advisor, it is to be returned as-is)
|
||||
* @throws UnknownAdviceTypeException if no registered advisor adapter
|
||||
* can wrap the supposed advice
|
||||
*/
|
||||
@@ -48,21 +48,20 @@ public interface AdvisorAdapterRegistry {
|
||||
/**
|
||||
* Return an array of AOP Alliance MethodInterceptors to allow use of the
|
||||
* given Advisor in an interception-based framework.
|
||||
* <p>Don't worry about the pointcut associated with the Advisor,
|
||||
* if it's a PointcutAdvisor: just return an interceptor.
|
||||
* <p>Don't worry about the pointcut associated with the {@link Advisor}, if it is
|
||||
* a {@link org.springframework.aop.PointcutAdvisor}: just return an interceptor.
|
||||
* @param advisor Advisor to find an interceptor for
|
||||
* @return an array of MethodInterceptors to expose this Advisor's behavior
|
||||
* @throws UnknownAdviceTypeException if the Advisor type is
|
||||
* not understood by any registered AdvisorAdapter.
|
||||
* not understood by any registered AdvisorAdapter
|
||||
*/
|
||||
MethodInterceptor[] getInterceptors(Advisor advisor) throws UnknownAdviceTypeException;
|
||||
|
||||
/**
|
||||
* Register the given AdvisorAdapter. Note that it is not necessary to register
|
||||
* Register the given {@link AdvisorAdapter}. Note that it is not necessary to register
|
||||
* adapters for an AOP Alliance Interceptors or Spring Advices: these must be
|
||||
* automatically recognized by an AdvisorAdapterRegistry implementation.
|
||||
* @param adapter AdvisorAdapter that understands a particular Advisor
|
||||
* or Advice types
|
||||
* automatically recognized by an {@code AdvisorAdapterRegistry} implementation.
|
||||
* @param adapter AdvisorAdapter that understands particular Advisor or Advice types
|
||||
*/
|
||||
void registerAdvisorAdapter(AdvisorAdapter adapter);
|
||||
|
||||
|
||||
+4
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,8 @@ import org.springframework.util.Assert;
|
||||
* to use this class directly.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @see MethodBeforeAdviceInterceptor
|
||||
* @see ThrowsAdviceInterceptor
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class AfterReturningAdviceInterceptor implements MethodInterceptor, AfterAdvice, Serializable {
|
||||
@@ -47,6 +49,7 @@ public class AfterReturningAdviceInterceptor implements MethodInterceptor, After
|
||||
this.advice = advice;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
Object retVal = mi.proceed();
|
||||
|
||||
+8
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,7 @@ import java.io.Serializable;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.aop.BeforeAdvice;
|
||||
import org.springframework.aop.MethodBeforeAdvice;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -30,11 +31,13 @@ import org.springframework.util.Assert;
|
||||
* to use this class directly.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @see AfterReturningAdviceInterceptor
|
||||
* @see ThrowsAdviceInterceptor
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class MethodBeforeAdviceInterceptor implements MethodInterceptor, Serializable {
|
||||
public class MethodBeforeAdviceInterceptor implements MethodInterceptor, BeforeAdvice, Serializable {
|
||||
|
||||
private MethodBeforeAdvice advice;
|
||||
private final MethodBeforeAdvice advice;
|
||||
|
||||
|
||||
/**
|
||||
@@ -46,9 +49,10 @@ public class MethodBeforeAdviceInterceptor implements MethodInterceptor, Seriali
|
||||
this.advice = advice;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
this.advice.before(mi.getMethod(), mi.getArguments(), mi.getThis() );
|
||||
this.advice.before(mi.getMethod(), mi.getArguments(), mi.getThis());
|
||||
return mi.proceed();
|
||||
}
|
||||
|
||||
|
||||
+35
-28
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,6 +51,8 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @see MethodBeforeAdviceInterceptor
|
||||
* @see AfterReturningAdviceInterceptor
|
||||
*/
|
||||
public class ThrowsAdviceInterceptor implements MethodInterceptor, AfterAdvice {
|
||||
|
||||
@@ -67,9 +69,8 @@ public class ThrowsAdviceInterceptor implements MethodInterceptor, AfterAdvice {
|
||||
|
||||
/**
|
||||
* Create a new ThrowsAdviceInterceptor for the given ThrowsAdvice.
|
||||
* @param throwsAdvice the advice object that defines the exception
|
||||
* handler methods (usually a {@link org.springframework.aop.ThrowsAdvice}
|
||||
* implementation)
|
||||
* @param throwsAdvice the advice object that defines the exception handler methods
|
||||
* (usually a {@link org.springframework.aop.ThrowsAdvice} implementation)
|
||||
*/
|
||||
public ThrowsAdviceInterceptor(Object throwsAdvice) {
|
||||
Assert.notNull(throwsAdvice, "Advice must not be null");
|
||||
@@ -78,13 +79,14 @@ public class ThrowsAdviceInterceptor implements MethodInterceptor, AfterAdvice {
|
||||
Method[] methods = throwsAdvice.getClass().getMethods();
|
||||
for (Method method : methods) {
|
||||
if (method.getName().equals(AFTER_THROWING) &&
|
||||
(method.getParameterCount() == 1 || method.getParameterCount() == 4) &&
|
||||
Throwable.class.isAssignableFrom(method.getParameterTypes()[method.getParameterCount() - 1])
|
||||
) {
|
||||
// Have an exception handler
|
||||
this.exceptionHandlerMap.put(method.getParameterTypes()[method.getParameterCount() - 1], method);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Found exception handler method: " + method);
|
||||
(method.getParameterCount() == 1 || method.getParameterCount() == 4)) {
|
||||
Class<?> throwableParam = method.getParameterTypes()[method.getParameterCount() - 1];
|
||||
if (Throwable.class.isAssignableFrom(throwableParam)) {
|
||||
// An exception handler to register...
|
||||
this.exceptionHandlerMap.put(throwableParam, method);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Found exception handler method on throws advice: " + method);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,14 +97,33 @@ public class ThrowsAdviceInterceptor implements MethodInterceptor, AfterAdvice {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the number of handler methods in this advice.
|
||||
*/
|
||||
public int getHandlerMethodCount() {
|
||||
return this.exceptionHandlerMap.size();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
try {
|
||||
return mi.proceed();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
Method handlerMethod = getExceptionHandler(ex);
|
||||
if (handlerMethod != null) {
|
||||
invokeHandlerMethod(mi, ex, handlerMethod);
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the exception handle method. Can return null if not found.
|
||||
* Determine the exception handle method for the given exception.
|
||||
* @param exception the exception thrown
|
||||
* @return a handler for the given exception type
|
||||
* @return a handler for the given exception type, or {@code null} if none found
|
||||
*/
|
||||
@Nullable
|
||||
private Method getExceptionHandler(Throwable exception) {
|
||||
@@ -121,24 +142,10 @@ public class ThrowsAdviceInterceptor implements MethodInterceptor, AfterAdvice {
|
||||
return handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
try {
|
||||
return mi.proceed();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
Method handlerMethod = getExceptionHandler(ex);
|
||||
if (handlerMethod != null) {
|
||||
invokeHandlerMethod(mi, ex, handlerMethod);
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
private void invokeHandlerMethod(MethodInvocation mi, Throwable ex, Method method) throws Throwable {
|
||||
Object[] handlerArgs;
|
||||
if (method.getParameterCount() == 1) {
|
||||
handlerArgs = new Object[] { ex };
|
||||
handlerArgs = new Object[] {ex};
|
||||
}
|
||||
else {
|
||||
handlerArgs = new Object[] {mi.getMethod(), mi.getArguments(), mi.getThis(), ex};
|
||||
|
||||
+2
-2
@@ -419,7 +419,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
||||
// Found a matching TargetSource.
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("TargetSourceCreator [" + tsc +
|
||||
" found custom TargetSource for bean with name '" + beanName + "'");
|
||||
"] found custom TargetSource for bean with name '" + beanName + "'");
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
@@ -561,7 +561,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
||||
* Subclasses may choose to implement this: for example,
|
||||
* to change the interfaces exposed.
|
||||
* <p>The default implementation is empty.
|
||||
* @param proxyFactory ProxyFactory that is already configured with
|
||||
* @param proxyFactory a ProxyFactory that is already configured with
|
||||
* TargetSource and interfaces and will be used to create the proxy
|
||||
* immediately after this method returns
|
||||
*/
|
||||
|
||||
+12
-15
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.aop.framework.autoproxy;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -45,7 +45,7 @@ public class BeanFactoryAdvisorRetrievalHelper {
|
||||
private final ConfigurableListableBeanFactory beanFactory;
|
||||
|
||||
@Nullable
|
||||
private String[] cachedAdvisorBeanNames;
|
||||
private volatile String[] cachedAdvisorBeanNames;
|
||||
|
||||
|
||||
/**
|
||||
@@ -66,22 +66,19 @@ public class BeanFactoryAdvisorRetrievalHelper {
|
||||
*/
|
||||
public List<Advisor> findAdvisorBeans() {
|
||||
// Determine list of advisor bean names, if not cached already.
|
||||
String[] advisorNames = null;
|
||||
synchronized (this) {
|
||||
advisorNames = this.cachedAdvisorBeanNames;
|
||||
if (advisorNames == null) {
|
||||
// Do not initialize FactoryBeans here: We need to leave all regular beans
|
||||
// uninitialized to let the auto-proxy creator apply to them!
|
||||
advisorNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
|
||||
this.beanFactory, Advisor.class, true, false);
|
||||
this.cachedAdvisorBeanNames = advisorNames;
|
||||
}
|
||||
String[] advisorNames = this.cachedAdvisorBeanNames;
|
||||
if (advisorNames == null) {
|
||||
// Do not initialize FactoryBeans here: We need to leave all regular beans
|
||||
// uninitialized to let the auto-proxy creator apply to them!
|
||||
advisorNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
|
||||
this.beanFactory, Advisor.class, true, false);
|
||||
this.cachedAdvisorBeanNames = advisorNames;
|
||||
}
|
||||
if (advisorNames.length == 0) {
|
||||
return new LinkedList<>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<Advisor> advisors = new LinkedList<>();
|
||||
List<Advisor> advisors = new ArrayList<>();
|
||||
for (String name : advisorNames) {
|
||||
if (isEligibleBean(name)) {
|
||||
if (this.beanFactory.isCurrentlyInCreation(name)) {
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,13 +29,13 @@ import org.apache.commons.logging.LogFactory;
|
||||
*/
|
||||
public class SimpleAsyncUncaughtExceptionHandler implements AsyncUncaughtExceptionHandler {
|
||||
|
||||
private final Log logger = LogFactory.getLog(SimpleAsyncUncaughtExceptionHandler.class);
|
||||
private static final Log logger = LogFactory.getLog(SimpleAsyncUncaughtExceptionHandler.class);
|
||||
|
||||
|
||||
@Override
|
||||
public void handleUncaughtException(Throwable ex, Method method, Object... params) {
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error(String.format("Unexpected error occurred invoking async " +
|
||||
"method '%s'.", method), ex);
|
||||
logger.error("Unexpected error occurred invoking async method: " + method, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -52,7 +52,8 @@ import org.springframework.util.ClassUtils;
|
||||
* @see #setProxyTargetClass
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ScopedProxyFactoryBean extends ProxyConfig implements FactoryBean<Object>, BeanFactoryAware {
|
||||
public class ScopedProxyFactoryBean extends ProxyConfig
|
||||
implements FactoryBean<Object>, BeanFactoryAware, AopInfrastructureBean {
|
||||
|
||||
/** The TargetSource that manages scoping */
|
||||
private final SimpleBeanTargetSource scopedTargetSource = new SimpleBeanTargetSource();
|
||||
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -131,8 +131,9 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
|
||||
*/
|
||||
@Override
|
||||
public boolean matches(Method method, @Nullable Class<?> targetClass) {
|
||||
return ((targetClass != null && matchesPattern(ClassUtils.getQualifiedMethodName(method, targetClass))) ||
|
||||
matchesPattern(ClassUtils.getQualifiedMethodName(method)));
|
||||
return ((targetClass != null && targetClass != method.getDeclaringClass() &&
|
||||
matchesPattern(ClassUtils.getQualifiedMethodName(method, targetClass))) ||
|
||||
matchesPattern(ClassUtils.getQualifiedMethodName(method, method.getDeclaringClass())));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -192,8 +192,7 @@ public abstract class AopUtils {
|
||||
* @see org.springframework.util.ClassUtils#getMostSpecificMethod
|
||||
*/
|
||||
public static Method getMostSpecificMethod(Method method, @Nullable Class<?> targetClass) {
|
||||
Class<?> specificTargetClass = (targetClass != null && !Proxy.isProxyClass(targetClass) ?
|
||||
ClassUtils.getUserClass(targetClass) : null);
|
||||
Class<?> specificTargetClass = (targetClass != null ? ClassUtils.getUserClass(targetClass) : null);
|
||||
Method resolvedMethod = ClassUtils.getMostSpecificMethod(method, specificTargetClass);
|
||||
// If we are dealing with method with generic parameters, find the original method.
|
||||
return BridgeMethodResolver.findBridgedMethod(resolvedMethod);
|
||||
@@ -247,8 +246,8 @@ public abstract class AopUtils {
|
||||
for (Class<?> clazz : classes) {
|
||||
Method[] methods = ReflectionUtils.getAllDeclaredMethods(clazz);
|
||||
for (Method method : methods) {
|
||||
if ((introductionAwareMethodMatcher != null &&
|
||||
introductionAwareMethodMatcher.matches(method, targetClass, hasIntroductions)) ||
|
||||
if (introductionAwareMethodMatcher != null ?
|
||||
introductionAwareMethodMatcher.matches(method, targetClass, hasIntroductions) :
|
||||
methodMatcher.matches(method, targetClass)) {
|
||||
return true;
|
||||
}
|
||||
@@ -306,7 +305,7 @@ public abstract class AopUtils {
|
||||
if (candidateAdvisors.isEmpty()) {
|
||||
return candidateAdvisors;
|
||||
}
|
||||
List<Advisor> eligibleAdvisors = new LinkedList<>();
|
||||
List<Advisor> eligibleAdvisors = new ArrayList<>();
|
||||
for (Advisor candidate : candidateAdvisors) {
|
||||
if (candidate instanceof IntroductionAdvisor && canApply(candidate, clazz)) {
|
||||
eligibleAdvisors.add(candidate);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -131,7 +131,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher
|
||||
return false;
|
||||
}
|
||||
ControlFlowPointcut that = (ControlFlowPointcut) other;
|
||||
return (this.clazz.equals(that.clazz)) && ObjectUtils.nullSafeEquals(that.methodName, this.methodName);
|
||||
return (this.clazz.equals(that.clazz)) && ObjectUtils.nullSafeEquals(this.methodName, that.methodName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,8 @@ import org.springframework.lang.Nullable;
|
||||
/**
|
||||
* Convenient abstract superclass for dynamic method matchers,
|
||||
* which do care about arguments at runtime.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public abstract class DynamicMethodMatcher implements MethodMatcher {
|
||||
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import org.springframework.aop.Pointcut;
|
||||
* Convenient superclass when we want to force subclasses to
|
||||
* implement MethodMatcher interface, but subclasses
|
||||
* will want to be pointcuts. The getClassFilter() method can
|
||||
* be overriden to customize ClassFilter behaviour as well.
|
||||
* be overridden to customize ClassFilter behaviour as well.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -90,8 +90,8 @@ public abstract class MethodMatchers {
|
||||
*/
|
||||
public static boolean matches(MethodMatcher mm, Method method, @Nullable Class<?> targetClass, boolean hasIntroductions) {
|
||||
Assert.notNull(mm, "MethodMatcher must not be null");
|
||||
return ((mm instanceof IntroductionAwareMethodMatcher &&
|
||||
((IntroductionAwareMethodMatcher) mm).matches(method, targetClass, hasIntroductions)) ||
|
||||
return (mm instanceof IntroductionAwareMethodMatcher ?
|
||||
((IntroductionAwareMethodMatcher) mm).matches(method, targetClass, hasIntroductions) :
|
||||
mm.matches(method, targetClass));
|
||||
}
|
||||
|
||||
@@ -144,23 +144,20 @@ public abstract class MethodMatchers {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof UnionMethodMatcher)) {
|
||||
if (!(other instanceof UnionMethodMatcher)) {
|
||||
return false;
|
||||
}
|
||||
UnionMethodMatcher that = (UnionMethodMatcher) obj;
|
||||
UnionMethodMatcher that = (UnionMethodMatcher) other;
|
||||
return (this.mm1.equals(that.mm1) && this.mm2.equals(that.mm2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hashCode = 17;
|
||||
hashCode = 37 * hashCode + this.mm1.hashCode();
|
||||
hashCode = 37 * hashCode + this.mm2.hashCode();
|
||||
return hashCode;
|
||||
return 37 * this.mm1.hashCode() + this.mm2.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,6 +206,12 @@ public abstract class MethodMatchers {
|
||||
}
|
||||
return (this.cf1.equals(otherCf1) && this.cf2.equals(otherCf2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
// Allow for matching with regular UnionMethodMatcher by providing same hash...
|
||||
return super.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -231,18 +234,18 @@ public abstract class MethodMatchers {
|
||||
|
||||
@Override
|
||||
public boolean matches(Method method, @Nullable Class<?> targetClass, boolean hasIntroductions) {
|
||||
return MethodMatchers.matches(this.mm1, method, targetClass, hasIntroductions) &&
|
||||
MethodMatchers.matches(this.mm2, method, targetClass, hasIntroductions);
|
||||
return (MethodMatchers.matches(this.mm1, method, targetClass, hasIntroductions) &&
|
||||
MethodMatchers.matches(this.mm2, method, targetClass, hasIntroductions));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Method method, @Nullable Class<?> targetClass) {
|
||||
return this.mm1.matches(method, targetClass) && this.mm2.matches(method, targetClass);
|
||||
return (this.mm1.matches(method, targetClass) && this.mm2.matches(method, targetClass));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRuntime() {
|
||||
return this.mm1.isRuntime() || this.mm2.isRuntime();
|
||||
return (this.mm1.isRuntime() || this.mm2.isRuntime());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -250,10 +253,10 @@ public abstract class MethodMatchers {
|
||||
// Because a dynamic intersection may be composed of a static and dynamic part,
|
||||
// we must avoid calling the 3-arg matches method on a dynamic matcher, as
|
||||
// it will probably be an unsupported operation.
|
||||
boolean aMatches = this.mm1.isRuntime() ?
|
||||
this.mm1.matches(method, targetClass, args) : this.mm1.matches(method, targetClass);
|
||||
boolean bMatches = this.mm2.isRuntime() ?
|
||||
this.mm2.matches(method, targetClass, args) : this.mm2.matches(method, targetClass);
|
||||
boolean aMatches = (this.mm1.isRuntime() ?
|
||||
this.mm1.matches(method, targetClass, args) : this.mm1.matches(method, targetClass));
|
||||
boolean bMatches = (this.mm2.isRuntime() ?
|
||||
this.mm2.matches(method, targetClass, args) : this.mm2.matches(method, targetClass));
|
||||
return aMatches && bMatches;
|
||||
}
|
||||
|
||||
@@ -271,10 +274,7 @@ public abstract class MethodMatchers {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hashCode = 17;
|
||||
hashCode = 37 * hashCode + this.mm1.hashCode();
|
||||
hashCode = 37 * hashCode + this.mm2.hashCode();
|
||||
return hashCode;
|
||||
return 37 * this.mm1.hashCode() + this.mm2.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,8 +18,8 @@ package org.springframework.aop.support;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -38,7 +38,7 @@ import org.springframework.util.PatternMatchUtils;
|
||||
@SuppressWarnings("serial")
|
||||
public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut implements Serializable {
|
||||
|
||||
private List<String> mappedNames = new LinkedList<>();
|
||||
private List<String> mappedNames = new ArrayList<>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -55,11 +55,8 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme
|
||||
* Matching will be the union of all these; if any match,
|
||||
* the pointcut matches.
|
||||
*/
|
||||
public void setMappedNames(@Nullable String... mappedNames) {
|
||||
this.mappedNames = new LinkedList<>();
|
||||
if (mappedNames != null) {
|
||||
this.mappedNames.addAll(Arrays.asList(mappedNames));
|
||||
}
|
||||
public void setMappedNames(String... mappedNames) {
|
||||
this.mappedNames = new ArrayList<>(Arrays.asList(mappedNames));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,7 +21,8 @@ import java.io.Serializable;
|
||||
import org.springframework.aop.ClassFilter;
|
||||
|
||||
/**
|
||||
* Simple ClassFilter implementation that passes classes (and optionally subclasses)
|
||||
* Simple ClassFilter implementation that passes classes (and optionally subclasses).
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@@ -37,7 +38,7 @@ public class RootClassFilter implements ClassFilter, Serializable {
|
||||
|
||||
@Override
|
||||
public boolean matches(Class<?> candidate) {
|
||||
return clazz.isAssignableFrom(candidate);
|
||||
return this.clazz.isAssignableFrom(candidate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,8 @@ import org.springframework.lang.Nullable;
|
||||
/**
|
||||
* Convenient abstract superclass for static method matchers, which don't care
|
||||
* about arguments at runtime.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public abstract class StaticMethodMatcher implements MethodMatcher {
|
||||
|
||||
|
||||
+6
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.aop.support.annotation;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.aop.support.StaticMethodMatcher;
|
||||
@@ -71,6 +72,10 @@ public class AnnotationMethodMatcher extends StaticMethodMatcher {
|
||||
if (matchesMethod(method)) {
|
||||
return true;
|
||||
}
|
||||
// Proxy classes never have annotations on their redeclared methods.
|
||||
if (targetClass != null && Proxy.isProxyClass(targetClass)) {
|
||||
return false;
|
||||
}
|
||||
// The method may be on an interface, so let's check on the target class as well.
|
||||
Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass);
|
||||
return (specificMethod != method && matchesMethod(specificMethod));
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -74,8 +74,8 @@ public abstract class AbstractPrototypeBasedTargetSource extends AbstractBeanFac
|
||||
* @param target the bean instance to destroy
|
||||
*/
|
||||
protected void destroyPrototypeInstance(Object target) {
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("Destroying instance of bean '" + getTargetBeanName() + "'");
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Destroying instance of bean '" + getTargetBeanName() + "'");
|
||||
}
|
||||
if (getBeanFactory() instanceof ConfigurableBeanFactory) {
|
||||
((ConfigurableBeanFactory) getBeanFactory()).destroyBean(getTargetBeanName(), target);
|
||||
@@ -85,7 +85,7 @@ public abstract class AbstractPrototypeBasedTargetSource extends AbstractBeanFac
|
||||
((DisposableBean) target).destroy();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
logger.error("Couldn't invoke destroy method of bean with name '" + getTargetBeanName() + "'", ex);
|
||||
logger.error("Destroy method on bean with name '" + getTargetBeanName() + "' threw an exception", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -30,13 +27,7 @@ import org.junit.Test;
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AspectJAdviceParameterNameDiscoverAnnotationTests
|
||||
extends AspectJAdviceParameterNameDiscovererTests {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface MyAnnotation {}
|
||||
|
||||
public void pjpAndAnAnnotation(ProceedingJoinPoint pjp, MyAnnotation ann) {}
|
||||
public class AspectJAdviceParameterNameDiscoverAnnotationTests extends AspectJAdviceParameterNameDiscovererTests {
|
||||
|
||||
@Test
|
||||
public void testAnnotationBinding() {
|
||||
@@ -45,4 +36,9 @@ public class AspectJAdviceParameterNameDiscoverAnnotationTests
|
||||
new String[] {"thisJoinPoint","ann"});
|
||||
}
|
||||
|
||||
|
||||
public void pjpAndAnAnnotation(ProceedingJoinPoint pjp, MyAnnotation ann) {}
|
||||
|
||||
@interface MyAnnotation {}
|
||||
|
||||
}
|
||||
|
||||
+58
-52
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
@@ -34,47 +35,6 @@ import static org.junit.Assert.*;
|
||||
*/
|
||||
public class AspectJAdviceParameterNameDiscovererTests {
|
||||
|
||||
// methods to discover parameter names for
|
||||
public void noArgs() {
|
||||
}
|
||||
|
||||
public void tjp(JoinPoint jp) {
|
||||
}
|
||||
|
||||
public void tjpsp(JoinPoint.StaticPart tjpsp) {
|
||||
}
|
||||
|
||||
public void twoJoinPoints(JoinPoint jp1, JoinPoint jp2) {
|
||||
}
|
||||
|
||||
public void oneThrowable(Exception ex) {
|
||||
}
|
||||
|
||||
public void jpAndOneThrowable(JoinPoint jp, Exception ex) {
|
||||
}
|
||||
|
||||
public void jpAndTwoThrowables(JoinPoint jp, Exception ex, Error err) {
|
||||
}
|
||||
|
||||
public void oneObject(Object x) {
|
||||
}
|
||||
|
||||
public void twoObjects(Object x, Object y) {
|
||||
}
|
||||
|
||||
public void onePrimitive(int x) {
|
||||
}
|
||||
|
||||
public void oneObjectOnePrimitive(Object x, int y) {
|
||||
}
|
||||
|
||||
public void oneThrowableOnePrimitive(Throwable x, int y) {
|
||||
}
|
||||
|
||||
public void theBigOne(JoinPoint jp, Throwable x, int y, Object foo) {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNoArgs() {
|
||||
assertParameterNames(getMethod("noArgs"), "execution(* *(..))", new String[0]);
|
||||
@@ -221,22 +181,26 @@ public class AspectJAdviceParameterNameDiscovererTests {
|
||||
|
||||
@Test
|
||||
public void testThisAndPrimitive() {
|
||||
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && this(obj)", new String[] {"obj", "count"});
|
||||
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && this(obj)",
|
||||
new String[] {"obj", "count"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTargetAndPrimitive() {
|
||||
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && target(obj)", new String[] {"obj", "count"});
|
||||
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && target(obj)",
|
||||
new String[] {"obj", "count"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThrowingAndPrimitive() {
|
||||
assertParameterNames(getMethod("oneThrowableOnePrimitive"), "args(count)", null, "ex", new String[] {"ex", "count"});
|
||||
assertParameterNames(getMethod("oneThrowableOnePrimitive"), "args(count)", null, "ex",
|
||||
new String[] {"ex", "count"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllTogetherNow() {
|
||||
assertParameterNames(getMethod("theBigOne"), "this(foo) && args(x)", null, "ex", new String[] {"thisJoinPoint", "ex", "x", "foo"});
|
||||
assertParameterNames(getMethod("theBigOne"), "this(foo) && args(x)", null, "ex",
|
||||
new String[] {"thisJoinPoint", "ex", "x", "foo"});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -253,8 +217,8 @@ public class AspectJAdviceParameterNameDiscovererTests {
|
||||
|
||||
|
||||
protected Method getMethod(String name) {
|
||||
// assumes no overloading of test methods...
|
||||
Method[] candidates = this.getClass().getMethods();
|
||||
// Assumes no overloading of test methods...
|
||||
Method[] candidates = getClass().getMethods();
|
||||
for (Method candidate : candidates) {
|
||||
if (candidate.getName().equals(name)) {
|
||||
return candidate;
|
||||
@@ -268,8 +232,8 @@ public class AspectJAdviceParameterNameDiscovererTests {
|
||||
assertParameterNames(method, pointcut, null, null, parameterNames);
|
||||
}
|
||||
|
||||
protected void assertParameterNames(Method method, String pointcut, String returning, String throwing,
|
||||
String[] parameterNames) {
|
||||
protected void assertParameterNames(
|
||||
Method method, String pointcut, String returning, String throwing, String[] parameterNames) {
|
||||
|
||||
assertEquals("bad test specification, must have same number of parameter names as method arguments",
|
||||
method.getParameterCount(), parameterNames.length);
|
||||
@@ -300,8 +264,8 @@ public class AspectJAdviceParameterNameDiscovererTests {
|
||||
assertException(method, pointcut, null, null, exceptionType, message);
|
||||
}
|
||||
|
||||
protected void assertException(Method method, String pointcut, String returning, String throwing,
|
||||
Class<?> exceptionType, String message) {
|
||||
protected void assertException(
|
||||
Method method, String pointcut, String returning, String throwing, Class<?> exceptionType, String message) {
|
||||
|
||||
AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer(pointcut);
|
||||
discoverer.setRaiseExceptions(true);
|
||||
@@ -333,4 +297,46 @@ public class AspectJAdviceParameterNameDiscovererTests {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
// Methods to discover parameter names for
|
||||
|
||||
public void noArgs() {
|
||||
}
|
||||
|
||||
public void tjp(JoinPoint jp) {
|
||||
}
|
||||
|
||||
public void tjpsp(JoinPoint.StaticPart tjpsp) {
|
||||
}
|
||||
|
||||
public void twoJoinPoints(JoinPoint jp1, JoinPoint jp2) {
|
||||
}
|
||||
|
||||
public void oneThrowable(Exception ex) {
|
||||
}
|
||||
|
||||
public void jpAndOneThrowable(JoinPoint jp, Exception ex) {
|
||||
}
|
||||
|
||||
public void jpAndTwoThrowables(JoinPoint jp, Exception ex, Error err) {
|
||||
}
|
||||
|
||||
public void oneObject(Object x) {
|
||||
}
|
||||
|
||||
public void twoObjects(Object x, Object y) {
|
||||
}
|
||||
|
||||
public void onePrimitive(int x) {
|
||||
}
|
||||
|
||||
public void oneObjectOnePrimitive(Object x, int y) {
|
||||
}
|
||||
|
||||
public void oneThrowableOnePrimitive(Throwable x, int y) {
|
||||
}
|
||||
|
||||
public void theBigOne(JoinPoint jp, Throwable x, int y, Object foo) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-14
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -218,38 +218,27 @@ public class AspectJExpressionPointcutTests {
|
||||
@Test
|
||||
public void testSimpleAdvice() {
|
||||
String expression = "execution(int org.springframework.tests.sample.beans.TestBean.getAge())";
|
||||
|
||||
CallCountingInterceptor interceptor = new CallCountingInterceptor();
|
||||
|
||||
TestBean testBean = getAdvisedProxy(expression, interceptor);
|
||||
|
||||
assertEquals("Calls should be 0", 0, interceptor.getCount());
|
||||
|
||||
testBean.getAge();
|
||||
|
||||
assertEquals("Calls should be 1", 1, interceptor.getCount());
|
||||
|
||||
testBean.setAge(90);
|
||||
|
||||
assertEquals("Calls should still be 1", 1, interceptor.getCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDynamicMatchingProxy() {
|
||||
String expression = "execution(void org.springframework.tests.sample.beans.TestBean.setSomeNumber(Number)) && args(Double)";
|
||||
|
||||
CallCountingInterceptor interceptor = new CallCountingInterceptor();
|
||||
|
||||
TestBean testBean = getAdvisedProxy(expression, interceptor);
|
||||
|
||||
assertEquals("Calls should be 0", 0, interceptor.getCount());
|
||||
|
||||
testBean.setSomeNumber(new Double(30));
|
||||
|
||||
assertEquals("Calls should be 1", 1, interceptor.getCount());
|
||||
|
||||
testBean.setSomeNumber(new Integer(90));
|
||||
|
||||
assertEquals("Calls should be 1", 1, interceptor.getCount());
|
||||
}
|
||||
|
||||
@@ -291,7 +280,7 @@ public class AspectJExpressionPointcutTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithUnsupportedPointcutPrimitive() throws Exception {
|
||||
public void testWithUnsupportedPointcutPrimitive() {
|
||||
String expression = "call(int org.springframework.tests.sample.beans.TestBean.getAge())";
|
||||
|
||||
try {
|
||||
@@ -301,7 +290,6 @@ public class AspectJExpressionPointcutTests {
|
||||
catch (UnsupportedPointcutPrimitiveException ex) {
|
||||
assertEquals("Should not support call pointcut", PointcutPrimitive.CALL, ex.getUnsupportedPrimitive());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -332,6 +320,7 @@ public class AspectJExpressionPointcutTests {
|
||||
// Empty
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -77,6 +77,7 @@ public class BeanNamePointcutMatchingTests {
|
||||
assertMisMatch("someName", "!bean(someName) || bean(someOtherName)");
|
||||
}
|
||||
|
||||
|
||||
private void assertMatch(String beanName, String pcExpression) {
|
||||
assertTrue("Unexpected mismatch for bean \"" + beanName + "\" for pcExpression \"" + pcExpression + "\"",
|
||||
matches(beanName, pcExpression));
|
||||
@@ -98,4 +99,5 @@ public class BeanNamePointcutMatchingTests {
|
||||
pointcut.setExpression(pcExpression);
|
||||
return pointcut.matches(TestBean.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -218,7 +218,7 @@ public class MethodInvocationProceedingJoinPointTests {
|
||||
itb.unreliableFileOperation();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// we don't realy care...
|
||||
// we don't really care...
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+65
-29
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,30 +26,30 @@ import org.junit.Test;
|
||||
import test.annotation.EmptySpringAnnotation;
|
||||
import test.annotation.transaction.Tx;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Java5-specific {@link AspectJExpressionPointcutTests}.
|
||||
* Java 5 specific {@link AspectJExpressionPointcutTests}.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class TigerAspectJExpressionPointcutTests {
|
||||
|
||||
// TODO factor into static in AspectJExpressionPointcut
|
||||
private Method getAge;
|
||||
|
||||
private Map<String,Method> methodsOnHasGeneric = new HashMap<>();
|
||||
private final Map<String, Method> methodsOnHasGeneric = new HashMap<>();
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws NoSuchMethodException {
|
||||
public void setup() throws NoSuchMethodException {
|
||||
getAge = TestBean.class.getMethod("getAge");
|
||||
// Assumes no overloading
|
||||
for (Method m : HasGeneric.class.getMethods()) {
|
||||
methodsOnHasGeneric.put(m.getName(), m);
|
||||
for (Method method : HasGeneric.class.getMethods()) {
|
||||
methodsOnHasGeneric.put(method.getName(), method);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchVarargs() throws SecurityException, NoSuchMethodException {
|
||||
public void testMatchVarargs() throws Exception {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
class MyTemplate {
|
||||
@@ -87,11 +87,6 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
AspectJExpressionPointcut jdbcVarArgs = new AspectJExpressionPointcut();
|
||||
jdbcVarArgs.setExpression(expression);
|
||||
|
||||
// TODO: the expression above no longer matches Object[]
|
||||
// assertFalse(jdbcVarArgs.matches(
|
||||
// JdbcTemplate.class.getMethod("queryForInt", String.class, Object[].class),
|
||||
// JdbcTemplate.class));
|
||||
|
||||
assertTrue(jdbcVarArgs.matches(
|
||||
MyTemplate.class.getMethod("queryForInt", String.class, Object[].class),
|
||||
MyTemplate.class));
|
||||
@@ -105,19 +100,19 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchAnnotationOnClassWithAtWithin() throws SecurityException, NoSuchMethodException {
|
||||
public void testMatchAnnotationOnClassWithAtWithin() throws Exception {
|
||||
String expression = "@within(test.annotation.transaction.Tx)";
|
||||
testMatchAnnotationOnClass(expression);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchAnnotationOnClassWithoutBinding() throws SecurityException, NoSuchMethodException {
|
||||
public void testMatchAnnotationOnClassWithoutBinding() throws Exception {
|
||||
String expression = "within(@test.annotation.transaction.Tx *)";
|
||||
testMatchAnnotationOnClass(expression);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchAnnotationOnClassWithSubpackageWildcard() throws SecurityException, NoSuchMethodException {
|
||||
public void testMatchAnnotationOnClassWithSubpackageWildcard() throws Exception {
|
||||
String expression = "within(@(test.annotation..*) *)";
|
||||
AspectJExpressionPointcut springAnnotatedPc = testMatchAnnotationOnClass(expression);
|
||||
assertFalse(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class), TestBean.class));
|
||||
@@ -129,12 +124,12 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchAnnotationOnClassWithExactPackageWildcard() throws SecurityException, NoSuchMethodException {
|
||||
public void testMatchAnnotationOnClassWithExactPackageWildcard() throws Exception {
|
||||
String expression = "within(@(test.annotation.transaction.*) *)";
|
||||
testMatchAnnotationOnClass(expression);
|
||||
}
|
||||
|
||||
private AspectJExpressionPointcut testMatchAnnotationOnClass(String expression) throws SecurityException, NoSuchMethodException {
|
||||
private AspectJExpressionPointcut testMatchAnnotationOnClass(String expression) throws Exception {
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
@@ -147,7 +142,7 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnMethodWithFQN() throws SecurityException, NoSuchMethodException {
|
||||
public void testAnnotationOnMethodWithFQN() throws Exception {
|
||||
String expression = "@annotation(test.annotation.transaction.Tx)";
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
@@ -161,28 +156,56 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnMethodWithWildcard() throws SecurityException, NoSuchMethodException {
|
||||
public void testAnnotationOnCglibProxyMethod() throws Exception {
|
||||
String expression = "@annotation(test.annotation.transaction.Tx)";
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
ProxyFactory factory = new ProxyFactory(new BeanA());
|
||||
factory.setProxyTargetClass(true);
|
||||
BeanA proxy = (BeanA) factory.getProxy();
|
||||
assertTrue(ajexp.matches(BeanA.class.getMethod("getAge"), proxy.getClass()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnDynamicProxyMethod() throws Exception {
|
||||
String expression = "@annotation(test.annotation.transaction.Tx)";
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
ProxyFactory factory = new ProxyFactory(new BeanA());
|
||||
factory.setProxyTargetClass(false);
|
||||
IBeanA proxy = (IBeanA) factory.getProxy();
|
||||
assertTrue(ajexp.matches(IBeanA.class.getMethod("getAge"), proxy.getClass()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnMethodWithWildcard() throws Exception {
|
||||
String expression = "execution(@(test.annotation..*) * *(..))";
|
||||
AspectJExpressionPointcut anySpringMethodAnnotation = new AspectJExpressionPointcut();
|
||||
anySpringMethodAnnotation.setExpression(expression);
|
||||
|
||||
assertFalse(anySpringMethodAnnotation.matches(getAge, TestBean.class));
|
||||
assertFalse(anySpringMethodAnnotation.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
|
||||
assertFalse(anySpringMethodAnnotation.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||
assertFalse(anySpringMethodAnnotation.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
|
||||
assertFalse(anySpringMethodAnnotation.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||
assertFalse(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
assertTrue(anySpringMethodAnnotation.matches(BeanA.class.getMethod("getAge"), BeanA.class));
|
||||
assertFalse(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnMethodArgumentsWithFQN() throws SecurityException, NoSuchMethodException {
|
||||
public void testAnnotationOnMethodArgumentsWithFQN() throws Exception {
|
||||
String expression = "@args(*, test.annotation.EmptySpringAnnotation))";
|
||||
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut();
|
||||
takesSpringAnnotatedArgument2.setExpression(expression);
|
||||
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
@@ -203,14 +226,16 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationOnMethodArgumentsWithWildcards() throws SecurityException, NoSuchMethodException {
|
||||
public void testAnnotationOnMethodArgumentsWithWildcards() throws Exception {
|
||||
String expression = "execution(* *(*, @(test..*) *))";
|
||||
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut();
|
||||
takesSpringAnnotatedArgument2.setExpression(expression);
|
||||
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
@@ -260,12 +285,21 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
|
||||
@EmptySpringAnnotation
|
||||
public static class SpringAnnotated {
|
||||
|
||||
public void foo() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class BeanA {
|
||||
interface IBeanA {
|
||||
|
||||
@Tx
|
||||
int getAge();
|
||||
}
|
||||
|
||||
|
||||
static class BeanA implements IBeanA {
|
||||
|
||||
private String name;
|
||||
|
||||
private int age;
|
||||
@@ -275,6 +309,7 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
}
|
||||
|
||||
@Tx
|
||||
@Override
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
@@ -283,6 +318,7 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
|
||||
@Tx
|
||||
static class BeanB {
|
||||
|
||||
private String name;
|
||||
|
||||
public void setName(String name) {
|
||||
|
||||
+77
-96
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -46,7 +46,6 @@ import test.aop.PerTargetAspect;
|
||||
import test.aop.TwoAdviceAspect;
|
||||
|
||||
import org.springframework.aop.Advisor;
|
||||
import org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.framework.AopConfigException;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
@@ -82,22 +81,24 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
@Test
|
||||
public void testRejectsPerCflowAspect() {
|
||||
try {
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerCflowAspect(),"someBean"));
|
||||
getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new PerCflowAspect(), "someBean"));
|
||||
fail("Cannot accept cflow");
|
||||
}
|
||||
catch (AopConfigException ex) {
|
||||
assertTrue(ex.getMessage().indexOf("PERCFLOW") != -1);
|
||||
assertTrue(ex.getMessage().contains("PERCFLOW"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRejectsPerCflowBelowAspect() {
|
||||
try {
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerCflowBelowAspect(),"someBean"));
|
||||
getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new PerCflowBelowAspect(), "someBean"));
|
||||
fail("Cannot accept cflowbelow");
|
||||
}
|
||||
catch (AopConfigException ex) {
|
||||
assertTrue(ex.getMessage().indexOf("PERCFLOWBELOW") != -1);
|
||||
assertTrue(ex.getMessage().contains("PERCFLOWBELOW"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +113,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
assertEquals("Around advice must NOT apply", realAge, itb.getAge());
|
||||
|
||||
Advised advised = (Advised) itb;
|
||||
SyntheticInstantiationAdvisor sia = (SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
|
||||
ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia =
|
||||
(ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
|
||||
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
||||
InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[3];
|
||||
LazySingletonAspectInstanceFactoryDecorator maaif =
|
||||
@@ -199,7 +201,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
Advised advised = (Advised) itb;
|
||||
// Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
|
||||
assertEquals(4, advised.getAdvisors().length);
|
||||
SyntheticInstantiationAdvisor sia = (SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
|
||||
ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia =
|
||||
(ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
|
||||
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
||||
InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
|
||||
LazySingletonAspectInstanceFactoryDecorator maaif =
|
||||
@@ -227,16 +230,15 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
int realAge = 65;
|
||||
target.setAge(realAge);
|
||||
PerTypeWithinAspectInstanceFactory aif = new PerTypeWithinAspectInstanceFactory();
|
||||
TestBean itb = (TestBean) createProxy(target,
|
||||
getFixture().getAdvisors(aif),
|
||||
TestBean.class);
|
||||
TestBean itb = (TestBean) createProxy(target, getFixture().getAdvisors(aif), TestBean.class);
|
||||
assertEquals("No method calls", 0, aif.getInstantiationCount());
|
||||
assertEquals("Around advice must now apply", 0, itb.getAge());
|
||||
|
||||
Advised advised = (Advised) itb;
|
||||
// Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
|
||||
assertEquals(4, advised.getAdvisors().length);
|
||||
SyntheticInstantiationAdvisor sia = (SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
|
||||
ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia =
|
||||
(ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
|
||||
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
||||
InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
|
||||
LazySingletonAspectInstanceFactoryDecorator maaif =
|
||||
@@ -257,9 +259,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
assertEquals("Around advice must still apply", 1, itb.getAge());
|
||||
assertEquals("Around advice must still apply", 2, itb.getAge());
|
||||
|
||||
TestBean itb2 = (TestBean) createProxy(target,
|
||||
getFixture().getAdvisors(aif),
|
||||
TestBean.class);
|
||||
TestBean itb2 = (TestBean) createProxy(target, getFixture().getAdvisors(aif), TestBean.class);
|
||||
assertEquals(1, aif.getInstantiationCount());
|
||||
assertEquals("Around advice be independent for second instance", 0, itb2.getAge());
|
||||
assertEquals(2, aif.getInstantiationCount());
|
||||
@@ -284,7 +284,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
public void testNamedPointcutFromAspectLibraryWithBinding() {
|
||||
TestBean target = new TestBean();
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new NamedPointcutAspectFromLibraryWithBinding(),"someBean")),
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(
|
||||
new NamedPointcutAspectFromLibraryWithBinding(), "someBean")),
|
||||
ITestBean.class);
|
||||
itb.setAge(10);
|
||||
assertEquals("Around advice must apply", 20, itb.getAge());
|
||||
@@ -296,7 +297,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
int realAge = 65;
|
||||
target.setAge(realAge);
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(aspectInstance,"someBean")),
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(aspectInstance, "someBean")),
|
||||
ITestBean.class);
|
||||
assertEquals("Around advice must apply", -1, itb.getAge());
|
||||
assertEquals(realAge, target.getAge());
|
||||
@@ -306,7 +307,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
public void testBindingWithSingleArg() {
|
||||
TestBean target = new TestBean();
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new BindingAspectWithSingleArg(),"someBean")),
|
||||
getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new BindingAspectWithSingleArg(), "someBean")),
|
||||
ITestBean.class);
|
||||
itb.setAge(10);
|
||||
assertEquals("Around advice must apply", 20, itb.getAge());
|
||||
@@ -317,7 +319,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
public void testBindingWithMultipleArgsDifferentlyOrdered() {
|
||||
ManyValuedArgs target = new ManyValuedArgs();
|
||||
ManyValuedArgs mva = (ManyValuedArgs) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new ManyValuedArgs(),"someBean")),
|
||||
getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new ManyValuedArgs(), "someBean")),
|
||||
ManyValuedArgs.class);
|
||||
|
||||
String a = "a";
|
||||
@@ -338,7 +341,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
assertFalse(notLockableTarget instanceof Lockable);
|
||||
NotLockable notLockable1 = (NotLockable) createProxy(notLockableTarget,
|
||||
getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean")),
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")),
|
||||
NotLockable.class);
|
||||
assertTrue(notLockable1 instanceof Lockable);
|
||||
Lockable lockable = (Lockable) notLockable1;
|
||||
@@ -349,7 +352,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
NotLockable notLockable2Target = new NotLockable();
|
||||
NotLockable notLockable2 = (NotLockable) createProxy(notLockable2Target,
|
||||
getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean")),
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")),
|
||||
NotLockable.class);
|
||||
assertTrue(notLockable2 instanceof Lockable);
|
||||
Lockable lockable2 = (Lockable) notLockable2;
|
||||
@@ -368,11 +371,11 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
@Test
|
||||
public void testIntroductionAdvisorExcludedFromTargetImplementingInterface() {
|
||||
assertTrue(AopUtils.findAdvisorsThatCanApply(
|
||||
getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(
|
||||
new MakeLockable(),"someBean")),
|
||||
CannotBeUnlocked.class).isEmpty());
|
||||
assertEquals(2, AopUtils.findAdvisorsThatCanApply(getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean")), NotLockable.class).size());
|
||||
getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")),
|
||||
CannotBeUnlocked.class).isEmpty());
|
||||
assertEquals(2, AopUtils.findAdvisorsThatCanApply(getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean")), NotLockable.class).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -408,42 +411,34 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")),
|
||||
List.class
|
||||
),
|
||||
CannotBeUnlocked.class);
|
||||
List.class);
|
||||
assertFalse("Type pattern must have excluded mixin", proxy instanceof Lockable);
|
||||
}
|
||||
|
||||
/* prereq AspectJ 1.6.7
|
||||
@Test
|
||||
public void testIntroductionBasedOnAnnotationMatch_Spr5307() {
|
||||
public void testIntroductionBasedOnAnnotationMatch_SPR5307() {
|
||||
AnnotatedTarget target = new AnnotatedTargetImpl();
|
||||
|
||||
List<Advisor> advisors = getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeAnnotatedTypeModifiable(),"someBean"));
|
||||
Object proxy = createProxy(target,
|
||||
advisors,
|
||||
AnnotatedTarget.class);
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeAnnotatedTypeModifiable(), "someBean"));
|
||||
Object proxy = createProxy(target, advisors, AnnotatedTarget.class);
|
||||
System.out.println(advisors.get(1));
|
||||
assertTrue(proxy instanceof Lockable);
|
||||
Lockable lockable = (Lockable)proxy;
|
||||
lockable.locked();
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: Why does this test fail? It hasn't been run before, so it maybe never actually passed...
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testIntroductionWithArgumentBinding() {
|
||||
TestBean target = new TestBean();
|
||||
|
||||
List<Advisor> advisors = getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeITestBeanModifiable(),"someBean"));
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeITestBeanModifiable(), "someBean"));
|
||||
advisors.addAll(getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean")));
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")));
|
||||
|
||||
Modifiable modifiable = (Modifiable) createProxy(target,
|
||||
advisors,
|
||||
ITestBean.class);
|
||||
Modifiable modifiable = (Modifiable) createProxy(target, advisors, ITestBean.class);
|
||||
assertThat(modifiable, instanceOf(Modifiable.class));
|
||||
Lockable lockable = (Lockable) modifiable;
|
||||
assertFalse(lockable.locked());
|
||||
@@ -477,11 +472,11 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
public void testAspectMethodThrowsExceptionLegalOnSignature() {
|
||||
TestBean target = new TestBean();
|
||||
UnsupportedOperationException expectedException = new UnsupportedOperationException();
|
||||
List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new ExceptionAspect(expectedException),"someBean"));
|
||||
List<Advisor> advisors = getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new ExceptionAspect(expectedException), "someBean"));
|
||||
assertEquals("One advice method was found", 1, advisors.size());
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
advisors,
|
||||
ITestBean.class);
|
||||
ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class);
|
||||
|
||||
try {
|
||||
itb.getAge();
|
||||
fail();
|
||||
@@ -497,11 +492,11 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
public void testAspectMethodThrowsExceptionIllegalOnSignature() {
|
||||
TestBean target = new TestBean();
|
||||
RemoteException expectedException = new RemoteException();
|
||||
List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new ExceptionAspect(expectedException),"someBean"));
|
||||
List<Advisor> advisors = getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new ExceptionAspect(expectedException), "someBean"));
|
||||
assertEquals("One advice method was found", 1, advisors.size());
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
advisors,
|
||||
ITestBean.class);
|
||||
ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class);
|
||||
|
||||
try {
|
||||
itb.getAge();
|
||||
fail();
|
||||
@@ -522,10 +517,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
|
||||
// Required everywhere we use AspectJ proxies
|
||||
pf.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
||||
|
||||
for (Object a : advisors) {
|
||||
pf.addAdvisor((Advisor) a);
|
||||
}
|
||||
pf.addAdvisors(advisors);
|
||||
|
||||
pf.setExposeProxy(true);
|
||||
return pf.getProxy();
|
||||
@@ -534,13 +526,11 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
@Test
|
||||
public void testTwoAdvicesOnOneAspect() {
|
||||
TestBean target = new TestBean();
|
||||
|
||||
TwoAdviceAspect twoAdviceAspect = new TwoAdviceAspect();
|
||||
List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(twoAdviceAspect,"someBean"));
|
||||
List<Advisor> advisors = getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(twoAdviceAspect, "someBean"));
|
||||
assertEquals("Two advice methods found", 2, advisors.size());
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
advisors,
|
||||
ITestBean.class);
|
||||
ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class);
|
||||
itb.setName("");
|
||||
assertEquals(0, itb.getAge());
|
||||
int newAge = 32;
|
||||
@@ -551,16 +541,15 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
@Test
|
||||
public void testAfterAdviceTypes() throws Exception {
|
||||
Echo target = new Echo();
|
||||
|
||||
ExceptionHandling afterReturningAspect = new ExceptionHandling();
|
||||
List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(afterReturningAspect,"someBean"));
|
||||
Echo echo = (Echo) createProxy(target,
|
||||
advisors,
|
||||
Echo.class);
|
||||
List<Advisor> advisors = getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(afterReturningAspect, "someBean"));
|
||||
Echo echo = (Echo) createProxy(target, advisors, Echo.class);
|
||||
assertEquals(0, afterReturningAspect.successCount);
|
||||
assertEquals("", echo.echo(""));
|
||||
assertEquals(1, afterReturningAspect.successCount);
|
||||
assertEquals(0, afterReturningAspect.failureCount);
|
||||
|
||||
try {
|
||||
echo.echo(new FileNotFoundException());
|
||||
fail();
|
||||
@@ -580,9 +569,9 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
public void testFailureWithoutExplicitDeclarePrecedence() {
|
||||
TestBean target = new TestBean();
|
||||
MetadataAwareAspectInstanceFactory aspectInstanceFactory = new SingletonMetadataAwareAspectInstanceFactory(
|
||||
new NoDeclarePrecedenceShouldFail(), "someBean");
|
||||
new NoDeclarePrecedenceShouldFail(), "someBean");
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
getFixture().getAdvisors(aspectInstanceFactory), ITestBean.class);
|
||||
getFixture().getAdvisors(aspectInstanceFactory), ITestBean.class);
|
||||
itb.getAge();
|
||||
}
|
||||
|
||||
@@ -590,21 +579,10 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
public void testDeclarePrecedenceNotSupported() {
|
||||
TestBean target = new TestBean();
|
||||
MetadataAwareAspectInstanceFactory aspectInstanceFactory = new SingletonMetadataAwareAspectInstanceFactory(
|
||||
new DeclarePrecedenceShouldSucceed(), "someBean");
|
||||
createProxy(target, getFixture().getAdvisors(aspectInstanceFactory),
|
||||
ITestBean.class);
|
||||
new DeclarePrecedenceShouldSucceed(), "someBean");
|
||||
createProxy(target, getFixture().getAdvisors(aspectInstanceFactory), ITestBean.class);
|
||||
}
|
||||
|
||||
/** Not supported in 2.0!
|
||||
public void testExplicitDeclarePrecedencePreventsFailure() {
|
||||
TestBean target = new TestBean();
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new DeclarePrecedenceShouldSucceed(), "someBean")),
|
||||
ITestBean.class);
|
||||
assertEquals(666, itb.getAge());
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@Aspect("percflow(execution(* *(..)))")
|
||||
public static class PerCflowAspect {
|
||||
@@ -723,6 +701,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
|
||||
@Aspect
|
||||
public static class NamedPointcutAspectWithoutFQN {
|
||||
|
||||
@Pointcut("execution(* getAge())")
|
||||
public void getAge() {
|
||||
}
|
||||
@@ -779,7 +758,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
|
||||
@Around(value="setAge(age)",argNames="age")
|
||||
// @ArgNames({"age"}) // AMC needs more work here? ignoring pjp arg... ok??
|
||||
// argNames should be suported in Around as it is in Pointcut
|
||||
// argNames should be suported in Around as it is in Pointcut
|
||||
public void changeReturnType(ProceedingJoinPoint pjp, int age) throws Throwable {
|
||||
pjp.proceed(new Object[] {age*2});
|
||||
}
|
||||
@@ -788,12 +767,12 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
|
||||
@Aspect
|
||||
public static class ManyValuedArgs {
|
||||
|
||||
public String mungeArgs(String a, int b, int c, String d, StringBuffer e) {
|
||||
return a + b + c + d + e;
|
||||
}
|
||||
|
||||
@Around(value="execution(String mungeArgs(..)) && args(a, b, c, d, e)",
|
||||
argNames="b,c,d,e,a")
|
||||
@Around(value="execution(String mungeArgs(..)) && args(a, b, c, d, e)", argNames="b,c,d,e,a")
|
||||
public String reverseAdvice(ProceedingJoinPoint pjp, int b, int c, String d, StringBuffer e, String a) throws Throwable {
|
||||
assertEquals(a + b+ c+ d+ e, pjp.proceed());
|
||||
return a + b + c + d + e;
|
||||
@@ -803,6 +782,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
|
||||
@Aspect
|
||||
public static class ExceptionAspect {
|
||||
|
||||
private final Exception ex;
|
||||
|
||||
public ExceptionAspect(Exception ex) {
|
||||
@@ -829,8 +809,11 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
|
||||
@Aspect
|
||||
public static class ExceptionHandling {
|
||||
|
||||
public int successCount;
|
||||
|
||||
public int failureCount;
|
||||
|
||||
public int afterCount;
|
||||
|
||||
@AfterReturning("execution(* echo(*))")
|
||||
@@ -902,10 +885,12 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
abstract class AbstractMakeModifiable {
|
||||
|
||||
public interface MutableModifable extends Modifiable {
|
||||
|
||||
void markDirty();
|
||||
}
|
||||
|
||||
public static class ModifiableImpl implements MutableModifable {
|
||||
|
||||
private boolean modified;
|
||||
|
||||
@Override
|
||||
@@ -924,10 +909,9 @@ abstract class AbstractMakeModifiable {
|
||||
}
|
||||
}
|
||||
|
||||
@Before(value="execution(void set*(*)) && this(modifiable) && args(newValue)",
|
||||
argNames="modifiable,newValue")
|
||||
public void recordModificationIfSetterArgumentDiffersFromOldValue(JoinPoint jp,
|
||||
MutableModifable mixin, Object newValue) {
|
||||
@Before(value="execution(void set*(*)) && this(modifiable) && args(newValue)", argNames="modifiable,newValue")
|
||||
public void recordModificationIfSetterArgumentDiffersFromOldValue(
|
||||
JoinPoint jp, MutableModifable mixin, Object newValue) {
|
||||
|
||||
/*
|
||||
* We use the mixin to check and, if necessary, change,
|
||||
@@ -992,6 +976,7 @@ class MakeITestBeanModifiable extends AbstractMakeModifiable {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a declare parents pointcut - spr5307
|
||||
* @author Andy Clement
|
||||
@@ -1001,8 +986,7 @@ class MakeITestBeanModifiable extends AbstractMakeModifiable {
|
||||
class MakeAnnotatedTypeModifiable extends AbstractMakeModifiable {
|
||||
|
||||
@DeclareParents(value = "(@org.springframework.aop.aspectj.annotation.Measured *)",
|
||||
// @DeclareParents(value = "(@Measured *)", // this would be a nice alternative...
|
||||
defaultImpl=DefaultLockable.class)
|
||||
defaultImpl = DefaultLockable.class)
|
||||
public static Lockable mixin;
|
||||
|
||||
}
|
||||
@@ -1014,14 +998,11 @@ class MakeAnnotatedTypeModifiable extends AbstractMakeModifiable {
|
||||
@Aspect
|
||||
class MakeLockable {
|
||||
|
||||
@DeclareParents(value = "org.springframework..*",
|
||||
defaultImpl=DefaultLockable.class)
|
||||
@DeclareParents(value = "org.springframework..*", defaultImpl = DefaultLockable.class)
|
||||
public static Lockable mixin;
|
||||
|
||||
@Before(value="execution(void set*(*)) && this(mixin)", argNames="mixin")
|
||||
public void checkNotLocked(
|
||||
Lockable mixin) // Bind to arg
|
||||
{
|
||||
public void checkNotLocked( Lockable mixin) {
|
||||
// Can also obtain the mixin (this) this way
|
||||
//Lockable mixin = (Lockable) jp.getThis();
|
||||
if (mixin.locked()) {
|
||||
@@ -1069,6 +1050,7 @@ interface Modifiable {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used as a target.
|
||||
* @author Andy Clement
|
||||
@@ -1076,11 +1058,12 @@ interface Modifiable {
|
||||
interface AnnotatedTarget {
|
||||
}
|
||||
|
||||
|
||||
@Measured
|
||||
class AnnotatedTargetImpl implements AnnotatedTarget {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Measured {}
|
||||
|
||||
@@ -1104,9 +1087,7 @@ class PerThisAspect {
|
||||
|
||||
public int count;
|
||||
|
||||
/**
|
||||
* Just to check that this doesn't cause problems with introduction processing
|
||||
*/
|
||||
// Just to check that this doesn't cause problems with introduction processing
|
||||
private ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean();
|
||||
|
||||
@Around("execution(int *.getAge())")
|
||||
|
||||
+6
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -41,11 +41,12 @@ public class NameMatchMethodPointcutTests {
|
||||
|
||||
protected SerializableNopInterceptor nop;
|
||||
|
||||
|
||||
/**
|
||||
* Create an empty pointcut, populating instance variables.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
public void setup() {
|
||||
ProxyFactory pf = new ProxyFactory(new SerializablePerson());
|
||||
nop = new SerializableNopInterceptor();
|
||||
pc = new NameMatchMethodPointcut();
|
||||
@@ -53,6 +54,7 @@ public class NameMatchMethodPointcutTests {
|
||||
proxied = (Person) pf.getProxy();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMatchingOnly() {
|
||||
// Can't do exact matching through isMatch
|
||||
@@ -94,7 +96,7 @@ public class NameMatchMethodPointcutTests {
|
||||
|
||||
@Test
|
||||
public void testSets() throws Throwable {
|
||||
pc.setMappedNames(new String[] { "set*", "echo" });
|
||||
pc.setMappedNames("set*", "echo");
|
||||
assertEquals(0, nop.getCount());
|
||||
proxied.getName();
|
||||
proxied.setName("");
|
||||
@@ -116,7 +118,7 @@ public class NameMatchMethodPointcutTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsAndHashCode() throws Exception {
|
||||
public void testEqualsAndHashCode() {
|
||||
NameMatchMethodPointcut pc1 = new NameMatchMethodPointcut();
|
||||
NameMatchMethodPointcut pc2 = new NameMatchMethodPointcut();
|
||||
|
||||
|
||||
+5
-5
@@ -70,13 +70,13 @@ public class HotSwappableTargetSourceTests {
|
||||
@Test
|
||||
public void testBasicFunctionality() {
|
||||
SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable");
|
||||
assertEquals(INITIAL_COUNT, proxied.getCount() );
|
||||
assertEquals(INITIAL_COUNT, proxied.getCount());
|
||||
proxied.doWork();
|
||||
assertEquals(INITIAL_COUNT + 1, proxied.getCount() );
|
||||
assertEquals(INITIAL_COUNT + 1, proxied.getCount());
|
||||
|
||||
proxied = (SideEffectBean) beanFactory.getBean("swappable");
|
||||
proxied.doWork();
|
||||
assertEquals(INITIAL_COUNT + 2, proxied.getCount() );
|
||||
assertEquals(INITIAL_COUNT + 2, proxied.getCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,9 +85,9 @@ public class HotSwappableTargetSourceTests {
|
||||
SideEffectBean target2 = (SideEffectBean) beanFactory.getBean("target2");
|
||||
|
||||
SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable");
|
||||
assertEquals(target1.getCount(), proxied.getCount() );
|
||||
assertEquals(target1.getCount(), proxied.getCount());
|
||||
proxied.doWork();
|
||||
assertEquals(INITIAL_COUNT + 1, proxied.getCount() );
|
||||
assertEquals(INITIAL_COUNT + 1, proxied.getCount());
|
||||
|
||||
HotSwappableTargetSource swapper = (HotSwappableTargetSource) beanFactory.getBean("swapper");
|
||||
Object old = swapper.swap(target2);
|
||||
|
||||
+4
-4
@@ -56,14 +56,14 @@ public class PrototypeTargetSourceTests {
|
||||
@Test
|
||||
public void testPrototypeAndSingletonBehaveDifferently() {
|
||||
SideEffectBean singleton = (SideEffectBean) beanFactory.getBean("singleton");
|
||||
assertEquals(INITIAL_COUNT, singleton.getCount() );
|
||||
assertEquals(INITIAL_COUNT, singleton.getCount());
|
||||
singleton.doWork();
|
||||
assertEquals(INITIAL_COUNT + 1, singleton.getCount() );
|
||||
assertEquals(INITIAL_COUNT + 1, singleton.getCount());
|
||||
|
||||
SideEffectBean prototype = (SideEffectBean) beanFactory.getBean("prototype");
|
||||
assertEquals(INITIAL_COUNT, prototype.getCount() );
|
||||
assertEquals(INITIAL_COUNT, prototype.getCount());
|
||||
prototype.doWork();
|
||||
assertEquals(INITIAL_COUNT, prototype.getCount() );
|
||||
assertEquals(INITIAL_COUNT, prototype.getCount());
|
||||
}
|
||||
|
||||
|
||||
|
||||
+11
-11
@@ -62,9 +62,9 @@ public class ThreadLocalTargetSourceTests {
|
||||
@Test
|
||||
public void testUseDifferentManagedInstancesInSameThread() {
|
||||
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
|
||||
assertEquals(INITIAL_COUNT, apartment.getCount() );
|
||||
assertEquals(INITIAL_COUNT, apartment.getCount());
|
||||
apartment.doWork();
|
||||
assertEquals(INITIAL_COUNT + 1, apartment.getCount() );
|
||||
assertEquals(INITIAL_COUNT + 1, apartment.getCount());
|
||||
|
||||
ITestBean test = (ITestBean) beanFactory.getBean("threadLocal2");
|
||||
assertEquals("Rod", test.getName());
|
||||
@@ -74,12 +74,12 @@ public class ThreadLocalTargetSourceTests {
|
||||
@Test
|
||||
public void testReuseInSameThread() {
|
||||
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
|
||||
assertEquals(INITIAL_COUNT, apartment.getCount() );
|
||||
assertEquals(INITIAL_COUNT, apartment.getCount());
|
||||
apartment.doWork();
|
||||
assertEquals(INITIAL_COUNT + 1, apartment.getCount() );
|
||||
assertEquals(INITIAL_COUNT + 1, apartment.getCount());
|
||||
|
||||
apartment = (SideEffectBean) beanFactory.getBean("apartment");
|
||||
assertEquals(INITIAL_COUNT + 1, apartment.getCount() );
|
||||
assertEquals(INITIAL_COUNT + 1, apartment.getCount());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,20 +106,20 @@ public class ThreadLocalTargetSourceTests {
|
||||
@Test
|
||||
public void testNewThreadHasOwnInstance() throws InterruptedException {
|
||||
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
|
||||
assertEquals(INITIAL_COUNT, apartment.getCount() );
|
||||
assertEquals(INITIAL_COUNT, apartment.getCount());
|
||||
apartment.doWork();
|
||||
apartment.doWork();
|
||||
apartment.doWork();
|
||||
assertEquals(INITIAL_COUNT + 3, apartment.getCount() );
|
||||
assertEquals(INITIAL_COUNT + 3, apartment.getCount());
|
||||
|
||||
class Runner implements Runnable {
|
||||
public SideEffectBean mine;
|
||||
@Override
|
||||
public void run() {
|
||||
this.mine = (SideEffectBean) beanFactory.getBean("apartment");
|
||||
assertEquals(INITIAL_COUNT, mine.getCount() );
|
||||
assertEquals(INITIAL_COUNT, mine.getCount());
|
||||
mine.doWork();
|
||||
assertEquals(INITIAL_COUNT + 1, mine.getCount() );
|
||||
assertEquals(INITIAL_COUNT + 1, mine.getCount());
|
||||
}
|
||||
}
|
||||
Runner r = new Runner();
|
||||
@@ -130,11 +130,11 @@ public class ThreadLocalTargetSourceTests {
|
||||
assertNotNull(r);
|
||||
|
||||
// Check it didn't affect the other thread's copy
|
||||
assertEquals(INITIAL_COUNT + 3, apartment.getCount() );
|
||||
assertEquals(INITIAL_COUNT + 3, apartment.getCount());
|
||||
|
||||
// When we use other thread's copy in this thread
|
||||
// it should behave like ours
|
||||
assertEquals(INITIAL_COUNT + 3, r.mine.getCount() );
|
||||
assertEquals(INITIAL_COUNT + 3, r.mine.getCount());
|
||||
|
||||
// Bound to two threads
|
||||
assertEquals(2, ((ThreadLocalTargetSourceStats) apartment).getObjectCount());
|
||||
|
||||
@@ -80,8 +80,8 @@ compileTestJava {
|
||||
|
||||
dependencies {
|
||||
aspects(project(":spring-orm"))
|
||||
ajc("org.aspectj:aspectjtools:1.9.0") // for JDK 9+ build compatibility
|
||||
rt("org.aspectj:aspectjrt:1.9.0") // for JDK 9+ build compatibility
|
||||
ajc("org.aspectj:aspectjtools:1.9.1") // for JDK 9+ build compatibility
|
||||
rt("org.aspectj:aspectjrt:1.9.1") // for JDK 9+ build compatibility
|
||||
compile("org.aspectj:aspectjweaver:${aspectjVersion}") // for Maven POM exposure
|
||||
optional(project(":spring-aop")) // for @Async support
|
||||
optional(project(":spring-beans")) // for @Configurable support
|
||||
|
||||
Vendored
+2
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,6 +34,7 @@ import org.springframework.context.annotation.Role;
|
||||
* @see org.springframework.cache.annotation.CachingConfigurationSelector
|
||||
*/
|
||||
@Configuration
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
public class AspectJCachingConfiguration extends AbstractCachingConfiguration {
|
||||
|
||||
@Bean(name = CacheManagementConfigUtils.CACHE_ASPECT_BEAN_NAME)
|
||||
|
||||
Vendored
+2
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,6 +34,7 @@ import org.springframework.context.annotation.Role;
|
||||
* @see org.springframework.cache.annotation.CachingConfigurationSelector
|
||||
*/
|
||||
@Configuration
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
public class AspectJJCacheConfiguration extends AbstractJCacheConfiguration {
|
||||
|
||||
@Bean(name = CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME)
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ import org.springframework.transaction.annotation.AnnotationTransactionAttribute
|
||||
* @see javax.transaction.Transactional
|
||||
* @see AnnotationTransactionAspect
|
||||
*/
|
||||
@RequiredTypes({"javax.transaction.Transactional"})
|
||||
@RequiredTypes("javax.transaction.Transactional")
|
||||
public aspect JtaAnnotationTransactionAspect extends AbstractTransactionAspect {
|
||||
|
||||
public JtaAnnotationTransactionAspect() {
|
||||
|
||||
@@ -3,7 +3,7 @@ description = "Spring Beans"
|
||||
apply plugin: "groovy"
|
||||
|
||||
dependencies {
|
||||
compile(project(':spring-core'))
|
||||
compile(project(":spring-core"))
|
||||
optional("javax.inject:javax.inject:1")
|
||||
optional("org.yaml:snakeyaml:1.20")
|
||||
optional("org.codehaus.groovy:groovy-all:${groovyVersion}")
|
||||
@@ -12,8 +12,7 @@ dependencies {
|
||||
testCompile("org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}")
|
||||
}
|
||||
|
||||
// This modules does joint compilation for Java and Groovy code,
|
||||
// with the compileGroovy task.
|
||||
// This module does joint compilation for Java and Groovy code with the compileGroovy task.
|
||||
sourceSets {
|
||||
main.groovy.srcDirs += "src/main/java"
|
||||
main.java.srcDirs = []
|
||||
@@ -24,9 +23,8 @@ compileGroovy {
|
||||
targetCompatibility = 1.8
|
||||
}
|
||||
|
||||
// This module also builds Kotlin code and the compileKotlin task
|
||||
// naturally depends on compileJava.
|
||||
// We need to redefine dependencies to break task cycles.
|
||||
compileGroovy.dependsOn = compileGroovy.taskDependencies.values - 'compileJava'
|
||||
// This module also builds Kotlin code and the compileKotlin task naturally depends on
|
||||
// compileJava. We need to redefine dependencies to break task cycles.
|
||||
compileGroovy.dependsOn = compileGroovy.taskDependencies.values - "compileJava"
|
||||
compileKotlin.dependsOn(compileGroovy)
|
||||
compileKotlin.classpath += files(compileGroovy.destinationDir)
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -110,7 +110,7 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl
|
||||
}
|
||||
catch (PropertyAccessException ex) {
|
||||
if (propertyAccessExceptions == null) {
|
||||
propertyAccessExceptions = new LinkedList<>();
|
||||
propertyAccessExceptions = new ArrayList<>();
|
||||
}
|
||||
propertyAccessExceptions.add(ex);
|
||||
}
|
||||
|
||||
+1
-2
@@ -299,8 +299,7 @@ public class CachedIntrospectionResults {
|
||||
// in particular for Java 8 default methods...
|
||||
Class<?> clazz = beanClass;
|
||||
while (clazz != null && clazz != Object.class) {
|
||||
Class<?>[] ifcs = clazz.getInterfaces();
|
||||
for (Class<?> ifc : ifcs) {
|
||||
for (Class<?> ifc : clazz.getInterfaces()) {
|
||||
if (!ClassUtils.isJavaLanguageInterface(ifc)) {
|
||||
for (PropertyDescriptor pd : getBeanInfo(ifc).getPropertyDescriptors()) {
|
||||
if (!this.propertyDescriptorCache.containsKey(pd.getName())) {
|
||||
|
||||
@@ -43,8 +43,10 @@ import org.springframework.util.ObjectUtils;
|
||||
* Decorator for a standard {@link BeanInfo} object, e.g. as created by
|
||||
* {@link Introspector#getBeanInfo(Class)}, designed to discover and register static
|
||||
* and/or non-void returning setter methods. For example:
|
||||
*
|
||||
* <pre class="code">
|
||||
* public class Bean {
|
||||
*
|
||||
* private Foo foo;
|
||||
*
|
||||
* public Foo getFoo() {
|
||||
@@ -56,6 +58,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* return this;
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* The standard JavaBeans {@code Introspector} will discover the {@code getFoo} read
|
||||
* method, but will bypass the {@code #setFoo(Foo)} write method, because its non-void
|
||||
* returning signature does not comply with the JavaBeans specification.
|
||||
@@ -68,6 +71,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* indexed properties</a> are fully supported.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
* @see #ExtendedBeanInfo(BeanInfo)
|
||||
* @see ExtendedBeanInfoFactory
|
||||
@@ -79,8 +83,7 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||
|
||||
private final BeanInfo delegate;
|
||||
|
||||
private final Set<PropertyDescriptor> propertyDescriptors =
|
||||
new TreeSet<>(new PropertyDescriptorComparator());
|
||||
private final Set<PropertyDescriptor> propertyDescriptors = new TreeSet<>(new PropertyDescriptorComparator());
|
||||
|
||||
|
||||
/**
|
||||
@@ -91,11 +94,9 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||
* through its method descriptors to find any non-void returning write methods and
|
||||
* update or create the corresponding {@link PropertyDescriptor} for each one found.
|
||||
* @param delegate the wrapped {@code BeanInfo}, which is never modified
|
||||
* @throws IntrospectionException if any problems occur creating and adding new
|
||||
* property descriptors
|
||||
* @see #getPropertyDescriptors()
|
||||
*/
|
||||
public ExtendedBeanInfo(BeanInfo delegate) throws IntrospectionException {
|
||||
public ExtendedBeanInfo(BeanInfo delegate) {
|
||||
this.delegate = delegate;
|
||||
for (PropertyDescriptor pd : delegate.getPropertyDescriptors()) {
|
||||
try {
|
||||
@@ -213,9 +214,9 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||
|
||||
|
||||
/**
|
||||
* Return the set of {@link PropertyDescriptor}s from the wrapped {@link BeanInfo}
|
||||
* object as well as {@code PropertyDescriptor}s for each non-void returning setter
|
||||
* method found during construction.
|
||||
* Return the set of {@link PropertyDescriptor PropertyDescriptors} from the wrapped
|
||||
* {@link BeanInfo} object as well as {@code PropertyDescriptors} for each non-void
|
||||
* returning setter method found during construction.
|
||||
* @see #ExtendedBeanInfo(BeanInfo)
|
||||
*/
|
||||
@Override
|
||||
@@ -259,6 +260,9 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A simple {@link PropertyDescriptor}.
|
||||
*/
|
||||
static class SimplePropertyDescriptor extends PropertyDescriptor {
|
||||
|
||||
@Nullable
|
||||
@@ -278,7 +282,9 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||
PropertyDescriptorUtils.copyNonMethodProperties(original, this);
|
||||
}
|
||||
|
||||
public SimplePropertyDescriptor(String propertyName, @Nullable Method readMethod, Method writeMethod) throws IntrospectionException {
|
||||
public SimplePropertyDescriptor(String propertyName, @Nullable Method readMethod, Method writeMethod)
|
||||
throws IntrospectionException {
|
||||
|
||||
super(propertyName, null, null);
|
||||
this.readMethod = readMethod;
|
||||
this.writeMethod = writeMethod;
|
||||
@@ -350,6 +356,9 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A simple {@link IndexedPropertyDescriptor}.
|
||||
*/
|
||||
static class SimpleIndexedPropertyDescriptor extends IndexedPropertyDescriptor {
|
||||
|
||||
@Nullable
|
||||
@@ -379,8 +388,9 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||
PropertyDescriptorUtils.copyNonMethodProperties(original, this);
|
||||
}
|
||||
|
||||
public SimpleIndexedPropertyDescriptor(String propertyName, @Nullable Method readMethod, @Nullable Method writeMethod,
|
||||
@Nullable Method indexedReadMethod, Method indexedWriteMethod) throws IntrospectionException {
|
||||
public SimpleIndexedPropertyDescriptor(String propertyName, @Nullable Method readMethod,
|
||||
@Nullable Method writeMethod, @Nullable Method indexedReadMethod, Method indexedWriteMethod)
|
||||
throws IntrospectionException {
|
||||
|
||||
super(propertyName, null, null, null, null);
|
||||
this.readMethod = readMethod;
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Default implementation of the {@link PropertyValues} interface.
|
||||
* The default implementation of the {@link PropertyValues} interface.
|
||||
* Allows simple manipulation of properties, and provides constructors
|
||||
* to support deep copy and construction from a Map.
|
||||
*
|
||||
@@ -80,7 +80,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||
|
||||
/**
|
||||
* Construct a new MutablePropertyValues object from a Map.
|
||||
* @param original Map with property values keyed by property name Strings
|
||||
* @param original a Map with property values keyed by property name Strings
|
||||
* @see #addPropertyValues(Map)
|
||||
*/
|
||||
public MutablePropertyValues(@Nullable Map<?, ?> original) {
|
||||
@@ -101,7 +101,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||
* PropertyValue objects as-is.
|
||||
* <p>This is a constructor for advanced usage scenarios.
|
||||
* It is not intended for typical programmatic use.
|
||||
* @param propertyValueList List of PropertyValue objects
|
||||
* @param propertyValueList a List of PropertyValue objects
|
||||
*/
|
||||
public MutablePropertyValues(@Nullable List<PropertyValue> propertyValueList) {
|
||||
this.propertyValueList =
|
||||
@@ -145,7 +145,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||
|
||||
/**
|
||||
* Add all property values from the given Map.
|
||||
* @param other Map with property values keyed by property name,
|
||||
* @param other a Map with property values keyed by property name,
|
||||
* which must be a String
|
||||
* @return this in order to allow for adding multiple property values in a chain
|
||||
*/
|
||||
@@ -160,7 +160,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||
/**
|
||||
* Add a PropertyValue object, replacing any existing one for the
|
||||
* corresponding property or getting merged with it (if applicable).
|
||||
* @param pv PropertyValue object to add
|
||||
* @param pv the PropertyValue object to add
|
||||
* @return this in order to allow for adding multiple property values in a chain
|
||||
*/
|
||||
public MutablePropertyValues addPropertyValue(PropertyValue pv) {
|
||||
@@ -348,14 +348,8 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof MutablePropertyValues)) {
|
||||
return false;
|
||||
}
|
||||
MutablePropertyValues that = (MutablePropertyValues) other;
|
||||
return this.propertyValueList.equals(that.propertyValueList);
|
||||
return (this == other || (other instanceof MutablePropertyValues &&
|
||||
this.propertyValueList.equals(((MutablePropertyValues) other).propertyValueList)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,14 +30,12 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
class PropertyDescriptorUtils {
|
||||
abstract class PropertyDescriptorUtils {
|
||||
|
||||
/**
|
||||
* See {@link java.beans.FeatureDescriptor}.
|
||||
*/
|
||||
public static void copyNonMethodProperties(PropertyDescriptor source, PropertyDescriptor target)
|
||||
throws IntrospectionException {
|
||||
|
||||
public static void copyNonMethodProperties(PropertyDescriptor source, PropertyDescriptor target) {
|
||||
target.setExpert(source.isExpert());
|
||||
target.setHidden(source.isHidden());
|
||||
target.setPreferred(source.isPreferred());
|
||||
|
||||
+4
-4
@@ -27,12 +27,12 @@ import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Path;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Currency;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -318,7 +318,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
// Check property-specific editor first.
|
||||
PropertyEditor editor = getCustomEditor(propertyPath, requiredType);
|
||||
if (editor == null) {
|
||||
List<String> strippedPaths = new LinkedList<>();
|
||||
List<String> strippedPaths = new ArrayList<>();
|
||||
addStrippedPropertyPaths(strippedPaths, "", propertyPath);
|
||||
for (Iterator<String> it = strippedPaths.iterator(); it.hasNext() && editor == null;) {
|
||||
String strippedPath = it.next();
|
||||
@@ -438,7 +438,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
if (this.customEditorsForPath != null) {
|
||||
CustomEditorHolder editorHolder = this.customEditorsForPath.get(propertyName);
|
||||
if (editorHolder == null) {
|
||||
List<String> strippedPaths = new LinkedList<>();
|
||||
List<String> strippedPaths = new ArrayList<>();
|
||||
addStrippedPropertyPaths(strippedPaths, "", propertyName);
|
||||
for (Iterator<String> it = strippedPaths.iterator(); it.hasNext() && editorHolder == null;) {
|
||||
String strippedName = it.next();
|
||||
@@ -517,7 +517,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
* Holder for a registered custom editor with property name.
|
||||
* Keeps the PropertyEditor itself plus the type it was registered for.
|
||||
*/
|
||||
private static class CustomEditorHolder {
|
||||
private static final class CustomEditorHolder {
|
||||
|
||||
private final PropertyEditor propertyEditor;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -46,7 +46,7 @@ public interface PropertyValues {
|
||||
* Return the changes since the previous PropertyValues.
|
||||
* Subclasses should also override {@code equals}.
|
||||
* @param old old property values
|
||||
* @return PropertyValues updated or new properties.
|
||||
* @return the updated or new properties.
|
||||
* Return empty PropertyValues if there are no changes.
|
||||
* @see Object#equals
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,21 +17,19 @@
|
||||
package org.springframework.beans.factory;
|
||||
|
||||
/**
|
||||
* Marker superinterface indicating that a bean is eligible to be
|
||||
* notified by the Spring container of a particular framework object
|
||||
* through a callback-style method. Actual method signature is
|
||||
* determined by individual subinterfaces, but should typically
|
||||
* consist of just one void-returning method that accepts a single
|
||||
* argument.
|
||||
* A marker superinterface indicating that a bean is eligible to be notified by the
|
||||
* Spring container of a particular framework object through a callback-style method.
|
||||
* The actual method signature is determined by individual subinterfaces but should
|
||||
* typically consist of just one void-returning method that accepts a single argument.
|
||||
*
|
||||
* <p>Note that merely implementing {@link Aware} provides no default
|
||||
* functionality. Rather, processing must be done explicitly, for example
|
||||
* in a {@link org.springframework.beans.factory.config.BeanPostProcessor BeanPostProcessor}.
|
||||
* <p>Note that merely implementing {@link Aware} provides no default functionality.
|
||||
* Rather, processing must be done explicitly, for example in a
|
||||
* {@link org.springframework.beans.factory.config.BeanPostProcessor}.
|
||||
* Refer to {@link org.springframework.context.support.ApplicationContextAwareProcessor}
|
||||
* and {@link org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory}
|
||||
* for examples of processing {@code *Aware} interface callbacks.
|
||||
* for an example of processing specific {@code *Aware} interface callbacks.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
*/
|
||||
public interface Aware {
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ package org.springframework.beans.factory;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.LinkedList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.FatalBeanException;
|
||||
@@ -135,7 +135,7 @@ public class BeanCreationException extends FatalBeanException {
|
||||
*/
|
||||
public void addRelatedCause(Throwable ex) {
|
||||
if (this.relatedCauses == null) {
|
||||
this.relatedCauses = new LinkedList<>();
|
||||
this.relatedCauses = new ArrayList<>();
|
||||
}
|
||||
this.relatedCauses.add(ex);
|
||||
}
|
||||
|
||||
+10
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -78,7 +78,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
||||
/**
|
||||
* Create a new BeanDefinitionStoreException.
|
||||
* @param resourceDescription description of the resource that the bean definition came from
|
||||
* @param beanName the name of the bean requested
|
||||
* @param beanName the name of the bean
|
||||
* @param msg the detail message (appended to an introductory message that indicates
|
||||
* the resource and the name of the bean)
|
||||
*/
|
||||
@@ -89,21 +89,23 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
||||
/**
|
||||
* Create a new BeanDefinitionStoreException.
|
||||
* @param resourceDescription description of the resource that the bean definition came from
|
||||
* @param beanName the name of the bean requested
|
||||
* @param beanName the name of the bean
|
||||
* @param msg the detail message (appended to an introductory message that indicates
|
||||
* the resource and the name of the bean)
|
||||
* @param cause the root cause (may be {@code null})
|
||||
*/
|
||||
public BeanDefinitionStoreException(@Nullable String resourceDescription, String beanName, String msg, @Nullable Throwable cause) {
|
||||
super("Invalid bean definition with name '" + beanName + "' defined in " + resourceDescription + ": " + msg, cause);
|
||||
public BeanDefinitionStoreException(
|
||||
@Nullable String resourceDescription, String beanName, String msg, @Nullable Throwable cause) {
|
||||
|
||||
super("Invalid bean definition with name '" + beanName + "' defined in " + resourceDescription + ": " + msg,
|
||||
cause);
|
||||
this.resourceDescription = resourceDescription;
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the description of the resource that the bean
|
||||
* definition came from, if any.
|
||||
* Return the description of the resource that the bean definition came from, if available.
|
||||
*/
|
||||
@Nullable
|
||||
public String getResourceDescription() {
|
||||
@@ -111,7 +113,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the bean requested, if any.
|
||||
* Return the name of the bean, if available.
|
||||
*/
|
||||
@Nullable
|
||||
public String getBeanName() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -181,8 +181,7 @@ public interface BeanFactory {
|
||||
* but may also be translated into a conventional by-name lookup based on the name
|
||||
* of the given type. For more extensive retrieval operations across sets of beans,
|
||||
* use {@link ListableBeanFactory} and/or {@link BeanFactoryUtils}.
|
||||
* @param requiredType type the bean must match; can be an interface or superclass.
|
||||
* {@code null} is disallowed.
|
||||
* @param requiredType type the bean must match; can be an interface or superclass
|
||||
* @return an instance of the single bean matching the required type
|
||||
* @throws NoSuchBeanDefinitionException if no bean of the given type was found
|
||||
* @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found
|
||||
@@ -200,8 +199,7 @@ public interface BeanFactory {
|
||||
* but may also be translated into a conventional by-name lookup based on the name
|
||||
* of the given type. For more extensive retrieval operations across sets of beans,
|
||||
* use {@link ListableBeanFactory} and/or {@link BeanFactoryUtils}.
|
||||
* @param requiredType type the bean must match; can be an interface or superclass.
|
||||
* {@code null} is disallowed.
|
||||
* @param requiredType type the bean must match; can be an interface or superclass
|
||||
* @param args arguments to use when creating a bean instance using explicit arguments
|
||||
* (only applied when creating a new instance as opposed to retrieving an existing one)
|
||||
* @return an instance of the bean
|
||||
|
||||
+41
-26
@@ -106,6 +106,8 @@ public abstract class BeanFactoryUtils {
|
||||
}
|
||||
|
||||
|
||||
// Retrieval of bean names
|
||||
|
||||
/**
|
||||
* Count all beans in any hierarchy in which this factory participates.
|
||||
* Includes counts of ancestor bean factories.
|
||||
@@ -113,6 +115,7 @@ public abstract class BeanFactoryUtils {
|
||||
* with the same name) are only counted once.
|
||||
* @param lbf the bean factory
|
||||
* @return count of beans including those defined in ancestor factories
|
||||
* @see #beanNamesIncludingAncestors
|
||||
*/
|
||||
public static int countBeansIncludingAncestors(ListableBeanFactory lbf) {
|
||||
return beanNamesIncludingAncestors(lbf).length;
|
||||
@@ -140,6 +143,7 @@ public abstract class BeanFactoryUtils {
|
||||
* @param type the type that beans must match (as a {@code ResolvableType})
|
||||
* @return the array of matching bean names, or an empty array if none
|
||||
* @since 4.2
|
||||
* @see ListableBeanFactory#getBeanNamesForType(ResolvableType)
|
||||
*/
|
||||
public static String[] beanNamesForTypeIncludingAncestors(ListableBeanFactory lbf, ResolvableType type) {
|
||||
Assert.notNull(lbf, "ListableBeanFactory must not be null");
|
||||
@@ -166,6 +170,7 @@ public abstract class BeanFactoryUtils {
|
||||
* @param lbf the bean factory
|
||||
* @param type the type that beans must match (as a {@code Class})
|
||||
* @return the array of matching bean names, or an empty array if none
|
||||
* @see ListableBeanFactory#getBeanNamesForType(Class)
|
||||
*/
|
||||
public static String[] beanNamesForTypeIncludingAncestors(ListableBeanFactory lbf, Class<?> type) {
|
||||
Assert.notNull(lbf, "ListableBeanFactory must not be null");
|
||||
@@ -200,6 +205,7 @@ public abstract class BeanFactoryUtils {
|
||||
* for this flag will initialize FactoryBeans and "factory-bean" references.
|
||||
* @param type the type that beans must match
|
||||
* @return the array of matching bean names, or an empty array if none
|
||||
* @see ListableBeanFactory#getBeanNamesForType(Class, boolean, boolean)
|
||||
*/
|
||||
public static String[] beanNamesForTypeIncludingAncestors(
|
||||
ListableBeanFactory lbf, Class<?> type, boolean includeNonSingletons, boolean allowEagerInit) {
|
||||
@@ -217,6 +223,35 @@ public abstract class BeanFactoryUtils {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all bean names whose {@code Class} has the supplied {@link Annotation}
|
||||
* type, including those defined in ancestor factories, without creating any bean
|
||||
* instances yet. Will return unique names in case of overridden bean definitions.
|
||||
* @param lbf the bean factory
|
||||
* @param annotationType the type of annotation to look for
|
||||
* @return the array of matching bean names, or an empty array if none
|
||||
* @since 5.0
|
||||
* @see ListableBeanFactory#getBeanNamesForAnnotation(Class)
|
||||
*/
|
||||
public static String[] beanNamesForAnnotationIncludingAncestors(
|
||||
ListableBeanFactory lbf, Class<? extends Annotation> annotationType) {
|
||||
|
||||
Assert.notNull(lbf, "ListableBeanFactory must not be null");
|
||||
String[] result = lbf.getBeanNamesForAnnotation(annotationType);
|
||||
if (lbf instanceof HierarchicalBeanFactory) {
|
||||
HierarchicalBeanFactory hbf = (HierarchicalBeanFactory) lbf;
|
||||
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) {
|
||||
String[] parentResult = beanNamesForAnnotationIncludingAncestors(
|
||||
(ListableBeanFactory) hbf.getParentBeanFactory(), annotationType);
|
||||
result = mergeNamesWithParent(result, parentResult, hbf);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Retrieval of bean instances
|
||||
|
||||
/**
|
||||
* Return all beans of the given type or subtypes, also picking up beans defined in
|
||||
* ancestor bean factories if the current bean factory is a HierarchicalBeanFactory.
|
||||
@@ -233,6 +268,7 @@ public abstract class BeanFactoryUtils {
|
||||
* @param type type of bean to match
|
||||
* @return the Map of matching bean instances, or an empty Map if none
|
||||
* @throws BeansException if a bean could not be created
|
||||
* @see ListableBeanFactory#getBeansOfType(Class)
|
||||
*/
|
||||
public static <T> Map<String, T> beansOfTypeIncludingAncestors(ListableBeanFactory lbf, Class<T> type)
|
||||
throws BeansException {
|
||||
@@ -280,6 +316,7 @@ public abstract class BeanFactoryUtils {
|
||||
* for this flag will initialize FactoryBeans and "factory-bean" references.
|
||||
* @return the Map of matching bean instances, or an empty Map if none
|
||||
* @throws BeansException if a bean could not be created
|
||||
* @see ListableBeanFactory#getBeansOfType(Class, boolean, boolean)
|
||||
*/
|
||||
public static <T> Map<String, T> beansOfTypeIncludingAncestors(
|
||||
ListableBeanFactory lbf, Class<T> type, boolean includeNonSingletons, boolean allowEagerInit)
|
||||
@@ -303,7 +340,6 @@ public abstract class BeanFactoryUtils {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a single bean of the given type or subtypes, also picking up beans
|
||||
* defined in ancestor bean factories if the current bean factory is a
|
||||
@@ -325,6 +361,7 @@ public abstract class BeanFactoryUtils {
|
||||
* @throws NoSuchBeanDefinitionException if no bean of the given type was found
|
||||
* @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found
|
||||
* @throws BeansException if the bean could not be created
|
||||
* @see #beansOfTypeIncludingAncestors(ListableBeanFactory, Class)
|
||||
*/
|
||||
public static <T> T beanOfTypeIncludingAncestors(ListableBeanFactory lbf, Class<T> type)
|
||||
throws BeansException {
|
||||
@@ -333,31 +370,6 @@ public abstract class BeanFactoryUtils {
|
||||
return uniqueBean(type, beansOfType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all bean names whose {@code Class} has the supplied {@link Annotation}
|
||||
* type, including those defined in ancestor factories, without creating any bean
|
||||
* instances yet. Will return unique names in case of overridden bean definitions.
|
||||
* @param lbf the bean factory
|
||||
* @param annotationType the type of annotation to look for
|
||||
* @return the array of matching bean names, or an empty array if none
|
||||
* @since 5.0
|
||||
*/
|
||||
public static String[] beanNamesForAnnotationIncludingAncestors(
|
||||
ListableBeanFactory lbf, Class<? extends Annotation> annotationType) {
|
||||
|
||||
Assert.notNull(lbf, "ListableBeanFactory must not be null");
|
||||
String[] result = lbf.getBeanNamesForAnnotation(annotationType);
|
||||
if (lbf instanceof HierarchicalBeanFactory) {
|
||||
HierarchicalBeanFactory hbf = (HierarchicalBeanFactory) lbf;
|
||||
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) {
|
||||
String[] parentResult = beanNamesForAnnotationIncludingAncestors(
|
||||
(ListableBeanFactory) hbf.getParentBeanFactory(), annotationType);
|
||||
result = mergeNamesWithParent(result, parentResult, hbf);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single bean of the given type or subtypes, also picking up beans
|
||||
* defined in ancestor bean factories if the current bean factory is a
|
||||
@@ -386,6 +398,7 @@ public abstract class BeanFactoryUtils {
|
||||
* @throws NoSuchBeanDefinitionException if no bean of the given type was found
|
||||
* @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found
|
||||
* @throws BeansException if the bean could not be created
|
||||
* @see #beansOfTypeIncludingAncestors(ListableBeanFactory, Class, boolean, boolean)
|
||||
*/
|
||||
public static <T> T beanOfTypeIncludingAncestors(
|
||||
ListableBeanFactory lbf, Class<T> type, boolean includeNonSingletons, boolean allowEagerInit)
|
||||
@@ -410,6 +423,7 @@ public abstract class BeanFactoryUtils {
|
||||
* @throws NoSuchBeanDefinitionException if no bean of the given type was found
|
||||
* @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found
|
||||
* @throws BeansException if the bean could not be created
|
||||
* @see ListableBeanFactory#getBeansOfType(Class)
|
||||
*/
|
||||
public static <T> T beanOfType(ListableBeanFactory lbf, Class<T> type) throws BeansException {
|
||||
Assert.notNull(lbf, "ListableBeanFactory must not be null");
|
||||
@@ -440,6 +454,7 @@ public abstract class BeanFactoryUtils {
|
||||
* @throws NoSuchBeanDefinitionException if no bean of the given type was found
|
||||
* @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found
|
||||
* @throws BeansException if the bean could not be created
|
||||
* @see ListableBeanFactory#getBeansOfType(Class, boolean, boolean)
|
||||
*/
|
||||
public static <T> T beanOfType(
|
||||
ListableBeanFactory lbf, Class<T> type, boolean includeNonSingletons, boolean allowEagerInit)
|
||||
|
||||
+5
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,7 +32,6 @@ public class CannotLoadBeanClassException extends FatalBeanException {
|
||||
@Nullable
|
||||
private String resourceDescription;
|
||||
|
||||
@Nullable
|
||||
private String beanName;
|
||||
|
||||
@Nullable
|
||||
@@ -47,8 +46,8 @@ public class CannotLoadBeanClassException extends FatalBeanException {
|
||||
* @param beanClassName the name of the bean class
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public CannotLoadBeanClassException(
|
||||
@Nullable String resourceDescription, String beanName, @Nullable String beanClassName, ClassNotFoundException cause) {
|
||||
public CannotLoadBeanClassException(@Nullable String resourceDescription, String beanName,
|
||||
@Nullable String beanClassName, ClassNotFoundException cause) {
|
||||
|
||||
super("Cannot find class [" + beanClassName + "] for bean with name '" + beanName + "'" +
|
||||
(resourceDescription != null ? " defined in " + resourceDescription : ""), cause);
|
||||
@@ -65,8 +64,8 @@ public class CannotLoadBeanClassException extends FatalBeanException {
|
||||
* @param beanClassName the name of the bean class
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public CannotLoadBeanClassException(
|
||||
@Nullable String resourceDescription, String beanName, @Nullable String beanClassName, LinkageError cause) {
|
||||
public CannotLoadBeanClassException(@Nullable String resourceDescription, String beanName,
|
||||
@Nullable String beanClassName, LinkageError cause) {
|
||||
|
||||
super("Error loading class [" + beanClassName + "] for bean with name '" + beanName + "'" +
|
||||
(resourceDescription != null ? " defined in " + resourceDescription : "") +
|
||||
@@ -89,7 +88,6 @@ public class CannotLoadBeanClassException extends FatalBeanException {
|
||||
/**
|
||||
* Return the name of the bean requested.
|
||||
*/
|
||||
@Nullable
|
||||
public String getBeanName() {
|
||||
return this.beanName;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,28 +17,29 @@
|
||||
package org.springframework.beans.factory;
|
||||
|
||||
/**
|
||||
* Interface to be implemented by beans that want to release resources
|
||||
* on destruction. A BeanFactory is supposed to invoke the destroy
|
||||
* method if it disposes a cached singleton. An application context
|
||||
* is supposed to dispose all of its singletons on close.
|
||||
* Interface to be implemented by beans that want to release resources on destruction.
|
||||
* A {@link BeanFactory} will invoke the destroy method on individual destruction of a
|
||||
* scoped bean. An {@link org.springframework.context.ApplicationContext} is supposed
|
||||
* to dispose all of its singletons on shutdown, driven by the application lifecycle.
|
||||
*
|
||||
* <p>An alternative to implementing DisposableBean is specifying a custom
|
||||
* destroy-method, for example in an XML bean definition.
|
||||
* For a list of all bean lifecycle methods, see the
|
||||
* {@link BeanFactory BeanFactory javadocs}.
|
||||
* <p>A Spring-managed bean may also implement Java's {@link AutoCloseable} interface
|
||||
* for the same purpose. An alternative to implementing an interface is specifying a
|
||||
* custom destroy method, for example in an XML bean definition. For a list of all
|
||||
* bean lifecycle methods, see the {@link BeanFactory BeanFactory javadocs}.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 12.08.2003
|
||||
* @see org.springframework.beans.factory.support.RootBeanDefinition#getDestroyMethodName
|
||||
* @see org.springframework.context.ConfigurableApplicationContext#close
|
||||
* @see InitializingBean
|
||||
* @see org.springframework.beans.factory.support.RootBeanDefinition#getDestroyMethodName()
|
||||
* @see org.springframework.beans.factory.config.ConfigurableBeanFactory#destroySingletons()
|
||||
* @see org.springframework.context.ConfigurableApplicationContext#close()
|
||||
*/
|
||||
public interface DisposableBean {
|
||||
|
||||
/**
|
||||
* Invoked by a BeanFactory on destruction of a singleton.
|
||||
* @throws Exception in case of shutdown errors.
|
||||
* Exceptions will get logged but not rethrown to allow
|
||||
* other beans to release their resources too.
|
||||
* Invoked by the containing {@code BeanFactory} on destruction of a bean.
|
||||
* @throws Exception in case of shutdown errors. Exceptions will get logged
|
||||
* but not rethrown to allow other beans to release their resources as well.
|
||||
*/
|
||||
void destroy() throws Exception;
|
||||
|
||||
|
||||
+17
-20
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,32 +17,29 @@
|
||||
package org.springframework.beans.factory;
|
||||
|
||||
/**
|
||||
* Interface to be implemented by beans that need to react once all their
|
||||
* properties have been set by a BeanFactory: for example, to perform custom
|
||||
* initialization, or merely to check that all mandatory properties have been set.
|
||||
* Interface to be implemented by beans that need to react once all their properties
|
||||
* have been set by a {@link BeanFactory}: e.g. to perform custom initialization,
|
||||
* or merely to check that all mandatory properties have been set.
|
||||
*
|
||||
* <p>An alternative to implementing InitializingBean is specifying a custom
|
||||
* init-method, for example in an XML bean definition.
|
||||
* For a list of all bean lifecycle methods, see the
|
||||
* {@link BeanFactory BeanFactory javadocs}.
|
||||
* <p>An alternative to implementing {@code InitializingBean} is specifying a custom
|
||||
* init method, for example in an XML bean definition. For a list of all bean
|
||||
* lifecycle methods, see the {@link BeanFactory BeanFactory javadocs}.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @see BeanNameAware
|
||||
* @see BeanFactoryAware
|
||||
* @see BeanFactory
|
||||
* @see org.springframework.beans.factory.support.RootBeanDefinition#getInitMethodName
|
||||
* @see org.springframework.context.ApplicationContextAware
|
||||
* @author Juergen Hoeller
|
||||
* @see DisposableBean
|
||||
* @see org.springframework.beans.factory.config.BeanDefinition#getPropertyValues()
|
||||
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#getInitMethodName()
|
||||
*/
|
||||
public interface InitializingBean {
|
||||
|
||||
/**
|
||||
* Invoked by a BeanFactory after it has set all bean properties supplied
|
||||
* (and satisfied BeanFactoryAware and ApplicationContextAware).
|
||||
* <p>This method allows the bean instance to perform initialization only
|
||||
* possible when all bean properties have been set and to throw an
|
||||
* exception in the event of misconfiguration.
|
||||
* @throws Exception in the event of misconfiguration (such
|
||||
* as failure to set an essential property) or if initialization fails.
|
||||
* Invoked by the containing {@code BeanFactory} after it has set all bean properties
|
||||
* and satisfied {@link BeanFactoryAware}, {@code ApplicationContextAware} etc.
|
||||
* <p>This method allows the bean instance to perform validation of its overall
|
||||
* configuration and final initialization when all bean properties have been set.
|
||||
* @throws Exception in the event of misconfiguration (such as failure to set an
|
||||
* essential property) or if initialization fails for any other reason
|
||||
*/
|
||||
void afterPropertiesSet() throws Exception;
|
||||
|
||||
|
||||
+15
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,15 +23,22 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Marks a constructor, field, setter method or config method as to be autowired
|
||||
* by Spring's dependency injection facilities.
|
||||
* Marks a constructor, field, setter method or config method as to be autowired by
|
||||
* Spring's dependency injection facilities. This is an alternative to the JSR-330
|
||||
* {@link javax.inject.Inject} annotation, adding required-vs-optional semantics.
|
||||
*
|
||||
* <p>Only one constructor (at max) of any given bean class may carry this annotation,
|
||||
* indicating the constructor to autowire when used as a Spring bean. Such a
|
||||
* constructor does not have to be public.
|
||||
* <p>Only one constructor (at max) of any given bean class may declare this annotation
|
||||
* with the 'required' parameter set to {@code true}, indicating <i>the</i> constructor
|
||||
* to autowire when used as a Spring bean. If multiple <i>non-required</i> constructors
|
||||
* declare the annotation, they will be considered as candidates for autowiring.
|
||||
* The constructor with the greatest number of dependencies that can be satisfied by
|
||||
* matching beans in the Spring container will be chosen. If none of the candidates
|
||||
* can be satisfied, then a primary/default constructor (if present) will be used.
|
||||
* If a class only declares a single constructor to begin with, it will always be used,
|
||||
* even if not annotated. An annotated constructor does not have to be public.
|
||||
*
|
||||
* <p>Fields are injected right after construction of a bean, before any config
|
||||
* methods are invoked. Such a config field does not have to be public.
|
||||
* <p>Fields are injected right after construction of a bean, before any config methods
|
||||
* are invoked. Such a config field does not have to be public.
|
||||
*
|
||||
* <p>Config methods may have an arbitrary name and any number of arguments; each of
|
||||
* those arguments will be autowired with a matching bean in the Spring container.
|
||||
|
||||
+30
-33
@@ -28,7 +28,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -75,15 +74,15 @@ import org.springframework.util.StringUtils;
|
||||
* <p>Also supports JSR-330's {@link javax.inject.Inject @Inject} annotation,
|
||||
* if available, as a direct alternative to Spring's own {@code @Autowired}.
|
||||
*
|
||||
* <p>Only one constructor (at max) of any given bean class may carry this
|
||||
* annotation with the 'required' parameter set to {@code true},
|
||||
* indicating <i>the</i> constructor to autowire when used as a Spring bean.
|
||||
* If multiple <i>non-required</i> constructors carry the annotation, they
|
||||
* will be considered as candidates for autowiring. The constructor with
|
||||
* the greatest number of dependencies that can be satisfied by matching
|
||||
* beans in the Spring container will be chosen. If none of the candidates
|
||||
* can be satisfied, then a default constructor (if present) will be used.
|
||||
* An annotated constructor does not have to be public.
|
||||
* <p>Only one constructor (at max) of any given bean class may declare this annotation
|
||||
* with the 'required' parameter set to {@code true}, indicating <i>the</i> constructor
|
||||
* to autowire when used as a Spring bean. If multiple <i>non-required</i> constructors
|
||||
* declare the annotation, they will be considered as candidates for autowiring.
|
||||
* The constructor with the greatest number of dependencies that can be satisfied by
|
||||
* matching beans in the Spring container will be chosen. If none of the candidates
|
||||
* can be satisfied, then a primary/default constructor (if present) will be used.
|
||||
* If a class only declares a single constructor to begin with, it will always be used,
|
||||
* even if not annotated. An annotated constructor does not have to be public.
|
||||
*
|
||||
* <p>Fields are injected right after construction of a bean, before any
|
||||
* config methods are invoked. Such a config field does not have to be public.
|
||||
@@ -121,7 +120,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private final Set<Class<? extends Annotation>> autowiredAnnotationTypes = new LinkedHashSet<>();
|
||||
private final Set<Class<? extends Annotation>> autowiredAnnotationTypes = new LinkedHashSet<>(4);
|
||||
|
||||
private String requiredParameterName = "required";
|
||||
|
||||
@@ -162,11 +161,11 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
/**
|
||||
* Set the 'autowired' annotation type, to be used on constructors, fields,
|
||||
* setter methods and arbitrary config methods.
|
||||
* <p>The default autowired annotation type is the Spring-provided
|
||||
* {@link Autowired} annotation, as well as {@link Value}.
|
||||
* <p>The default autowired annotation type is the Spring-provided {@link Autowired}
|
||||
* annotation, as well as {@link Value}.
|
||||
* <p>This setter property exists so that developers can provide their own
|
||||
* (non-Spring-specific) annotation type to indicate that a member is
|
||||
* supposed to be autowired.
|
||||
* (non-Spring-specific) annotation type to indicate that a member is supposed
|
||||
* to be autowired.
|
||||
*/
|
||||
public void setAutowiredAnnotationType(Class<? extends Annotation> autowiredAnnotationType) {
|
||||
Assert.notNull(autowiredAnnotationType, "'autowiredAnnotationType' must not be null");
|
||||
@@ -177,11 +176,11 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
/**
|
||||
* Set the 'autowired' annotation types, to be used on constructors, fields,
|
||||
* setter methods and arbitrary config methods.
|
||||
* <p>The default autowired annotation type is the Spring-provided
|
||||
* {@link Autowired} annotation, as well as {@link Value}.
|
||||
* <p>The default autowired annotation type is the Spring-provided {@link Autowired}
|
||||
* annotation, as well as {@link Value}.
|
||||
* <p>This setter property exists so that developers can provide their own
|
||||
* (non-Spring-specific) annotation types to indicate that a member is
|
||||
* supposed to be autowired.
|
||||
* (non-Spring-specific) annotation types to indicate that a member is supposed
|
||||
* to be autowired.
|
||||
*/
|
||||
public void setAutowiredAnnotationTypes(Set<Class<? extends Annotation>> autowiredAnnotationTypes) {
|
||||
Assert.notEmpty(autowiredAnnotationTypes, "'autowiredAnnotationTypes' must not be empty");
|
||||
@@ -190,8 +189,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of a parameter of the annotation that specifies
|
||||
* whether it is required.
|
||||
* Set the name of a parameter of the annotation that specifies whether it is required.
|
||||
* @see #setRequiredParameterValue(boolean)
|
||||
*/
|
||||
public void setRequiredParameterName(String requiredParameterName) {
|
||||
@@ -200,9 +198,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
|
||||
/**
|
||||
* Set the boolean value that marks a dependency as required
|
||||
* <p>For example if using 'required=true' (the default),
|
||||
* this value should be {@code true}; but if using
|
||||
* 'optional=false', this value should be {@code false}.
|
||||
* <p>For example if using 'required=true' (the default), this value should be
|
||||
* {@code true}; but if using 'optional=false', this value should be {@code false}.
|
||||
* @see #setRequiredParameterName(String)
|
||||
*/
|
||||
public void setRequiredParameterValue(boolean requiredParameterValue) {
|
||||
@@ -245,15 +242,15 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
ReflectionUtils.doWithMethods(beanClass, method -> {
|
||||
Lookup lookup = method.getAnnotation(Lookup.class);
|
||||
if (lookup != null) {
|
||||
Assert.state(beanFactory != null, "No BeanFactory available");
|
||||
Assert.state(this.beanFactory != null, "No BeanFactory available");
|
||||
LookupOverride override = new LookupOverride(method, lookup.value());
|
||||
try {
|
||||
RootBeanDefinition mbd = (RootBeanDefinition) beanFactory.getMergedBeanDefinition(beanName);
|
||||
RootBeanDefinition mbd = (RootBeanDefinition) this.beanFactory.getMergedBeanDefinition(beanName);
|
||||
mbd.getMethodOverrides().addOverride(override);
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException ex) {
|
||||
throw new BeanCreationException(beanName,
|
||||
"Cannot apply @Lookup to beans without corresponding bean definition");
|
||||
"Cannot apply @Lookup to beans without corresponding bean definition");
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -347,8 +344,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
else if (rawCandidates.length == 1 && rawCandidates[0].getParameterCount() > 0) {
|
||||
candidateConstructors = new Constructor<?>[] {rawCandidates[0]};
|
||||
}
|
||||
else if (nonSyntheticConstructors == 2 && primaryConstructor != null
|
||||
&& defaultConstructor != null && !primaryConstructor.equals(defaultConstructor)) {
|
||||
else if (nonSyntheticConstructors == 2 && primaryConstructor != null &&
|
||||
defaultConstructor != null && !primaryConstructor.equals(defaultConstructor)) {
|
||||
candidateConstructors = new Constructor<?>[] {primaryConstructor, defaultConstructor};
|
||||
}
|
||||
else if (nonSyntheticConstructors == 1 && primaryConstructor != null) {
|
||||
@@ -424,11 +421,11 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
}
|
||||
|
||||
private InjectionMetadata buildAutowiringMetadata(final Class<?> clazz) {
|
||||
LinkedList<InjectionMetadata.InjectedElement> elements = new LinkedList<>();
|
||||
List<InjectionMetadata.InjectedElement> elements = new ArrayList<>();
|
||||
Class<?> targetClass = clazz;
|
||||
|
||||
do {
|
||||
final LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<>();
|
||||
final List<InjectionMetadata.InjectedElement> currElements = new ArrayList<>();
|
||||
|
||||
ReflectionUtils.doWithLocalFields(targetClass, field -> {
|
||||
AnnotationAttributes ann = findAutowiredAnnotation(field);
|
||||
@@ -479,7 +476,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
|
||||
@Nullable
|
||||
private AnnotationAttributes findAutowiredAnnotation(AccessibleObject ao) {
|
||||
if (ao.getAnnotations().length > 0) {
|
||||
if (ao.getAnnotations().length > 0) { // autowiring annotations have to be local
|
||||
for (Class<? extends Annotation> type : this.autowiredAnnotationTypes) {
|
||||
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(ao, type);
|
||||
if (attributes != null) {
|
||||
@@ -541,7 +538,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
private Object resolvedCachedArgument(@Nullable String beanName, @Nullable Object cachedArgument) {
|
||||
if (cachedArgument instanceof DependencyDescriptor) {
|
||||
DependencyDescriptor descriptor = (DependencyDescriptor) cachedArgument;
|
||||
Assert.state(beanFactory != null, "No BeanFactory available");
|
||||
Assert.state(this.beanFactory != null, "No BeanFactory available");
|
||||
return this.beanFactory.resolveDependency(descriptor, beanName, null, null);
|
||||
}
|
||||
else {
|
||||
|
||||
+13
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,11 +22,11 @@ import java.util.function.Predicate;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||
import org.springframework.beans.factory.ListableBeanFactory;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.AutowireCandidateQualifier;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
@@ -35,8 +35,8 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Convenience methods performing bean lookups related to annotations, for example
|
||||
* Spring's {@link Qualifier @Qualifier} annotation.
|
||||
* Convenience methods performing bean lookups related to Spring-specific annotations,
|
||||
* for example Spring's {@link Qualifier @Qualifier} annotation.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
@@ -49,23 +49,23 @@ public abstract class BeanFactoryAnnotationUtils {
|
||||
* Obtain a bean of type {@code T} from the given {@code BeanFactory} declaring a
|
||||
* qualifier (e.g. via {@code <qualifier>} or {@code @Qualifier}) matching the given
|
||||
* qualifier, or having a bean name matching the given qualifier.
|
||||
* @param beanFactory the BeanFactory to get the target bean from
|
||||
* @param beanFactory the factory to get the target bean from (also searching ancestors)
|
||||
* @param beanType the type of bean to retrieve
|
||||
* @param qualifier the qualifier for selecting between multiple bean matches
|
||||
* @return the matching bean of type {@code T} (never {@code null})
|
||||
* @throws NoUniqueBeanDefinitionException if multiple matching beans of type {@code T} found
|
||||
* @throws NoSuchBeanDefinitionException if no matching bean of type {@code T} found
|
||||
* @throws BeansException if the bean could not be created
|
||||
* @see BeanFactory#getBean(Class)
|
||||
* @see BeanFactoryUtils#beanOfTypeIncludingAncestors(ListableBeanFactory, Class)
|
||||
*/
|
||||
public static <T> T qualifiedBeanOfType(BeanFactory beanFactory, Class<T> beanType, String qualifier)
|
||||
throws BeansException {
|
||||
|
||||
Assert.notNull(beanFactory, "BeanFactory must not be null");
|
||||
|
||||
if (beanFactory instanceof ConfigurableListableBeanFactory) {
|
||||
if (beanFactory instanceof ListableBeanFactory) {
|
||||
// Full qualifier matching supported.
|
||||
return qualifiedBeanOfType((ConfigurableListableBeanFactory) beanFactory, beanType, qualifier);
|
||||
return qualifiedBeanOfType((ListableBeanFactory) beanFactory, beanType, qualifier);
|
||||
}
|
||||
else if (beanFactory.containsBean(qualifier)) {
|
||||
// Fallback: target bean at least found by bean name.
|
||||
@@ -82,12 +82,12 @@ public abstract class BeanFactoryAnnotationUtils {
|
||||
/**
|
||||
* Obtain a bean of type {@code T} from the given {@code BeanFactory} declaring a qualifier
|
||||
* (e.g. {@code <qualifier>} or {@code @Qualifier}) matching the given qualifier).
|
||||
* @param bf the BeanFactory to get the target bean from
|
||||
* @param bf the factory to get the target bean from
|
||||
* @param beanType the type of bean to retrieve
|
||||
* @param qualifier the qualifier for selecting between multiple bean matches
|
||||
* @return the matching bean of type {@code T} (never {@code null})
|
||||
*/
|
||||
private static <T> T qualifiedBeanOfType(ConfigurableListableBeanFactory bf, Class<T> beanType, String qualifier) {
|
||||
private static <T> T qualifiedBeanOfType(ListableBeanFactory bf, Class<T> beanType, String qualifier) {
|
||||
String[] candidateBeans = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(bf, beanType);
|
||||
String matchingBean = null;
|
||||
for (String beanName : candidateBeans) {
|
||||
@@ -115,14 +115,14 @@ public abstract class BeanFactoryAnnotationUtils {
|
||||
* Check whether the named bean declares a qualifier of the given name.
|
||||
* @param qualifier the qualifier to match
|
||||
* @param beanName the name of the candidate bean
|
||||
* @param beanFactory the {@code BeanFactory} from which to retrieve the named bean
|
||||
* @param beanFactory the factory from which to retrieve the named bean
|
||||
* @return {@code true} if either the bean definition (in the XML case)
|
||||
* or the bean's factory method (in the {@code @Bean} case) defines a matching
|
||||
* qualifier value (through {@code <qualifier>} or {@code @Qualifier})
|
||||
* @since 5.0
|
||||
*/
|
||||
public static boolean isQualifierMatch(Predicate<String> qualifier, String beanName,
|
||||
@Nullable BeanFactory beanFactory) {
|
||||
public static boolean isQualifierMatch(
|
||||
Predicate<String> qualifier, String beanName, @Nullable BeanFactory beanFactory) {
|
||||
|
||||
// Try quick bean name or alias match first...
|
||||
if (qualifier.test(beanName)) {
|
||||
|
||||
+8
-7
@@ -23,9 +23,10 @@ import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -196,23 +197,23 @@ public class InitDestroyAnnotationBeanPostProcessor
|
||||
|
||||
private LifecycleMetadata buildLifecycleMetadata(final Class<?> clazz) {
|
||||
final boolean debug = logger.isDebugEnabled();
|
||||
LinkedList<LifecycleElement> initMethods = new LinkedList<>();
|
||||
LinkedList<LifecycleElement> destroyMethods = new LinkedList<>();
|
||||
List<LifecycleElement> initMethods = new ArrayList<>();
|
||||
List<LifecycleElement> destroyMethods = new ArrayList<>();
|
||||
Class<?> targetClass = clazz;
|
||||
|
||||
do {
|
||||
final LinkedList<LifecycleElement> currInitMethods = new LinkedList<>();
|
||||
final LinkedList<LifecycleElement> currDestroyMethods = new LinkedList<>();
|
||||
final List<LifecycleElement> currInitMethods = new ArrayList<>();
|
||||
final List<LifecycleElement> currDestroyMethods = new ArrayList<>();
|
||||
|
||||
ReflectionUtils.doWithLocalMethods(targetClass, method -> {
|
||||
if (initAnnotationType != null && method.isAnnotationPresent(initAnnotationType)) {
|
||||
if (this.initAnnotationType != null && method.isAnnotationPresent(this.initAnnotationType)) {
|
||||
LifecycleElement element = new LifecycleElement(method);
|
||||
currInitMethods.add(element);
|
||||
if (debug) {
|
||||
logger.debug("Found init method on class [" + clazz.getName() + "]: " + method);
|
||||
}
|
||||
}
|
||||
if (destroyAnnotationType != null && method.isAnnotationPresent(destroyAnnotationType)) {
|
||||
if (this.destroyAnnotationType != null && method.isAnnotationPresent(this.destroyAnnotationType)) {
|
||||
currDestroyMethods.add(new LifecycleElement(method));
|
||||
if (debug) {
|
||||
logger.debug("Found destroy method on class [" + clazz.getName() + "]: " + method);
|
||||
|
||||
+7
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -83,9 +83,8 @@ public class InjectionMetadata {
|
||||
Collection<InjectedElement> elementsToIterate =
|
||||
(checkedElements != null ? checkedElements : this.injectedElements);
|
||||
if (!elementsToIterate.isEmpty()) {
|
||||
boolean debug = logger.isDebugEnabled();
|
||||
for (InjectedElement element : elementsToIterate) {
|
||||
if (debug) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Processing injected element of bean '" + beanName + "': " + element);
|
||||
}
|
||||
element.inject(target, beanName, pvs);
|
||||
@@ -94,6 +93,7 @@ public class InjectionMetadata {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear property skipping for the contained elements.
|
||||
* @since 3.2.13
|
||||
*/
|
||||
public void clear(@Nullable PropertyValues pvs) {
|
||||
@@ -113,6 +113,9 @@ public class InjectionMetadata {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A single injected element.
|
||||
*/
|
||||
public abstract static class InjectedElement {
|
||||
|
||||
protected final Member member;
|
||||
@@ -226,6 +229,7 @@ public class InjectionMetadata {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear property skipping for this element.
|
||||
* @since 3.2.13
|
||||
*/
|
||||
protected void clearPropertySkipping(@Nullable PropertyValues pvs) {
|
||||
|
||||
+7
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -347,10 +347,12 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
|
||||
*/
|
||||
@Nullable
|
||||
protected Object findValue(Annotation[] annotationsToSearch) {
|
||||
AnnotationAttributes attr = AnnotatedElementUtils.getMergedAnnotationAttributes(
|
||||
AnnotatedElementUtils.forAnnotations(annotationsToSearch), this.valueAnnotationType);
|
||||
if (attr != null) {
|
||||
return extractValue(attr);
|
||||
if (annotationsToSearch.length > 0) { // qualifier annotations have to be local
|
||||
AnnotationAttributes attr = AnnotatedElementUtils.getMergedAnnotationAttributes(
|
||||
AnnotatedElementUtils.forAnnotations(annotationsToSearch), this.valueAnnotationType);
|
||||
if (attr != null) {
|
||||
return extractValue(attr);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -56,8 +56,8 @@ import org.springframework.util.Assert;
|
||||
* and obviates the need (<b>in part</b>) for a developer to code a method that
|
||||
* simply checks that all required properties have actually been set.
|
||||
*
|
||||
* <p>Please note that an 'init' method may still need to implemented (and may
|
||||
* still be desirable), because all that this class does is enforce that a
|
||||
* <p>Please note that an 'init' method may still need to be implemented (and may
|
||||
* still be desirable), because all that this class does is enforcing that a
|
||||
* 'required' property has actually been configured with a value. It does
|
||||
* <b>not</b> check anything else... In particular, it does not check that a
|
||||
* configured value is not {@code null}.
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -160,7 +160,7 @@ public abstract class AbstractFactoryBean<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine an 'eager singleton' instance, exposed in case of a
|
||||
* Determine an 'early singleton' instance, exposed in case of a
|
||||
* circular reference. Not called in a non-circular scenario.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -225,7 +225,7 @@ public abstract class AbstractFactoryBean<T>
|
||||
* FactoryBean is supposed to implement, for use with an 'early singleton
|
||||
* proxy' that will be exposed in case of a circular reference.
|
||||
* <p>The default implementation returns this FactoryBean's object type,
|
||||
* provided that it is an interface, or {@code null} else. The latter
|
||||
* provided that it is an interface, or {@code null} otherwise. The latter
|
||||
* indicates that early singleton access is not supported by this FactoryBean.
|
||||
* This will lead to a FactoryBeanNotInitializedException getting thrown.
|
||||
* @return the interfaces to use for 'early singletons',
|
||||
|
||||
+4
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -89,7 +89,9 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
|
||||
void setBeanClassLoader(@Nullable ClassLoader beanClassLoader);
|
||||
|
||||
/**
|
||||
* Return this factory's class loader for loading bean classes.
|
||||
* Return this factory's class loader for loading bean classes
|
||||
* (only {@code null} if even the system ClassLoader isn't accessible).
|
||||
* @see org.springframework.util.ClassUtils#forName(String, ClassLoader)
|
||||
*/
|
||||
@Nullable
|
||||
ClassLoader getBeanClassLoader();
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -43,9 +43,9 @@ import org.springframework.util.ObjectUtils;
|
||||
*/
|
||||
public class ConstructorArgumentValues {
|
||||
|
||||
private final Map<Integer, ValueHolder> indexedArgumentValues = new LinkedHashMap<>(0);
|
||||
private final Map<Integer, ValueHolder> indexedArgumentValues = new LinkedHashMap<>();
|
||||
|
||||
private final List<ValueHolder> genericArgumentValues = new LinkedList<>();
|
||||
private final List<ValueHolder> genericArgumentValues = new ArrayList<>();
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+2
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -296,7 +296,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
|
||||
/**
|
||||
* Return whether a fallback match is allowed.
|
||||
* <p>This is {@code false} by default but may be overridden to return {@code true} in order
|
||||
* to suggest to a {@link org.springframework.beans.factory.support.AutowireCandidateResolver}
|
||||
* to suggest to an {@link org.springframework.beans.factory.support.AutowireCandidateResolver}
|
||||
* that a fallback match is acceptable as well.
|
||||
* @since 4.0
|
||||
*/
|
||||
@@ -352,7 +352,6 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
|
||||
Type[] args = ((ParameterizedType) type).getActualTypeArguments();
|
||||
type = args[args.length - 1];
|
||||
}
|
||||
// TODO: Object.class if unresolvable
|
||||
}
|
||||
if (type instanceof Class) {
|
||||
return (Class<?>) type;
|
||||
|
||||
+11
-18
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,32 +30,25 @@ import org.springframework.beans.BeansException;
|
||||
public interface DestructionAwareBeanPostProcessor extends BeanPostProcessor {
|
||||
|
||||
/**
|
||||
* Apply this BeanPostProcessor to the given bean instance before
|
||||
* its destruction. Can invoke custom destruction callbacks.
|
||||
* <p>Like DisposableBean's {@code destroy} and a custom destroy method,
|
||||
* this callback just applies to singleton beans in the factory (including
|
||||
* inner beans).
|
||||
* Apply this BeanPostProcessor to the given bean instance before its
|
||||
* destruction, e.g. invoking custom destruction callbacks.
|
||||
* <p>Like DisposableBean's {@code destroy} and a custom destroy method, this
|
||||
* callback will only apply to beans which the container fully manages the
|
||||
* lifecycle for. This is usually the case for singletons and scoped beans.
|
||||
* @param bean the bean instance to be destroyed
|
||||
* @param beanName the name of the bean
|
||||
* @throws org.springframework.beans.BeansException in case of errors
|
||||
* @see org.springframework.beans.factory.DisposableBean
|
||||
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#setDestroyMethodName
|
||||
* @see org.springframework.beans.factory.DisposableBean#destroy()
|
||||
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#setDestroyMethodName(String)
|
||||
*/
|
||||
void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException;
|
||||
|
||||
/**
|
||||
* Determine whether the given bean instance requires destruction by this
|
||||
* post-processor.
|
||||
* <p><b>NOTE:</b> Even as a late addition, this method has been introduced on
|
||||
* {@code DestructionAwareBeanPostProcessor} itself instead of on a SmartDABPP
|
||||
* subinterface. This allows existing {@code DestructionAwareBeanPostProcessor}
|
||||
* implementations to easily provide {@code requiresDestruction} logic while
|
||||
* retaining compatibility with Spring <4.3, and it is also an easier onramp to
|
||||
* declaring {@code requiresDestruction} as a Java 8 default method in Spring 5.
|
||||
* <p>If an implementation of {@code DestructionAwareBeanPostProcessor} does
|
||||
* not provide a concrete implementation of this method, Spring's invocation
|
||||
* mechanism silently assumes a method returning {@code true} (the effective
|
||||
* default before 4.3, and the to-be-default in the Java 8 method in Spring 5).
|
||||
* <p>The default implementation returns {@code true}. If a pre-5 implementation
|
||||
* of {@code DestructionAwareBeanPostProcessor} does not provide a concrete
|
||||
* implementation of this method, Spring silently assumes {@code true} as well.
|
||||
* @param bean the bean instance to check
|
||||
* @return {@code true} if {@link #postProcessBeforeDestruction} is supposed to
|
||||
* be called for this bean instance eventually, or {@code false} if not needed
|
||||
|
||||
+1
-1
@@ -202,7 +202,7 @@ public class FieldRetrievingFactoryBean
|
||||
}
|
||||
|
||||
// Try to get the exact method first.
|
||||
Class<?> targetClass = (this.targetObject != null) ? this.targetObject.getClass() : this.targetClass;
|
||||
Class<?> targetClass = (this.targetObject != null ? this.targetObject.getClass() : this.targetClass);
|
||||
this.fieldObject = targetClass.getField(this.targetField);
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -55,7 +55,7 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
|
||||
* {@link #postProcessAfterInitialization} callback from the configured
|
||||
* {@link BeanPostProcessor BeanPostProcessors}.
|
||||
* <p>This callback will only be applied to bean definitions with a bean class.
|
||||
* In particular, it will not be applied to beans with a "factory-method".
|
||||
* In particular, it will not be applied to beans with a factory method.
|
||||
* <p>Post-processors may implement the extended
|
||||
* {@link SmartInstantiationAwareBeanPostProcessor} interface in order
|
||||
* to predict the type of the bean object that they are going to return here.
|
||||
@@ -65,8 +65,8 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
|
||||
* @return the bean object to expose instead of a default instance of the target bean,
|
||||
* or {@code null} to proceed with default instantiation
|
||||
* @throws org.springframework.beans.BeansException in case of errors
|
||||
* @see #postProcessAfterInstantiation
|
||||
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#hasBeanClass
|
||||
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#getFactoryMethodName
|
||||
*/
|
||||
@Nullable
|
||||
default Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
|
||||
@@ -86,6 +86,7 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
|
||||
* Returning {@code false} will also prevent any subsequent InstantiationAwareBeanPostProcessor
|
||||
* instances being invoked on this bean instance.
|
||||
* @throws org.springframework.beans.BeansException in case of errors
|
||||
* @see #postProcessBeforeInstantiation
|
||||
*/
|
||||
default boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
|
||||
return true;
|
||||
@@ -104,9 +105,8 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
|
||||
* dependency types - which the factory handles specifically - already filtered out)
|
||||
* @param bean the bean instance created, but whose properties have not yet been set
|
||||
* @param beanName the name of the bean
|
||||
* @return the actual property values to apply to the given bean
|
||||
* (can be the passed-in PropertyValues instance), or {@code null}
|
||||
* to skip property population
|
||||
* @return the actual property values to apply to the given bean (can be the passed-in
|
||||
* PropertyValues instance), or {@code null} to skip property population
|
||||
* @throws org.springframework.beans.BeansException in case of errors
|
||||
* @see org.springframework.beans.MutablePropertyValues
|
||||
*/
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -42,7 +42,7 @@ public abstract class InstantiationAwareBeanPostProcessorAdapter implements Smar
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Class<?> predictBeanType(Class<?> beanClass, String beanName) {
|
||||
public Class<?> predictBeanType(Class<?> beanClass, String beanName) throws BeansException {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -64,6 +64,8 @@ import org.springframework.lang.Nullable;
|
||||
* Note that the value of "foo" in the first document is not simply replaced
|
||||
* with the value in the second, but its nested values are merged.
|
||||
*
|
||||
* <p>Requires SnakeYAML 1.18 or higher, as of Spring Framework 5.0.6.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Juergen Hoeller
|
||||
* @since 4.1
|
||||
|
||||
+27
-13
@@ -30,6 +30,7 @@ import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.yaml.snakeyaml.LoaderOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
import org.yaml.snakeyaml.nodes.MappingNode;
|
||||
@@ -45,6 +46,8 @@ import org.springframework.util.StringUtils;
|
||||
/**
|
||||
* Base class for YAML factories.
|
||||
*
|
||||
* <p>Requires SnakeYAML 1.18 or higher, as of Spring Framework 5.0.6.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Juergen Hoeller
|
||||
* @since 4.1
|
||||
@@ -77,15 +80,16 @@ public abstract class YamlProcessor {
|
||||
* name: My Cool App
|
||||
* </pre>
|
||||
* when mapped with
|
||||
* <code>documentMatchers = YamlProcessor.mapMatcher({"environment": "prod"})</code>
|
||||
* <pre class="code">
|
||||
* setDocumentMatchers(properties ->
|
||||
* ("prod".equals(properties.getProperty("environment")) ? MatchStatus.FOUND : MatchStatus.NOT_FOUND));
|
||||
* </pre>
|
||||
* would end up as
|
||||
* <pre class="code">
|
||||
* environment=prod
|
||||
* url=http://foo.bar.com
|
||||
* name=My Cool App
|
||||
* url=http://dev.bar.com
|
||||
* </pre>
|
||||
* @param matchers a map of keys to value patterns (regular expressions)
|
||||
*/
|
||||
public void setDocumentMatchers(DocumentMatcher... matchers) {
|
||||
this.documentMatchers = Arrays.asList(matchers);
|
||||
@@ -94,8 +98,7 @@ public abstract class YamlProcessor {
|
||||
/**
|
||||
* Flag indicating that a document for which all the
|
||||
* {@link #setDocumentMatchers(DocumentMatcher...) document matchers} abstain will
|
||||
* nevertheless match.
|
||||
* @param matchDefault the flag to set (default true)
|
||||
* nevertheless match. Default is {@code true}.
|
||||
*/
|
||||
public void setMatchDefault(boolean matchDefault) {
|
||||
this.matchDefault = matchDefault;
|
||||
@@ -104,9 +107,7 @@ public abstract class YamlProcessor {
|
||||
/**
|
||||
* Method to use for resolving resources. Each resource will be converted to a Map,
|
||||
* so this property is used to decide which map entries to keep in the final output
|
||||
* from this factory.
|
||||
* @param resolutionMethod the resolution method to set (defaults to
|
||||
* {@link ResolutionMethod#OVERRIDE}).
|
||||
* from this factory. Default is {@link ResolutionMethod#OVERRIDE}.
|
||||
*/
|
||||
public void setResolutionMethod(ResolutionMethod resolutionMethod) {
|
||||
Assert.notNull(resolutionMethod, "ResolutionMethod must not be null");
|
||||
@@ -144,9 +145,14 @@ public abstract class YamlProcessor {
|
||||
|
||||
/**
|
||||
* Create the {@link Yaml} instance to use.
|
||||
* <p>The default implementation sets the "allowDuplicateKeys" flag to {@code false},
|
||||
* enabling built-in duplicate key handling in SnakeYAML 1.18+.
|
||||
* @see LoaderOptions#setAllowDuplicateKeys(boolean)
|
||||
*/
|
||||
protected Yaml createYaml() {
|
||||
return new Yaml(new StrictMapAppenderConstructor());
|
||||
LoaderOptions options = new LoaderOptions();
|
||||
options.setAllowDuplicateKeys(false);
|
||||
return new Yaml(options);
|
||||
}
|
||||
|
||||
private boolean process(MatchCallback callback, Yaml yaml, Resource resource) {
|
||||
@@ -293,10 +299,15 @@ public abstract class YamlProcessor {
|
||||
// Need a compound key
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Object> collection = (Collection<Object>) value;
|
||||
int count = 0;
|
||||
for (Object object : collection) {
|
||||
buildFlattenedMap(result,
|
||||
Collections.singletonMap("[" + (count++) + "]", object), key);
|
||||
if (collection.isEmpty()) {
|
||||
result.put(key, "");
|
||||
}
|
||||
else {
|
||||
int count = 0;
|
||||
for (Object object : collection) {
|
||||
buildFlattenedMap(result, Collections.singletonMap(
|
||||
"[" + (count++) + "]", object), key);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -389,7 +400,10 @@ public abstract class YamlProcessor {
|
||||
|
||||
/**
|
||||
* A specialized {@link Constructor} that checks for duplicate keys.
|
||||
* @deprecated as of Spring Framework 5.0.6 (not used anymore here),
|
||||
* superseded by SnakeYAML's own duplicate key handling
|
||||
*/
|
||||
@Deprecated
|
||||
protected static class StrictMapAppenderConstructor extends Constructor {
|
||||
|
||||
// Declared as public for use in subclasses
|
||||
|
||||
+3
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -74,6 +74,8 @@ import org.springframework.lang.Nullable;
|
||||
* servers[1]=foo.bar.com
|
||||
* </pre>
|
||||
*
|
||||
* <p>Requires SnakeYAML 1.18 or higher, as of Spring Framework 5.0.6.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Stephane Nicoll
|
||||
* @author Juergen Hoeller
|
||||
|
||||
+10
-10
@@ -371,9 +371,9 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
|
||||
}
|
||||
else if ("ref".equals(name)) {
|
||||
String refName;
|
||||
if (args[0] == null)
|
||||
if (args[0] == null) {
|
||||
throw new IllegalArgumentException("Argument to ref() is not a valid bean or was not found");
|
||||
|
||||
}
|
||||
if (args[0] instanceof RuntimeBeanReference) {
|
||||
refName = ((RuntimeBeanReference) args[0]).getBeanName();
|
||||
}
|
||||
@@ -489,11 +489,11 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
|
||||
Map.Entry factoryBeanEntry = (Map.Entry) ((Map) args[0]).entrySet().iterator().next();
|
||||
// If we have a closure body, that will be the last argument.
|
||||
// In between are the constructor args
|
||||
int constructorArgsTest = hasClosureArgument?2:1;
|
||||
int constructorArgsTest = (hasClosureArgument ? 2 : 1);
|
||||
// If we have more than this number of args, we have constructor args
|
||||
if (args.length > constructorArgsTest){
|
||||
// factory-method requires args
|
||||
int endOfConstructArgs = (hasClosureArgument? args.length - 1 : args.length);
|
||||
int endOfConstructArgs = (hasClosureArgument ? args.length - 1 : args.length);
|
||||
this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(beanName, null,
|
||||
resolveConstructorArguments(args, 1, endOfConstructArgs));
|
||||
}
|
||||
@@ -511,7 +511,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
|
||||
}
|
||||
else {
|
||||
List constructorArgs = resolveConstructorArguments(args, 0, hasClosureArgument ? args.length - 1 : args.length);
|
||||
currentBeanDefinition = new GroovyBeanDefinitionWrapper(beanName, null, constructorArgs);
|
||||
this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(beanName, null, constructorArgs);
|
||||
}
|
||||
|
||||
if (hasClosureArgument) {
|
||||
@@ -545,8 +545,8 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether there are any {@link RuntimeBeanReference}s inside the {@link Map}
|
||||
* and converts it to a {@link ManagedMap} if necessary.
|
||||
* Checks whether there are any {@link RuntimeBeanReference RuntimeBeanReferences}
|
||||
* inside the {@link Map} and converts it to a {@link ManagedMap} if necessary.
|
||||
* @param map the original Map
|
||||
* @return either the original map or a managed copy of it
|
||||
*/
|
||||
@@ -567,8 +567,8 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether there are any {@link RuntimeBeanReference}s inside the {@link List}
|
||||
* and converts it to a {@link ManagedList} if necessary.
|
||||
* Checks whether there are any {@link RuntimeBeanReference RuntimeBeanReferences}
|
||||
* inside the {@link List} and converts it to a {@link ManagedList} if necessary.
|
||||
* @param list the original List
|
||||
* @return either the original list or a managed copy of it
|
||||
*/
|
||||
@@ -630,7 +630,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
|
||||
|
||||
/**
|
||||
* This method overrides property retrieval in the scope of the
|
||||
* {@code GroovyBeanDefinitionReader} to either:
|
||||
* {@code GroovyBeanDefinitionReader}. A property retrieval will either:
|
||||
* <ul>
|
||||
* <li>Retrieve a variable from the bean builder's binding if it exists
|
||||
* <li>Retrieve a RuntimeBeanReference for a specific bean if it exists
|
||||
|
||||
+6
-6
@@ -24,7 +24,6 @@ import groovy.lang.GroovyObjectSupport;
|
||||
|
||||
import org.springframework.beans.BeanWrapper;
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.config.ConstructorArgumentValues;
|
||||
@@ -182,16 +181,16 @@ class GroovyBeanDefinitionWrapper extends GroovyObjectSupport {
|
||||
AbstractBeanDefinition bd = getBeanDefinition();
|
||||
if (AUTOWIRE.equals(property)) {
|
||||
if ("byName".equals(newValue)) {
|
||||
bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
|
||||
bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME);
|
||||
}
|
||||
else if ("byType".equals(newValue)) {
|
||||
bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE);
|
||||
bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
|
||||
}
|
||||
else if ("constructor".equals(newValue)) {
|
||||
bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR);
|
||||
bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
|
||||
}
|
||||
else if (Boolean.TRUE.equals(newValue)) {
|
||||
bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
|
||||
bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME);
|
||||
}
|
||||
}
|
||||
// constructorArgs
|
||||
@@ -211,8 +210,9 @@ class GroovyBeanDefinitionWrapper extends GroovyObjectSupport {
|
||||
}
|
||||
// factoryMethod
|
||||
else if (FACTORY_METHOD.equals(property)) {
|
||||
if (newValue != null)
|
||||
if (newValue != null) {
|
||||
bd.setFactoryMethodName(newValue.toString());
|
||||
}
|
||||
}
|
||||
// initMethod
|
||||
else if (INIT_METHOD.equals(property)) {
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ import org.springframework.beans.factory.config.BeanReference;
|
||||
* all {@link BeanReference BeanReferences} that are required to validate the configuration of the
|
||||
* overall logical entity as well as those required to provide full user visualisation of the configuration.
|
||||
* It is expected that certain {@link BeanReference BeanReferences} will not be important to
|
||||
* validation or to the user view of the configuration and as such these may be ommitted. A tool may wish to
|
||||
* validation or to the user view of the configuration and as such these may be omitted. A tool may wish to
|
||||
* display any additional {@link BeanReference BeanReferences} sourced through the supplied
|
||||
* {@link BeanDefinition BeanDefinitions} but this is not considered to be a typical case.
|
||||
*
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.beans.factory.parsing;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -38,7 +38,7 @@ public class CompositeComponentDefinition extends AbstractComponentDefinition {
|
||||
@Nullable
|
||||
private final Object source;
|
||||
|
||||
private final List<ComponentDefinition> nestedComponents = new LinkedList<>();
|
||||
private final List<ComponentDefinition> nestedComponents = new ArrayList<>();
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -82,7 +82,7 @@ public final class ParseState {
|
||||
*/
|
||||
@Nullable
|
||||
public Entry peek() {
|
||||
return this.state.isEmpty() ? null : this.state.peek();
|
||||
return this.state.peek();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+50
-50
@@ -30,15 +30,15 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.BeanWrapper;
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
@@ -154,10 +154,10 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
*/
|
||||
private final NamedThreadLocal<String> currentlyCreatedBean = new NamedThreadLocal<>("Currently created bean");
|
||||
|
||||
/** Cache of unfinished FactoryBean instances: FactoryBean name --> BeanWrapper */
|
||||
private final Map<String, BeanWrapper> factoryBeanInstanceCache = new ConcurrentHashMap<>(16);
|
||||
/** Cache of unfinished FactoryBean instances: FactoryBean name to BeanWrapper */
|
||||
private final ConcurrentMap<String, BeanWrapper> factoryBeanInstanceCache = new ConcurrentHashMap<>(16);
|
||||
|
||||
/** Cache of filtered PropertyDescriptors: bean Class -> PropertyDescriptor array */
|
||||
/** Cache of filtered PropertyDescriptors: bean Class to PropertyDescriptor array */
|
||||
private final ConcurrentMap<Class<?>, PropertyDescriptor[]> filteredPropertyDescriptorsCache =
|
||||
new ConcurrentHashMap<>(256);
|
||||
|
||||
@@ -298,8 +298,6 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
RootBeanDefinition bd = new RootBeanDefinition(beanClass);
|
||||
bd.setScope(SCOPE_PROTOTYPE);
|
||||
bd.allowCaching = ClassUtils.isCacheSafe(beanClass, getBeanClassLoader());
|
||||
// For the nullability warning, see the elaboration in AbstractBeanFactory.doGetBean;
|
||||
// in short: This is never going to be null unless user-declared code enforces null.
|
||||
return (T) createBean(beanClass.getName(), bd, null);
|
||||
}
|
||||
|
||||
@@ -333,8 +331,6 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
BeanWrapper bw = new BeanWrapperImpl(existingBean);
|
||||
initBeanWrapper(bw);
|
||||
populateBean(beanName, bd, bw);
|
||||
// For the nullability warning, see the elaboration in AbstractBeanFactory.doGetBean;
|
||||
// in short: This is never going to be null unless user-declared code enforces null.
|
||||
return initializeBean(beanName, existingBean, bd);
|
||||
}
|
||||
|
||||
@@ -354,8 +350,6 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
// Use non-singleton bean definition, to avoid registering bean as dependent bean.
|
||||
RootBeanDefinition bd = new RootBeanDefinition(beanClass, autowireMode, dependencyCheck);
|
||||
bd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
|
||||
// For the nullability warning, see the elaboration in AbstractBeanFactory.doGetBean;
|
||||
// in short: This is never going to be null unless user-declared code enforces null.
|
||||
return createBean(beanClass.getName(), bd, null);
|
||||
}
|
||||
|
||||
@@ -418,8 +412,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
throws BeansException {
|
||||
|
||||
Object result = existingBean;
|
||||
for (BeanPostProcessor beanProcessor : getBeanPostProcessors()) {
|
||||
Object current = beanProcessor.postProcessBeforeInitialization(result, beanName);
|
||||
for (BeanPostProcessor processor : getBeanPostProcessors()) {
|
||||
Object current = processor.postProcessBeforeInitialization(result, beanName);
|
||||
if (current == null) {
|
||||
return result;
|
||||
}
|
||||
@@ -433,8 +427,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
throws BeansException {
|
||||
|
||||
Object result = existingBean;
|
||||
for (BeanPostProcessor beanProcessor : getBeanPostProcessors()) {
|
||||
Object current = beanProcessor.postProcessAfterInitialization(result, beanName);
|
||||
for (BeanPostProcessor processor : getBeanPostProcessors()) {
|
||||
Object current = processor.postProcessAfterInitialization(result, beanName);
|
||||
if (current == null) {
|
||||
return result;
|
||||
}
|
||||
@@ -722,19 +716,18 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
int minNrOfArgs =
|
||||
(mbd.hasConstructorArgumentValues() ? mbd.getConstructorArgumentValues().getArgumentCount() : 0);
|
||||
Method[] candidates = ReflectionUtils.getUniqueDeclaredMethods(factoryClass);
|
||||
for (Method factoryMethod : candidates) {
|
||||
if (Modifier.isStatic(factoryMethod.getModifiers()) == isStatic &&
|
||||
factoryMethod.getName().equals(mbd.getFactoryMethodName()) &&
|
||||
factoryMethod.getParameterCount() >= minNrOfArgs) {
|
||||
for (Method candidate : candidates) {
|
||||
if (Modifier.isStatic(candidate.getModifiers()) == isStatic && mbd.isFactoryMethod(candidate) &&
|
||||
candidate.getParameterCount() >= minNrOfArgs) {
|
||||
// Declared type variables to inspect?
|
||||
if (factoryMethod.getTypeParameters().length > 0) {
|
||||
if (candidate.getTypeParameters().length > 0) {
|
||||
try {
|
||||
// Fully resolve parameter names and argument values.
|
||||
Class<?>[] paramTypes = factoryMethod.getParameterTypes();
|
||||
Class<?>[] paramTypes = candidate.getParameterTypes();
|
||||
String[] paramNames = null;
|
||||
ParameterNameDiscoverer pnd = getParameterNameDiscoverer();
|
||||
if (pnd != null) {
|
||||
paramNames = pnd.getParameterNames(factoryMethod);
|
||||
paramNames = pnd.getParameterNames(candidate);
|
||||
}
|
||||
ConstructorArgumentValues cav = mbd.getConstructorArgumentValues();
|
||||
Set<ConstructorArgumentValues.ValueHolder> usedValueHolders = new HashSet<>(paramTypes.length);
|
||||
@@ -751,8 +744,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
}
|
||||
}
|
||||
Class<?> returnType = AutowireUtils.resolveReturnTypeForFactoryMethod(
|
||||
factoryMethod, args, getBeanClassLoader());
|
||||
uniqueCandidate = (commonType == null ? factoryMethod : null);
|
||||
candidate, args, getBeanClassLoader());
|
||||
uniqueCandidate = (commonType == null && returnType == candidate.getReturnType() ?
|
||||
candidate : null);
|
||||
commonType = ClassUtils.determineCommonAncestor(returnType, commonType);
|
||||
if (commonType == null) {
|
||||
// Ambiguous return types found: return null to indicate "not determinable".
|
||||
@@ -766,8 +760,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
}
|
||||
}
|
||||
else {
|
||||
uniqueCandidate = (commonType == null ? factoryMethod : null);
|
||||
commonType = ClassUtils.determineCommonAncestor(factoryMethod.getReturnType(), commonType);
|
||||
uniqueCandidate = (commonType == null ? candidate : null);
|
||||
commonType = ClassUtils.determineCommonAncestor(candidate.getReturnType(), commonType);
|
||||
if (commonType == null) {
|
||||
// Ambiguous return types found: return null to indicate "not determinable".
|
||||
return null;
|
||||
@@ -776,12 +770,15 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
}
|
||||
}
|
||||
|
||||
if (commonType != null) {
|
||||
// Clear return type found: all factory methods return same type.
|
||||
mbd.factoryMethodReturnType = (uniqueCandidate != null ?
|
||||
ResolvableType.forMethodReturnType(uniqueCandidate) : ResolvableType.forClass(commonType));
|
||||
if (commonType == null) {
|
||||
return null;
|
||||
}
|
||||
return commonType;
|
||||
// Common return type found: all factory methods return same type. For a non-parameterized
|
||||
// unique candidate, cache the full type declaration context of the target factory method.
|
||||
cachedReturnType = (uniqueCandidate != null ?
|
||||
ResolvableType.forMethodReturnType(uniqueCandidate) : ResolvableType.forClass(commonType));
|
||||
mbd.factoryMethodReturnType = cachedReturnType;
|
||||
return cachedReturnType.resolve();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1119,10 +1116,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
}
|
||||
}
|
||||
|
||||
// Need to determine the constructor...
|
||||
// Candidate constructors for autowiring?
|
||||
Constructor<?>[] ctors = determineConstructorsFromBeanPostProcessors(beanClass, beanName);
|
||||
if (ctors != null ||
|
||||
mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_CONSTRUCTOR ||
|
||||
if (ctors != null || mbd.getResolvedAutowireMode() == AUTOWIRE_CONSTRUCTOR ||
|
||||
mbd.hasConstructorArgumentValues() || !ObjectUtils.isEmpty(args)) {
|
||||
return autowireConstructor(beanName, mbd, ctors, args);
|
||||
}
|
||||
@@ -1275,7 +1271,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
* from the bean definition.
|
||||
* @param beanName the name of the bean
|
||||
* @param mbd the bean definition for the bean
|
||||
* @param bw BeanWrapper with bean instance
|
||||
* @param bw the BeanWrapper with bean instance
|
||||
*/
|
||||
protected void populateBean(String beanName, RootBeanDefinition mbd, @Nullable BeanWrapper bw) {
|
||||
if (bw == null) {
|
||||
@@ -1312,25 +1308,21 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
|
||||
PropertyValues pvs = (mbd.hasPropertyValues() ? mbd.getPropertyValues() : null);
|
||||
|
||||
if (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_NAME ||
|
||||
mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_TYPE) {
|
||||
if (mbd.getResolvedAutowireMode() == AUTOWIRE_BY_NAME || mbd.getResolvedAutowireMode() == AUTOWIRE_BY_TYPE) {
|
||||
MutablePropertyValues newPvs = new MutablePropertyValues(pvs);
|
||||
|
||||
// Add property values based on autowire by name if applicable.
|
||||
if (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_NAME) {
|
||||
if (mbd.getResolvedAutowireMode() == AUTOWIRE_BY_NAME) {
|
||||
autowireByName(beanName, mbd, bw, newPvs);
|
||||
}
|
||||
|
||||
// Add property values based on autowire by type if applicable.
|
||||
if (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_TYPE) {
|
||||
if (mbd.getResolvedAutowireMode() == AUTOWIRE_BY_TYPE) {
|
||||
autowireByType(beanName, mbd, bw, newPvs);
|
||||
}
|
||||
|
||||
pvs = newPvs;
|
||||
}
|
||||
|
||||
boolean hasInstAwareBpps = hasInstantiationAwareBeanPostProcessors();
|
||||
boolean needsDepCheck = (mbd.getDependencyCheck() != RootBeanDefinition.DEPENDENCY_CHECK_NONE);
|
||||
boolean needsDepCheck = (mbd.getDependencyCheck() != AbstractBeanDefinition.DEPENDENCY_CHECK_NONE);
|
||||
|
||||
if (hasInstAwareBpps || needsDepCheck) {
|
||||
if (pvs == null) {
|
||||
@@ -1364,7 +1356,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
* @param beanName the name of the bean we're wiring up.
|
||||
* Useful for debugging messages; not used functionally.
|
||||
* @param mbd bean definition to update through autowiring
|
||||
* @param bw BeanWrapper from which we can obtain information about the bean
|
||||
* @param bw the BeanWrapper from which we can obtain information about the bean
|
||||
* @param pvs the PropertyValues to register wired objects with
|
||||
*/
|
||||
protected void autowireByName(
|
||||
@@ -1398,7 +1390,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
* behavior for bigger applications.
|
||||
* @param beanName the name of the bean to autowire by type
|
||||
* @param mbd the merged bean definition to update through autowiring
|
||||
* @param bw BeanWrapper from which we can obtain information about the bean
|
||||
* @param bw the BeanWrapper from which we can obtain information about the bean
|
||||
* @param pvs the PropertyValues to register wired objects with
|
||||
*/
|
||||
protected void autowireByType(
|
||||
@@ -1496,7 +1488,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
* @see #isExcludedFromDependencyCheck
|
||||
*/
|
||||
protected PropertyDescriptor[] filterPropertyDescriptorsForDependencyCheck(BeanWrapper bw) {
|
||||
List<PropertyDescriptor> pds = new LinkedList<>(Arrays.asList(bw.getPropertyDescriptors()));
|
||||
List<PropertyDescriptor> pds = new ArrayList<>(Arrays.asList(bw.getPropertyDescriptors()));
|
||||
pds.removeIf(this::isExcludedFromDependencyCheck);
|
||||
return pds.toArray(new PropertyDescriptor[0]);
|
||||
}
|
||||
@@ -1535,9 +1527,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
for (PropertyDescriptor pd : pds) {
|
||||
if (pd.getWriteMethod() != null && !pvs.contains(pd.getName())) {
|
||||
boolean isSimple = BeanUtils.isSimpleProperty(pd.getPropertyType());
|
||||
boolean unsatisfied = (dependencyCheck == RootBeanDefinition.DEPENDENCY_CHECK_ALL) ||
|
||||
(isSimple && dependencyCheck == RootBeanDefinition.DEPENDENCY_CHECK_SIMPLE) ||
|
||||
(!isSimple && dependencyCheck == RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
|
||||
boolean unsatisfied = (dependencyCheck == AbstractBeanDefinition.DEPENDENCY_CHECK_ALL) ||
|
||||
(isSimple && dependencyCheck == AbstractBeanDefinition.DEPENDENCY_CHECK_SIMPLE) ||
|
||||
(!isSimple && dependencyCheck == AbstractBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
|
||||
if (unsatisfied) {
|
||||
throw new UnsatisfiedDependencyException(mbd.getResourceDescription(), beanName, pd.getName(),
|
||||
"Set this property value or disable dependency checking for this bean.");
|
||||
@@ -1790,7 +1782,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
|
||||
if (initMethod == null) {
|
||||
if (mbd.isEnforceInitMethod()) {
|
||||
throw new BeanDefinitionValidationException("Couldn't find an init method named '" +
|
||||
throw new BeanDefinitionValidationException("Could not find an init method named '" +
|
||||
initMethodName + "' on bean with name '" + beanName + "'");
|
||||
}
|
||||
else {
|
||||
@@ -1866,6 +1858,14 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose the logger to collaborating delegates.
|
||||
* @since 5.0.7
|
||||
*/
|
||||
Log getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Special DependencyDescriptor variant for Spring's good old autowire="byType" mode.
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -158,7 +158,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
|
||||
|
||||
private boolean primary = false;
|
||||
|
||||
private final Map<String, AutowireCandidateQualifier> qualifiers = new LinkedHashMap<>(0);
|
||||
private final Map<String, AutowireCandidateQualifier> qualifiers = new LinkedHashMap<>();
|
||||
|
||||
@Nullable
|
||||
private Supplier<?> instanceSupplier;
|
||||
@@ -470,7 +470,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
|
||||
*/
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return SCOPE_SINGLETON.equals(scope) || SCOPE_DEFAULT.equals(scope);
|
||||
return SCOPE_SINGLETON.equals(this.scope) || SCOPE_DEFAULT.equals(this.scope);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -480,7 +480,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
|
||||
*/
|
||||
@Override
|
||||
public boolean isPrototype() {
|
||||
return SCOPE_PROTOTYPE.equals(scope);
|
||||
return SCOPE_PROTOTYPE.equals(this.scope);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+10
-11
@@ -29,11 +29,11 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.BeanWrapper;
|
||||
@@ -145,16 +145,16 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
||||
private TypeConverter typeConverter;
|
||||
|
||||
/** String resolvers to apply e.g. to annotation attribute values */
|
||||
private final List<StringValueResolver> embeddedValueResolvers = new LinkedList<>();
|
||||
private final List<StringValueResolver> embeddedValueResolvers = new CopyOnWriteArrayList<>();
|
||||
|
||||
/** BeanPostProcessors to apply in createBean */
|
||||
private final List<BeanPostProcessor> beanPostProcessors = new ArrayList<>();
|
||||
private final List<BeanPostProcessor> beanPostProcessors = new CopyOnWriteArrayList<>();
|
||||
|
||||
/** Indicates whether any InstantiationAwareBeanPostProcessors have been registered */
|
||||
private boolean hasInstantiationAwareBeanPostProcessors;
|
||||
private volatile boolean hasInstantiationAwareBeanPostProcessors;
|
||||
|
||||
/** Indicates whether any DestructionAwareBeanPostProcessors have been registered */
|
||||
private boolean hasDestructionAwareBeanPostProcessors;
|
||||
private volatile boolean hasDestructionAwareBeanPostProcessors;
|
||||
|
||||
/** Map from scope identifier String to corresponding Scope */
|
||||
private final Map<String, Scope> scopes = new LinkedHashMap<>(8);
|
||||
@@ -847,14 +847,17 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
||||
@Override
|
||||
public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor) {
|
||||
Assert.notNull(beanPostProcessor, "BeanPostProcessor must not be null");
|
||||
// Remove from old position, if any
|
||||
this.beanPostProcessors.remove(beanPostProcessor);
|
||||
this.beanPostProcessors.add(beanPostProcessor);
|
||||
// Track whether it is instantiation/destruction aware
|
||||
if (beanPostProcessor instanceof InstantiationAwareBeanPostProcessor) {
|
||||
this.hasInstantiationAwareBeanPostProcessors = true;
|
||||
}
|
||||
if (beanPostProcessor instanceof DestructionAwareBeanPostProcessor) {
|
||||
this.hasDestructionAwareBeanPostProcessors = true;
|
||||
}
|
||||
// Add to end of list
|
||||
this.beanPostProcessors.add(beanPostProcessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -985,7 +988,6 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
||||
@Override
|
||||
public BeanDefinition getMergedBeanDefinition(String name) throws BeansException {
|
||||
String beanName = transformedBeanName(name);
|
||||
|
||||
// Efficiently check whether bean definition exists in this factory.
|
||||
if (!containsBeanDefinition(beanName) && getParentBeanFactory() instanceof ConfigurableBeanFactory) {
|
||||
return ((ConfigurableBeanFactory) getParentBeanFactory()).getMergedBeanDefinition(beanName);
|
||||
@@ -997,18 +999,15 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
||||
@Override
|
||||
public boolean isFactoryBean(String name) throws NoSuchBeanDefinitionException {
|
||||
String beanName = transformedBeanName(name);
|
||||
|
||||
Object beanInstance = getSingleton(beanName, false);
|
||||
if (beanInstance != null) {
|
||||
return (beanInstance instanceof FactoryBean);
|
||||
}
|
||||
|
||||
// No singleton instance found -> check bean definition.
|
||||
if (!containsBeanDefinition(beanName) && getParentBeanFactory() instanceof ConfigurableBeanFactory) {
|
||||
// No bean definition found in this factory -> delegate to parent.
|
||||
return ((ConfigurableBeanFactory) getParentBeanFactory()).isFactoryBean(name);
|
||||
}
|
||||
|
||||
return isFactoryBean(beanName, getMergedLocalBeanDefinition(beanName));
|
||||
}
|
||||
|
||||
@@ -1501,7 +1500,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
||||
* should be used as fallback.
|
||||
* @param beanName the name of the bean
|
||||
* @param mbd the merged bean definition for the bean
|
||||
* @return the type for the bean if determinable, or {@code null} else
|
||||
* @return the type for the bean if determinable, or {@code null} otherwise
|
||||
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
|
||||
* @see #getBean(String)
|
||||
*/
|
||||
|
||||
+5
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -69,9 +69,7 @@ public class BeanDefinitionBuilder {
|
||||
* @param instanceSupplier a callback for creating an instance of the bean
|
||||
* @since 5.0
|
||||
*/
|
||||
public static <T> BeanDefinitionBuilder genericBeanDefinition(
|
||||
@Nullable Class<T> beanClass, Supplier<T> instanceSupplier) {
|
||||
|
||||
public static <T> BeanDefinitionBuilder genericBeanDefinition(Class<T> beanClass, Supplier<T> instanceSupplier) {
|
||||
BeanDefinitionBuilder builder = new BeanDefinitionBuilder(new GenericBeanDefinition());
|
||||
builder.beanDefinition.setBeanClass(beanClass);
|
||||
builder.beanDefinition.setInstanceSupplier(instanceSupplier);
|
||||
@@ -275,7 +273,7 @@ public class BeanDefinitionBuilder {
|
||||
* Set the autowire mode for this definition.
|
||||
*/
|
||||
public BeanDefinitionBuilder setAutowireMode(int autowireMode) {
|
||||
beanDefinition.setAutowireMode(autowireMode);
|
||||
this.beanDefinition.setAutowireMode(autowireMode);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -283,7 +281,7 @@ public class BeanDefinitionBuilder {
|
||||
* Set the depency check mode for this definition.
|
||||
*/
|
||||
public BeanDefinitionBuilder setDependencyCheck(int dependencyCheck) {
|
||||
beanDefinition.setDependencyCheck(dependencyCheck);
|
||||
this.beanDefinition.setDependencyCheck(dependencyCheck);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -316,7 +314,7 @@ public class BeanDefinitionBuilder {
|
||||
*/
|
||||
public BeanDefinitionBuilder applyCustomizers(BeanDefinitionCustomizer... customizers) {
|
||||
for (BeanDefinitionCustomizer customizer : customizers) {
|
||||
customizer.customize(beanDefinition);
|
||||
customizer.customize(this.beanDefinition);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -55,6 +55,7 @@ public interface BeanDefinitionRegistry extends AliasRegistry {
|
||||
* @throws BeanDefinitionStoreException if the BeanDefinition is invalid
|
||||
* or if there is already a BeanDefinition for the specified bean name
|
||||
* (and we are not allowed to override it)
|
||||
* @see GenericBeanDefinition
|
||||
* @see RootBeanDefinition
|
||||
* @see ChildBeanDefinition
|
||||
*/
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user