Compare commits

...

462 Commits

Author SHA1 Message Date
Spring Buildmaster 0e9ae56bdf Release version 5.0.12.RELEASE 2019-01-09 09:51:45 +00:00
Rossen Stoyanchev 5aa131a259 Correction for commit #c6e500
Issue: SPR-17630
2019-01-08 22:45:19 -05:00
Juergen Hoeller ea3017b1b6 Upgrade to Reactor Bismuth SR15 2019-01-08 23:48:24 +01:00
Juergen Hoeller 083b23e147 Polishing 2019-01-08 21:07:28 +01:00
Juergen Hoeller 0dd87e8339 Upgrade to Tomcat 8.5.37 and Hibernate Validator 6.0.14
Includes WebJars Locator 0.36, OkHttp 3.12.1, Apache Johnzon 1.1.11.
2019-01-08 18:45:52 +01:00
Juergen Hoeller e0283c2edf Polishing 2019-01-08 18:45:16 +01:00
Juergen Hoeller 183f367f2c DefaultListableBeanFactory checks for pre-converted Optional wrappers
Issue: SPR-17607
2019-01-08 18:44:38 +01:00
Juergen Hoeller 15f255a5eb Relaxed position assertion (for overflows in large inline maps)
Issue: SPR-17605

(cherry picked from commit b2756f5bd2)
2019-01-08 18:43:49 +01:00
Juergen Hoeller 8685f9fea3 Consistent support for EnumSet subclasses in CollectionFactory
Issue: SPR-17619

(cherry picked from commit 31a24720a6)
2019-01-08 18:43:23 +01:00
Juergen Hoeller 49cc5f2f81 MockMvcResultMatchers.forwardedUrl argument declared as nullable
Issue: SPR-17623

(cherry picked from commit 7a7958f275)
2019-01-08 18:43:07 +01:00
Sam Brannen 7ba5ee35df Link explicitly to JUnit 5.0.3 instead of current version 2019-01-08 18:12:54 +01:00
Rossen Stoyanchev c6e50087a0 Adjust UriComponentsBuilder#toUriString behavior
Commit #93b7a4 added support for pre-configuring URI variables at the
UriComponentsBuilder level, and also changed toUriString to encode
template and URI variables separately. However this went a bit too far
causing side effects for URLs with curly braces that don't represent
URI variables.

This commit restores the original toUriString behavior which is to
encode template and URI variables sepraately only if URI variables have
been pre-configured.

Issue: SPR-17630
2019-01-08 11:07:00 -05:00
Sam Brannen 7a88e6dbb7 Link explicitly to JUnit 4.12 instead of beta version
For details, see: https://github.com/junit-team/junit4/issues/1585
2019-01-08 16:28:22 +01:00
Sam Brannen e15b96a198 Provide external links to JUnit in published Javadoc API 2019-01-08 16:20:03 +01:00
Michel Schudel cba355a4d2 Fix XML parser default value handling
The xml parser does not fill in defaults provided in the XSD when
validation is disabled. As a result, attributes like default-lazy-init
will not receive the value "default" but an empty string.

With this commit, BeanDefinitionParserDelegate now takes this into
account, checking default values against empty string as well as
"default".

As a consequence, default-lazy-init attribute should now work correctly
even when the XSD validation is disabled.

Issue: SPR-8335
2019-01-08 12:23:49 +01:00
Rossen Stoyanchev 124e8179b2 Lenient URI template encoding
URI template encoding ignores mismatched curly braces, treating them as
literal parts instead.

Issue: SPR-17630
2019-01-02 16:42:01 -05:00
Violeta Georgieva 0742160821 Propagate the cancel signal to the downstream 2018-12-18 15:01:35 -05:00
Juergen Hoeller 03fb343528 Upgrade to Jackson 2.9.8 and Groovy 2.4.16
Includes upgrade to AspectJ 1.9.2 for spring-aspects compilation.
2018-12-17 17:56:08 +01:00
Juergen Hoeller 8de86b7fb3 Revised backport version 5.0.11
Issue: SPR-17410
Issue: SPR-17433
2018-12-17 17:55:54 +01:00
Juergen Hoeller 62885a1922 Revised format annotation docs
(cherry picked from commit aab421167b)
2018-12-17 17:38:52 +01:00
Juergen Hoeller 1b26f2fb31 ParameterNameDiscoverer may return individual null entries in an array
Issue: SPR-17565

(cherry picked from commit c48672c4c7)
2018-12-12 22:36:50 +01:00
Juergen Hoeller 6ca2cb5917 Polishing
(cherry picked from commit 106ae0cc5b)
2018-12-12 13:23:51 +01:00
Juergen Hoeller ce57d4ad58 Revised HttpHeaders javadoc 2018-12-12 12:54:01 +01:00
Juergen Hoeller 7377764d02 Polishing 2018-12-12 12:40:14 +01:00
Juergen Hoeller 288c97bd2d Revised SimpleEvaluationContext example
Issue: SPR-17581
2018-12-12 12:39:50 +01:00
Juergen Hoeller e95c1b3153 Relaxed assertion in NotificationPublisherAwareLazyTargetSource
Issue: SPR-17592

(cherry picked from commit 2c98c1b81a)
2018-12-12 12:39:38 +01:00
Juergen Hoeller 6505cb93ed Explicit documentation notes on JMS 2.0 vs 1.1 compatibility
Issue: SPR-17583

(cherry picked from commit 7b9c30f26e)
2018-12-12 12:39:22 +01:00
Juergen Hoeller a9b453d79f Polishing 2018-12-11 11:14:23 +01:00
Juergen Hoeller 693ad3c1f5 StandardEvaluationContext.setVariable leniently ignores null name
Issue: SPR-17565

(cherry picked from commit db63f7dd4a)
2018-12-05 14:16:56 +01:00
Juergen Hoeller 340d320696 Clarified VfsResource constructor
Issue: SPR-17563

(cherry picked from commit 50e5bdb813)
2018-12-04 22:28:04 +01:00
Juergen Hoeller bc864dc161 MockHttpServletRequest preserves original Accept-Language header value
Issue: SPR-17566

(cherry picked from commit 9efea7eb73)
2018-12-04 22:27:58 +01:00
Juergen Hoeller d73b027021 Upgrade to Rome 1.12 2018-12-04 02:38:10 +01:00
Juergen Hoeller 4a87262b24 Cleanup after unexpected exception from external delegation call
Issue: SPR-17559

(cherry picked from commit c024bdcc6f)
2018-12-04 02:38:00 +01:00
Juergen Hoeller c5428e63b4 NettyDataBufferFactory.join returns single-element buffer as-is
Issue: SPR-17560

(cherry picked from commit d5dab12909)
2018-12-04 00:13:34 +01:00
Juergen Hoeller 76fd1793a8 Avoid log statements between resource opening and returning
Issue: SPR-17559

(cherry picked from commit 7854b7ac40)
2018-12-04 00:13:22 +01:00
Juergen Hoeller d175d280a0 Backported decoder optimizations and related polishing
Includes downgrade to Netty 4.1.31 for StringDecoderTests.
2018-12-03 22:57:00 +01:00
Juergen Hoeller 8bc06d20ac Polishing 2018-12-03 22:18:43 +01:00
Juergen Hoeller ab2314f52d Upgrade javadoc links to Jackson 2.9
Includes upgrade to Netty 4.1.32.
2018-12-03 22:10:45 +01:00
Juergen Hoeller 7a45d5fdae Revised section on custom BeanPostProcessors
Issue: SPR-17556
2018-12-03 22:10:09 +01:00
Juergen Hoeller 2efac5ad6b JavaMailSenderImpl calls sendMessage with empty array instead of null
Issue: SPR-17540

(cherry picked from commit 16e9b83d43)
2018-12-03 22:09:51 +01:00
Spring Buildmaster 22df12e03c Next Development Version 2018-11-27 08:54:09 +00:00
Juergen Hoeller 0761446c04 Revised alias definition example in reference documentation
Issue: SPR-17536
2018-11-25 22:18:26 +01:00
Juergen Hoeller 7b2eebe99f ResolvableType-based matching consistently respects generic factory method return type (even for pre-initialized raw singleton instance)
Issue: SPR-17524

(cherry picked from commit ebbe14c363)
2018-11-25 22:18:09 +01:00
Juergen Hoeller cf31f020a2 Upgrade to Hibernate Validator 6.0.13 and EclipseLink 2.7.3
Also includes Hibernate ORM 5.1.16 for integration tests.
2018-11-24 15:12:02 +01:00
Juergen Hoeller 02616fbabd Upgrade to Kotlin 1.2.71, OkHttp 3.12, FreeMarker 2.3.28
Also includes Apache HttpClient 4.5.6 and HttpAsyncClient 4.1.4.
2018-11-24 14:44:57 +01:00
Juergen Hoeller 4a51acbeb2 DefaultResponseErrorHandler detects non-standard error code as well
Issue: SPR-17439
2018-11-23 19:12:41 +01:00
Juergen Hoeller 3d7e373e5a Polishing
(cherry picked from commit 77ab88b144)
2018-11-23 19:12:30 +01:00
Sam Brannen f0e69e06b7 Ensure that MethodParameter.findParameterIndex() is thread-safe
Prior to this commit, parallel invocations of
MethodParameter.findParameterIndex() (invoked indirectly via
SynthesizingMethodParameter.forParameter() and
MethodParameter.forParameter()) could intermittently lead to an
IllegalArgumentException being thrown due to a race condition in the
internal implementation of the JDK's
java.lang.reflect.Executable.getParameters() method.

This commit addresses this issue by introducing a fallback for-loop
that iterates over the candidate parameters a second time using
equality checks instead of identity checks.

Issue: SPR-17534

(cherry-picked from commit 81fde5ec41)
2018-11-23 17:38:42 +01:00
Sam Brannen cd67b285e1 Ensure that parameter resolution in SpringExtension is thread-safe
Prior to this commit, parallel execution of @BeforeEach and @AfterEach
methods that accepted @Autowired arguments would fail intermittently
due to a race condition in the internal implementation of the JDK's
java.lang.reflect.Executable.getParameters() method.

This commit addresses this issue by creating instances of
SynthesizingMethodParameter via
SynthesizingMethodParameter.forExecutable(Executable, int) instead of
SynthesizingMethodParameter.forParameter(Parameter), since the latter
looks up the parameter index by iterating over the array returned by
Executable.getParameters() (which is not thread-safe).

Issue: SPR-17533
2018-11-23 17:00:38 +01:00
Juergen Hoeller 39925c334d Polishing 2018-11-22 20:38:26 +01:00
Juergen Hoeller 2e55486cc3 Upgrade to Reactor Bismuth SR14, Tomcat 8.5.35, Jetty 9.4.14 2018-11-22 17:45:16 +01:00
Juergen Hoeller e2b74e6943 Polishing 2018-11-22 17:44:29 +01:00
Juergen Hoeller 5382260f30 Client/ServerRequest defensively accesses internal attribute map
Issue: SPR-17486
2018-11-22 17:43:53 +01:00
Juergen Hoeller 35da9f1ddf FastByteArrayOutputStream.read byte-to-int conversion
Issue: SPR-17492
2018-11-22 17:43:31 +01:00
Juergen Hoeller e6c979606c Nullability fine-tuning based on IntelliJ IDEA 2018.3 inspection
Issue: SPR-15540

(cherry picked from commit bf272b0b21)
2018-11-22 17:43:13 +01:00
Juergen Hoeller 23d1049363 CachingMetadataReaderFactory releases shared cache Map on clearCache()
LocalResourceCache properly initializes cacheLimit on construction.

Issue: SPR-17527

(cherry picked from commit 262c702da4)
2018-11-22 17:42:27 +01:00
Juergen Hoeller 37a50d701e SerializedBeanFactoryReference falls back to dummy with specific id
Issue: SPR-17508

(cherry picked from commit f5aeb81473)
2018-11-22 17:42:06 +01:00
Rossen Stoyanchev 567fcc41cc ForwardedHeaderTransformer handles encoding correctly
Issue: SPR-17525
2018-11-21 11:17:10 -05:00
Rossen Stoyanchev 97dac8a45d Update @since version after backport 2018-11-21 09:36:34 -05:00
Rossen Stoyanchev 736b3c45e8 BEST_MATCHING_HANDLER_ATTRIBUTE for spring-webmvc
Issue: SPR-17518
2018-11-21 09:24:35 -05:00
Brian Clozel 617b94afb6 Polish
See SPR-17502
2018-11-20 18:03:07 +01:00
Brian Clozel 5342c6e493 Remove Content-Length response header from errors
Prior to this commit, when errors happened before the response was
committed, the `Content-Length` response header would be left as is.
This can be problematic since the error can be handled later in the
chain and the response body changed accordingly. For example, Spring
Boot renders error pages in those cases. If the `Content-Length` is set,
HTTP clients can get confused and only consider part of the error
response body.

This commit ensures that any `Content-Length` response header is removed
in case of errors, if the response is not already committed.

This is done at the `AbstractServerHttpResponse` level, since errors can
be handled in multiple places and the response itself is the safest
place to handle this case.

As a consequence, this commit also removes `Content-Length` checks in
`EncoderHttpMessageWriter` since we now consider that we should rely on
the response body we're about to write rather than any previously set
value.

Issue: SPR-17502
(Cherry-picked from 3203d39821)
2018-11-19 16:06:32 +01:00
Rossen Stoyanchev 18da718bf5 Enforce use of unpooled data buffers in 5.0.x
Issue: SPR-17501
2018-11-16 11:26:54 -05:00
Rossen Stoyanchev 24051619a5 Consistent encoding in DefaultUriBuilderFactory
Unlike 5,1, TEMPLATE_AND_VALUES is not the default encoding mode.
Nevertheless when that mode is used, it should work consistently.

Issue: SPR-17465
2018-11-09 14:50:39 -05:00
Rossen Stoyanchev f73a5222f1 Ensure client response is drained with onStatus hook
Issue: SPR-17473
2018-11-08 22:33:37 -05:00
Juergen Hoeller 8a2262e210 Up-to-date version and link in ASM/CGLIB/Objenesis package javadoc
Issue: SPR-14514
Issue: SPR-15600
2018-11-08 17:06:54 +01:00
Juergen Hoeller 0167b79d7b Consistently return empty array in case of empty batch arguments
Issue: SPR-17476

(cherry picked from commit 362c59c310)
2018-11-08 13:57:42 +01:00
Juergen Hoeller b462ca22a5 Upgrade to Reactor Bismuth SR13 (and Netty 4.1.31)
Issue: SPR-17306
2018-11-05 22:42:42 +01:00
Juergen Hoeller 4bd95663f9 Polishing
(cherry picked from commit 5e7a8b275d)
2018-11-05 22:42:27 +01:00
Juergen Hoeller 561511f66c Explicit notes on class/method-level semantics in class hierarchies
Issue: SPR-17445

(cherry picked from commit ea3250c8d6)
2018-11-05 22:33:20 +01:00
Juergen Hoeller 88f4e9205a Synchronized onRefresh execution for concurrent ContextRefreshedEvent
Issue: SPR-17442

(cherry picked from commit b1f5f51503)
2018-11-05 22:32:47 +01:00
Juergen Hoeller 591e7f1f72 StandardEvaluationContext supports concurrent variable modification
Issue: SPR-17448

(cherry picked from commit 59fa647e2d)
2018-11-05 22:32:21 +01:00
Juergen Hoeller c834790135 Deprecate ReflectionUtils.invokeJdbcMethod (for removal in 5.2)
Includes deprecation of NON_BRIDGED_METHODS constant.

Issue: SPR-17464

(cherry picked from commit 0a7dcf14f9)
2018-11-05 22:32:04 +01:00
Rossen Stoyanchev 9b4f48309a Fix formatting on index.adoc 2018-11-05 13:16:27 -05:00
Rossen Stoyanchev 8013566d99 Feature Github Wiki more prominently
Issue: SPR-17469
2018-11-05 13:13:39 -05:00
Rossen Stoyanchev 3bb11a0123 Fix failing test
After the fix #658c7f for lenient parsing of dates, the error message
raised uses an HttpHeaders-formatted date. As a result the test
verifying the error message fails in the beginning of the month between
1-9 because it's formatted slightly differently.
2018-11-01 15:46:28 -04:00
Juergen Hoeller e28a995ab7 Consistent check for Void.class in DefaultClientResponse
Issue: SPR-16636
2018-10-27 15:19:55 +02:00
Juergen Hoeller c10a8bb3b8 Exclude FactoryBean implementation methods on CGLIB proxies as well
Issue: SPR-17374

(cherry picked from commit dc1e3b4628)
2018-10-27 15:19:12 +02:00
Brian Clozel 2d14bd7066 Configure ResourceUrlProvider in WebFlux
Prior to this commit, no `ResourceUrlProvider` was configured
in WebFlux (no bean was contributed by the WebFlux infrastructure).
Also, several `ResourceTransformer` instances that extend the
`ResourceTransformerSupport` base class need a `ResourceUrlProvider`
to resolve absolute URLs when rewriting resource URLs. At this point,
no `ResourceUrlProvider` was configured and they could only resolve
relative URLs.

This commit contributes a new `ResourceUrlProvider` to the WebFlux
configuration; this bean can be reused by the WebFlux infrastructure and
application code.

This also automatically configure this shared `ResourceUrlProvider`
instance on the resource chain where needed.

Issue: SPR-17433
(Cherry-picked from fc957e95bb)
2018-10-26 14:35:01 +02:00
Juergen Hoeller 2acfb2e0ff Polishing 2018-10-26 11:23:42 +02:00
Juergen Hoeller 3ceb05f63c Upgrade to Jackson 2.9.7, Netty 4.1.30, Tomcat 8.5.34, Undertow 1.4.26
Also includes Apache Johnzon 1.1.10 and JRuby 9.1.17.
2018-10-25 17:39:47 +02:00
Juergen Hoeller 9e2d024d8d Asciidoc revision (minor backport for addressing build-time warnings) 2018-10-25 17:39:47 +02:00
Brian Clozel 3b7c0fc1a1 Fix absolute paths when transforming resources
Prior to this commit, `ResourceTransformerSupport.toAbsolutePath`
would call `StringUtils.applyRelativePath` in all cases. But this
implementation is prepending the given path even if the relative path
starts with `"/"`.

This commit skips the entire operation if the given path is absolute,
i.e. it starts with `"/"`.

Issue: SPR-17432
(Cherry-picked from 2146e13787)
2018-10-25 17:35:26 +02:00
Juergen Hoeller d5f725d503 Polishing
(cherry picked from commit ffa032e78f)
2018-10-24 21:24:42 +02:00
Juergen Hoeller c9f1016581 ConfigurableWebApplicationContext needed for contextClass parameter
Issue: SPR-17414

(cherry picked from commit 1c67ef4bed)
2018-10-24 21:24:42 +02:00
Juergen Hoeller 110796375b SpringFactoriesLoader tolerates whitespace around class names
Issue: SPR-17413

(cherry picked from commit dd2ce20687)
2018-10-24 21:24:42 +02:00
Juergen Hoeller b87ce596a0 Avoid stacktrace if root resource is not resolvable in file system
Issue: SPR-17417

(cherry picked from commit 83a54dba7e)
2018-10-24 21:24:42 +02:00
Juergen Hoeller 5a6c081cfe Clarify FactoryBean initialization effect in getBeanNamesForAnnotation
Issue: SPR-17392

(cherry picked from commit da23505e94)
2018-10-24 21:24:42 +02:00
Juergen Hoeller c73b98cf33 Clarify destruction order effect in @DependsOn annotation javadoc
Issue: SPR-17384

(cherry picked from commit 00b7782b5f)
2018-10-24 21:24:42 +02:00
Brian Clozel cf25efc7d3 Fix ResourceUrlEncodingFilter lifecycle
Prior to this commit, the `ResourceUrlEncodingFilter` would wrap the
response and keep a reference to the request. When
`HttpServletResponse.encodeURL` is later called during view rendering,
the filter looks at the request and extracts context mapping information
in order to resolve resource paths in views.

This approach is flawed, when the filter is used with JSPs - if the
request is forwarded to the container by the `InternalResourceView`,
the request information is overwritten by the container. When the view
is being rendered, the information available in the request is outdated
and does not allow to correctly compute that context mapping
information.

This commit ensures that that information is being extracted from the
request as soon as the `ResourceUrlProvider` is set as a request
attribute.

Issue: SPR-17421
(Cherry-picked from 50a4769162)
2018-10-24 21:19:33 +02:00
Rossen Stoyanchev 36510cf808 Server adapters release buffers on error/cancel
Review and update Servlet and Undertow adapters to release any data
buffers they be holding on to at the time of error or cancellation.

Also remove onDiscard hooks from Reactor and Undertow request body.
For Reactor we expect it to be handled. For Undertow there isn't
any Reactor Core upstream for the callback to be useful.

Issue: SPR-17410
2018-10-23 20:56:08 -04:00
Rossen Stoyanchev d492d7b6a4 Update ref docs on ResponseEntity and reactive types
Issue: SPR-17400
2018-10-23 17:06:02 -04:00
Rossen Stoyanchev bf4d00cb62 Upgrade to Reactor Bismuth snapshots
Towards SR13 to confirm fix for SPR-17306.
2018-10-23 15:49:09 -04:00
Rossen Stoyanchev 6ea3441adf Restore log level for resolved exceptions
The fix for SPR-17178 switched from debug to warn level warning for
all sub-classes of AbstractHandlerExceptionResolver where the request
concerned the DefaultHandlerExceptionResolver only.

This commit restores the original DEBUG level logging that was in
AbstractHandlerExceptionResolver from before SPR-17178. In addition
DefaultHandlerExceptionResolver registers a warnLogCategory by default
which enables warn logging and hence fulfilling the original goal
for SPR-17178.

Issue: SPR-17383
2018-10-22 12:18:33 -04:00
Sebastien Deleuze 73db2081cd Leverage Java reflection for Kotlin enums
As discussed in KT-25165, from a Kotlin POV enum constructors
have no parameter, this is an "implementation detail"
required for running on the JVM, so it seems relevant to skip
Kotlin reflection in that case and just delegate to Java
reflection.

Issue: SPR-16931
2018-10-16 16:42:31 +02:00
Spring Buildmaster 38490f13b1 Next Development Version 2018-10-15 08:01:59 +00:00
Rossen Stoyanchev c8e320019f HttpRange validates requested ranges
Issue: SPR-17318
2018-10-14 22:53:33 -04:00
Juergen Hoeller 973eb5deb6 MethodValidationInterceptor excludes FactoryBean metadata methods
Issue: SPR-17374

(cherry picked from commit 5f2d47a17e)
2018-10-14 21:16:01 +02:00
Rossen Stoyanchev b89cb20b1d Lenient date parsing in HeadersResultMatchers
Rather than formatting the expected value, and be susceptible to
minor formatting differences (e.g. 01 vs 1 for day of month), parse the
actual header value leniently with HttpHeaders and compare time values.

Issue: SPR-17330
2018-10-12 15:51:32 -04:00
Juergen Hoeller 52ed4226bd Tests for MockHttpServletRequestTests.setContent reset in 5.0.x
Issue: SPR-17373
2018-10-12 17:57:07 +02:00
volkovandr b0433810da Updated Javadoc: date format patterns SPR-17366
(cherry picked from commit 61403e3bd3)
2018-10-12 17:56:58 +02:00
Christian Kulpa db2c807515 Fix deprecated property in MBeanExporter documentation 2018-10-12 16:30:11 +02:00
Juergen Hoeller a45bce1369 Polishing 2018-10-10 00:15:58 +02:00
Juergen Hoeller 8d1499e168 Comparators.nullsLow creates right kind of NullSafeComparator
Issue: SPR-17357
2018-10-10 00:15:50 +02:00
Juergen Hoeller ff0afcff06 Resource.lastModified() propagates 0 value if target resource exists
Includes consistent use of getContentLengthLong over getContentLength.

Issue: SPR-17320
2018-10-10 00:15:27 +02:00
Juergen Hoeller 53430760f3 Consistent exposure of empty attribute arrays in AnnotationMetadata
Issue: SPR-17347

(cherry picked from commit 83909e6e1e)
2018-10-10 00:15:04 +02:00
Juergen Hoeller d61a7ed1f0 AbstractApplicationContext.getApplicationListeners() exposes all statically registered listeners
Issue: SPR-17324

(cherry picked from commit c8c0737ce7)
2018-10-10 00:14:48 +02:00
Juergen Hoeller ca0ce7d631 AbstractApplicationEventMulticaster pre-sorts singleton listeners
Issue: SPR-17307

(cherry picked from commit 9063e66c5d)
2018-10-10 00:14:39 +02:00
Rossen Stoyanchev fc2f3ecf44 More defensive check for MockAsyncContext
Avoid automatically unwrapping the request in TestDispatcherServlet,
if we find the MockAsyncContext.

Issue: SPR-17353
2018-10-09 11:57:34 -04:00
Rossen Stoyanchev d551710c32 Restore calls to setLocale in MockHttpServletResponse
Issue: SPR-17284
2018-10-05 13:53:19 -04:00
Rossen Stoyanchev 6fe8cb949f Workaround for Synchronoss content-length limitation
Issue: SPR-17345
2018-10-05 13:52:58 -04:00
dmrachkovskyi 842297699d Defer obtaining argument resolver default value
Issue: SPR-17338
2018-10-05 13:52:28 -04:00
Juergen Hoeller d90d65bad2 Polishing 2018-09-29 17:36:15 +02:00
Juergen Hoeller a21ce42558 MockHttpServletRequest allows for removing registered header entries
Issue: SPR-17295
2018-09-29 17:36:03 +02:00
Juergen Hoeller e54eb56cb9 Revised javadoc for up-to-date constructor autowiring semantics
Issue: SPR-17299

(cherry picked from commit 333e327289)
2018-09-29 17:35:55 +02:00
Juergen Hoeller f5e6c707ae Polishing 2018-09-19 22:51:35 +02:00
Juergen Hoeller c0b0ee6db7 Polishing 2018-09-18 21:54:48 +02:00
Juergen Hoeller 4642c32c0f Defensively expect concurrent registration of BeanPostProcessors
Declaring beanPostProcessors (and also embeddedValueResolvers) as CopyOnWriteArrayList prevents ConcurrentModificationExceptions in case of concurrent registration/access attempts.

Issue: SPR-17286
2018-09-18 21:54:33 +02:00
Juergen Hoeller a55261f82d Polishing 2018-09-17 15:00:33 +02:00
Juergen Hoeller 5ca2c56cf0 Polishing 2018-09-17 14:39:54 +02:00
Juergen Hoeller 702d533e6f Polishing 2018-09-14 23:59:45 +02:00
Juergen Hoeller 1535f985be Polishing 2018-09-14 14:30:03 +02:00
Juergen Hoeller 94ae933122 Upgrade to Rhino 1.7.10 and Apache Johnzon 1.1.9
Includes reordering of web dependency declarations.
2018-09-14 14:29:57 +02:00
Arjen Poutsma 952315c333 DataBufferUtils does not release DataBuffer on error cases
This commit makes sure that in DataBufferUtils.write, any received data
buffers are returned as part of the returned flux, even when an error
occurs or is received.

Issue: SPR-16782

(cherry picked from commit 1a0522b805)
2018-09-12 14:58:37 +02:00
Arjen Poutsma a00607348c Fixed DataBufferUtils.join leak for error in source
This commit fixes an issue where DataBufferUtils.join() would not
release databuffers that preceded an error signal.

Issue: SPR-17025

(cherry picked from commit 196c0adf47)
2018-09-12 14:45:45 +02:00
Juergen Hoeller 1d58fac54d UriComponentsBuilder copies query params through MultiValueMap.addAll
Issue: SPR-17256
2018-09-11 15:15:15 +02:00
Juergen Hoeller 658bd7a686 Correct linkplain javadoc in BufferingClientHttpRequestFactory
Issue: SPR-17261

(cherry picked from commit e47355078c)
2018-09-11 15:15:00 +02:00
Juergen Hoeller 717e6dd2d9 Revise ServletUriComponentsBuilder javadoc
Issue: SPR-17255
2018-09-07 18:21:25 +02:00
Spring Buildmaster 7f82c192f5 Next Development Version 2018-09-07 12:16:08 +00:00
Juergen Hoeller dcdd08c432 Remove declaration for snapshot repository 2018-09-07 13:13:06 +02:00
Juergen Hoeller 06ed818f4c Fix SpEL compilation for non trivial elvis operand
Issue: SPR-17214
2018-09-07 13:12:53 +02:00
Juergen Hoeller ad5447253c ConfigurationClassParser consistently uses ClassUtils.forName
Issue: SPR-17253

(cherry picked from commit c803ad7998)
2018-09-07 13:12:26 +02:00
Juergen Hoeller 7653762240 XMLEventReader.getElementText() properly checks for start element
Issue: SPR-17233

(cherry picked from commit 84ec382201)
2018-09-07 13:12:10 +02:00
Sebastien Deleuze 89fca1b949 Fix Kotlin inner class nested configuration handling
Before this commit, Kotlin inner class nested configuration
handling thrown an IndexOutOfBoundsException due to bogus filtering
of its constructor parameter reference to an instance of the outer
class.

This commit keep constructor parameter of type INSTANCE in order to
throw a more meaningful NoSuchBeanDefinitionException.

Issue: SPR-17222
2018-09-07 11:42:23 +02:00
Rossen Stoyanchev 92bb76f3cd Disable Jackson's buffer recyling feature for WebFlux
Issue: SPR-17193
2018-09-06 16:21:27 -04:00
Stephane Nicoll 4b6a5fbd13 Upgrade to Reactor Bismuth SR11 2018-09-06 15:38:15 +02:00
Rossen Stoyanchev b17e7c321a Use random id for WebSocket sessions
Issue: SPR-17228
2018-09-05 19:49:50 -04:00
Toshiaki Maki ee559bb2c8 Use long for expires and lastModified in HeaderAssertions
This commit changes the type of parameters so that HeaderAssertions
can assert expires and lastModified properly.

Issue: SPR-17194
2018-09-05 17:26:42 -04:00
Brian Clozel 1371cfe301 Upgrade to Jetty 9.4.12.v20180830
(Cherry-picked from 7041e5e8e3)
2018-09-04 22:15:13 +02:00
Juergen Hoeller 04814e604e Polishing
(cherry picked from commit 95a56cd28d)
2018-08-31 12:57:31 +02:00
Juergen Hoeller e332e32a88 SpelExpression consistently exposes EvaluationContext to compiled AST
Operator includes explicit support for Boolean comparisons now.

Issue: SPR-17229

(cherry picked from commit 51cee658d5)
2018-08-31 12:57:23 +02:00
Juergen Hoeller 648fa60f48 Transactional timeout documented as seconds in annotation javadoc
Issue: SPR-17226

(cherry picked from commit 8c6f3505c4)
2018-08-31 12:57:12 +02:00
Brian Clozel 4004f92e3f Switch back to Reactor Bismuth SNAPTHOTs
Preparing for Bismut-SR11
2018-08-30 16:52:21 +02:00
Brian Clozel 6189e17d7c Fix empty body writing in EncoderHttpMessageWriter
Prior to this commit, an bug introduced in SPR-16949 prevented
`Mono.empty` bodies from being written to the response.

This commit ensures that empty bodies still trigger the writing to the
response and does not hang the processing of the exchange.

Issue: SPR-17220
Cherry-picked from: 280da61d5c
2018-08-27 21:19:12 +02:00
Juergen Hoeller 1e8cb5fc59 Upgrade to RxJava 2.1.17, Tomcat 8.5.33, Netty 4.1.29 2018-08-24 12:58:04 +02:00
Juergen Hoeller b5270a9cff Polishing 2018-08-24 12:39:03 +02:00
Juergen Hoeller a44fe4cbe4 Support Jackson filters in combination with serialization view
Issue: SPR-17209

(cherry picked from commit 03f1920106)
2018-08-24 12:38:51 +02:00
Kyle Carter abb92b6966 Fix usage of deprecated functionality in docs
Closes gh-1934
2018-08-20 09:44:31 +02:00
Juergen Hoeller 68cf18f4a3 SimpleAliasRegistry.hasAlias properly resolves multiple chained aliases
Issue: SPR-17191

(cherry picked from commit 2ac23badee)
2018-08-17 09:58:55 +02:00
Juergen Hoeller 92228f9e64 Fix recent javadoc errors
Issue: SPR-17174
2018-08-16 19:24:38 +02:00
Juergen Hoeller fb083a3776 Consistently use double quotes (even if no interpolation needed) 2018-08-16 15:53:37 +02:00
Juergen Hoeller f532de5a8a Polishing 2018-08-16 12:21:49 +02:00
Juergen Hoeller 6b3dd0779f Consistently skip unnecessary search on superclasses and empty elements
Issue: SPR-16933
2018-08-15 17:56:03 +02:00
Rossen Stoyanchev bf7fa39a48 Consistent logging of resolved exceptions
Issue: SPR-17178
2018-08-15 11:10:35 +03:00
Juergen Hoeller 37db3ba834 Polishing
(cherry picked from commit 6027cf2255)
2018-08-14 21:45:25 +02:00
Juergen Hoeller 4b2a0471e1 Revised documentation for PDF, Excel and JSON views
Issue: SPR-17180
Issue: SPR-17182

(cherry picked from commit c0c9e08bf9)
2018-08-14 21:45:17 +02:00
Juergen Hoeller 7894ecf445 Polishing 2018-08-13 14:29:36 +02:00
Juergen Hoeller 0e3f23eeb7 Polishing 2018-08-13 13:42:19 +02:00
Sam Brannen e306d3e83a Generate “Use” links in aggregated Spring API JavaDoc
This commit enables the `-use` javadoc flag so that class usage pages
are included in the aggregated JavaDoc that is published to
https://docs.spring.io/spring-framework/docs/.

Issue: SPR-17173
2018-08-13 11:59:35 +02:00
Rossen Stoyanchev f23496ae32 Fix URI var encoding issue with '$'
When expanding and strictly encoding URI variables, there is no need to
quote `/` and `$` which will be encoded anyway.

Issue: SPR-17168
2018-08-13 11:57:44 +03:00
Juergen Hoeller 1d8e5f4d85 Revert to Map entry iteration for less expensive static initialization
Issue: SPR-17169

(cherry picked from commit df51ff0386)
2018-08-12 21:02:26 +02:00
Juergen Hoeller d8aecd8c87 Post-processors consistently ignore ScopedObject/AopInfrastructureBean
Issue: SPR-17166
2018-08-12 14:36:20 +02:00
Stephane Nicoll 6ed03c24ac Disable quotes substitution in code sample
Issue: SPR-17167
2018-08-12 11:13:21 +02:00
Juergen Hoeller 9c1cbbb689 Post-processors consistently ignore ScopedObject/AopInfrastructureBean
Issue: SPR-17166
2018-08-11 22:46:17 +02:00
Juergen Hoeller 67d0c69a95 Polishing 2018-08-11 01:30:32 +02:00
Juergen Hoeller 951b39cc7a Polishing 2018-08-10 18:00:17 +02:00
Juergen Hoeller 1695ef7e87 Polishing 2018-08-09 18:07:03 +02:00
Juergen Hoeller 6f41d4ec4d DefaultLifecycleProcessor properly counts dependent beans in same phase
Issue: SPR-16901
2018-08-09 17:56:50 +02:00
Juergen Hoeller 42dbc39032 Polishing
(cherry picked from commit 8e571decc1)
2018-08-09 12:15:23 +02:00
Rossen Stoyanchev 1d45e326b7 Fix link from Spring MVC to OXM chapter 2018-08-09 10:29:10 +03:00
Juergen Hoeller 7737175140 Polishing 2018-08-09 03:02:52 +02:00
Juergen Hoeller e00fd52dc6 Polishing 2018-08-09 02:30:10 +02:00
Juergen Hoeller a159dd5993 AbstractAspectJAdvisorFactory uses AnnotationUtils.getValue 2018-08-09 02:07:00 +02:00
Juergen Hoeller d8d04d82c1 Polishing 2018-08-09 01:41:45 +02:00
Juergen Hoeller f3184a0878 Polishing 2018-08-09 00:49:54 +02:00
Juergen Hoeller 688ef9ad46 Find annotations on implemented generic superclass methods as well
Includes Java 8 getDeclaredAnnotation shortcut for lookup on Class.

Issue: SPR-17146

(cherry picked from commit 4521a79b2d)
2018-08-09 00:49:46 +02:00
Juergen Hoeller 9580bbd59f Expose checkbox field marker as 'hidden' to RequestDataValueProcessor
Issue: SPR-17147

(cherry picked from commit fa72186e28)
2018-08-09 00:49:39 +02:00
Juergen Hoeller a9305dbe8b ConcurrentModel ignores null value for put (also used by putAll)
Issue: SPR-17141

(cherry picked from commit b8b6367f9b)
2018-08-09 00:49:33 +02:00
Kazuhiro Sera a80f4caf37 Fix typos detected by github.com/client9/misspell
(cherry picked from commit be211ceead)
2018-08-09 00:49:27 +02:00
Rossen Stoyanchev eaafcee077 Proper use of setComplete in ContextPathCompositeHandler
Issue: SPR-17144
2018-08-08 16:41:50 +03:00
Juergen Hoeller a45ef35b38 Pruning of outdated JDK 6/7 references (plus related polishing)
(cherry picked from commit b325c74216)
2018-08-07 21:08:26 +02:00
Juergen Hoeller b87ee4ca32 ConcurrentModel.addAttribute(String, Object) ignores null value
Issue: SPR-17141

(cherry picked from commit 34ddb88851)
2018-08-07 21:08:18 +02:00
Juergen Hoeller 737ece71ca Polishing 2018-08-07 02:48:04 +02:00
Juergen Hoeller a938f528e2 Polishing 2018-08-07 02:41:18 +02:00
Juergen Hoeller 2b593b0b06 Upgrade to Log4J 2.11.1 2018-08-07 02:12:12 +02:00
Juergen Hoeller 4042c1d578 Polishing 2018-08-07 02:12:00 +02:00
Juergen Hoeller 34052945de Avoid unnecessary annotation introspection on framework methods
Issue: SPR-16933
2018-08-07 02:11:54 +02:00
Juergen Hoeller c814f5821a DisposableBean javadoc refers to singletons as well as scoped beans
Issue: SPR-17131

(cherry picked from commit f155d21c95)
2018-08-07 02:11:42 +02:00
Rossen Stoyanchev 6562e3047f takeUntilByteCount actually uses takeUntil
Issue: SPR-17188
2018-08-02 21:20:20 +03:00
Rossen Stoyanchev 0d0a0a2d08 Polish 2018-08-02 21:20:08 +03:00
Juergen Hoeller 08b5921fff Polishing 2018-08-02 17:45:46 +02:00
Juergen Hoeller f9307897b6 Polishing
(cherry picked from commit 2474c48749)
2018-08-02 17:18:08 +02:00
Juergen Hoeller f4c0421a7d Polishing
(cherry picked from commit dc36bb34c7)
2018-08-02 14:55:28 +02:00
Juergen Hoeller ecf6c381be SchedulerAccessor catches cluster race conditions on job rescheduling
Issue: SPR-17114

(cherry picked from commit fa97aab8be)
2018-08-02 14:55:22 +02:00
Juergen Hoeller 55e8aea2a3 Polishing 2018-08-01 12:35:01 +02:00
Juergen Hoeller 77e75fdf87 Avoid synthesizable annotation creation for @Bean/@Scope on scanning
Includes consistent (non-)use of AnnotationUtils/AnnotatedElementUtils.

Issue: SPR-16933
2018-08-01 12:18:10 +02:00
Juergen Hoeller 8c1290084d Polishing 2018-07-31 23:40:36 +02:00
Rossen Stoyanchev 4133355b72 Typo in URI Encoding section
Issue: SPR-17104
2018-07-31 23:28:08 +03:00
Rossen Stoyanchev 7476c5d5db Revert ""Order of messages" in STOMP section of reference docs"
This reverts commit dc066b0530 which
wasn't meant to be added to 5.0.x where the feature does not exist.
2018-07-31 23:15:49 +03:00
Juergen Hoeller fd75600c26 Polishing 2018-07-31 21:37:40 +02:00
Juergen Hoeller a4be54d760 Avoid synthesizable check for common annotation types
This revision immediately returns false from isSynthesizable for java.lang.annotation types.

Issue: SPR-16933
2018-07-31 21:37:34 +02:00
Juergen Hoeller f791b827ec Correct 404 status code and refined resolution failure log message 2018-07-30 23:33:53 +02:00
Juergen Hoeller a65c7ef780 Polishing 2018-07-30 23:13:22 +02:00
Juergen Hoeller 2a32c6cf57 Nullability refinements in spring-webmvc
Includes revision of web.servlet.tags.form for non-null conventions.

Issue: SPR-15540

(cherry picked from commit f74a631ea1)
2018-07-30 22:33:11 +02:00
Juergen Hoeller 91fa2ed0d4 Initialize pre-filled HashMaps with large enough capacity
Empty Maps are preferably initialized without capacity (not initializing them at all or lazily initializing with default capacity when needed).

Issue: SPR-17105

(cherry picked from commit 4a147d26fc)
2018-07-30 22:33:04 +02:00
Juergen Hoeller 006db06d11 Polishing 2018-07-27 18:48:09 +02:00
Juergen Hoeller 6839570187 Polishing
(cherry picked from commit 1fd6248d84)
2018-07-27 18:20:29 +02:00
Rossen Stoyanchev 5f96d7c46c Add notes on future deprecation of the RestTemplate
Issue: SPR-16993
2018-07-27 08:43:26 -04:00
Juergen Hoeller cca8968a44 Polishing 2018-07-26 23:40:32 +02:00
Juergen Hoeller b6a049a088 Polishing
(cherry picked from commit 7c9ba80f85)
2018-07-26 23:27:28 +02:00
Rossen Stoyanchev 2d83051ce1 bindToApplicatonContext uses WebSessionManager bean
Issue: SPR-17094
2018-07-26 16:05:33 -04:00
Rossen Stoyanchev f9ff6d4192 Polish 2018-07-26 15:54:21 -04:00
Juergen Hoeller 514c28b7c0 Revise BeanFactory vs ApplicationContext section in reference docs
Issue: SPR-17095

(cherry picked from commit 8277ea5794)
2018-07-26 18:50:21 +02:00
Juergen Hoeller 5da58393c1 Polishing 2018-07-26 15:55:15 +02:00
Juergen Hoeller 79936d98de Properly identify event-related ClassCastExceptions on JDK 11
Issue: SPR-17093

(cherry picked from commit e458777925)
2018-07-26 15:07:10 +02:00
Spring Buildmaster 7dff7bb7a4 Next Development Version 2018-07-26 07:49:44 +00:00
Juergen Hoeller d7cf2c869c MethodBeforeAdviceInterceptor implements BeforeAdvice marker interface
Includes related polishing in the advice interceptor implementations.

Issue: SPR-17088

(cherry picked from commit 4e03d3fdcb)
2018-07-25 20:16:48 +02:00
Juergen Hoeller c89fb745f7 ListBasedXMLEventReader uses defensive modifiable copy of given List
(cherry picked from commit 9ab63b8494)
2018-07-25 19:06:55 +02:00
Juergen Hoeller e214ee5c85 Backport of WebMvcConfigurationSupport javadoc revision 2018-07-25 15:39:39 +02:00
Juergen Hoeller 93ef169c5c Polishing 2018-07-25 14:40:31 +02:00
Brian Clozel 407bd96cf3 ResponseEntityResultHandler overwrites headers
Prior to this commit, controller handlers (regular and exception
handlers as well) would not overwrite existing HTTP response headers on
the exchange. This would lead to situations where Content-Type values
set during the initial handling phase would not be overwritten when
handling an error later on.

This commit aligns the implementation of that result handler on the
Spring MVC one in that regard.

Issue: SPR-17082
(Cherry-picked from 195f3f07e7)
2018-07-24 22:23:52 +02:00
Juergen Hoeller 0b5c099de2 Polishing 2018-07-24 22:10:07 +02:00
Juergen Hoeller 4f9a18f5aa Order setter for DefaultSimpUserRegistry
Issue: SPR-17023
2018-07-24 18:56:52 +02:00
Rossen Stoyanchev 9b3d80c5e4 Update STOMP section on working with subscriptions
1. Revise @SubscribeMapping to address common points of confusion.
2. Add ExecutorSubsribableChannel.
3. Split Events and Interception in two.

Issue: SPR-16950
2018-07-24 12:25:41 -04:00
Rossen Stoyanchev dc066b0530 "Order of messages" in STOMP section of reference docs
Issue: SPR-13989
2018-07-24 12:23:39 -04:00
Juergen Hoeller 0c44b5224f Polishing
(cherry picked from commit dd4468a)
2018-07-24 16:34:56 +02:00
Juergen Hoeller 207e8c2409 BeanFactoryAdvisorRetrievalHelper avoids synchronization for name cache
Issue: SPR-16570

(cherry picked from commit 7f1a8d7)
2018-07-24 16:34:50 +02:00
Juergen Hoeller 2329588856 Upgrade to Mockito 2.19.1 2018-07-24 15:00:47 +02:00
Juergen Hoeller f677d684e7 Polishing 2018-07-24 15:00:35 +02:00
Juergen Hoeller 3878db2e8c Provide predetermined capacity for cache operation collections
Issue: SPR-17079

(cherry picked from commit 20c34cb)
2018-07-24 14:59:05 +02:00
Rossen Stoyanchev 24a113fb27 Ensure headers work with ResponseEntity + reactive body
Issue: SPR-17076
2018-07-24 00:26:01 -04:00
Juergen Hoeller e21db2619b AspectJExpressionPointcut leniently ignores non-composable interfaces
Issue: SPR-17003

(cherry picked from commit bccff73)
2018-07-22 22:35:32 +02:00
Juergen Hoeller f5dd4d2c02 Polishing 2018-07-22 19:33:40 +02:00
Juergen Hoeller 192113de60 Correctly determine and propagate validation hints to DataBinder
Issue: SPR-17073

(cherry picked from commit 3c65c17)
2018-07-21 12:34:55 +02:00
Brian Clozel f89511e7fe Switch order of multipart Content-Type directives
Since SPR-15205, the `FormHttpMessageConverter` is adding a `charset`
directive to the `Content-Type` request header in order to help servers
understand which charset is being used to encode headers of each part.

As reported in SPR-17030 and others, some servers are not parsing
properly such header values and assume that `boundary` is the last
directive in the `Content-Type` header.

This commit reorders the charset information right before the boundary
declaration to get around those issues.

Issue: SPR-17030
(Cherry-picked from 390bb871d8)
2018-07-20 18:16:53 +02:00
Juergen Hoeller c3f6403f61 Polishing 2018-07-20 16:45:17 +02:00
Rossen Stoyanchev 5007d01c17 Fix for encoding issue with MvcUriComponentsBuilder
Provide method for stronger encoding of expanded URI variables when
building links from views.

Issue: SPR-17027
2018-07-19 19:07:22 -04:00
Rossen Stoyanchev f1c55a3b4a UriComponentsBuilder method to configure URI variables
See Javadoc on UriComponentsBuilder#uriVariables for details.

This helps to prepare for SPR-17027 where the MvcUriComponentsBuilder
already does a partial expand but was forced to build UriComonents
and then create a new UriComponentsBuilder from it to continue. This
change makes it possible to stay with the same builder instance.

Issue: SPR-17027
2018-07-19 19:07:22 -04:00
Rossen Stoyanchev 34a0cdfc33 Minor fixes: UriComponentsBuilder, UriComponents, docs
After the latest changes, two small fixes in the clone method to copy
the encode flag, and in the encodeUriTemplate method to account for
possible null query params.

Improvements in the URI encoding section.

Issue: SPR-17039, SPR-17027
2018-07-19 19:07:22 -04:00
Juergen Hoeller 1cd0135195 Restore original DefaultAdvisorChainFactory MethodMatcher invocation
Includes test for @Async pointcut against AOP proxy without target.
2018-07-20 00:33:27 +02:00
Juergen Hoeller 0c5c3103c6 ReflectiveMethodExecutor skips interface search (plus related polishing) 2018-07-19 16:51:13 +02:00
Juergen Hoeller c66f9d8880 Javadoc update: ConfigurationClassPostProcessor is priority-ordered
Issue: SPR-17062

(cherry picked from commit 0b60447)
2018-07-19 13:24:48 +02:00
Juergen Hoeller 4d3a899a53 OrderUtils caches order values (for AnnotationAwareOrderComparator)
Issue: SPR-17064

(cherry picked from commit d0bbbf4)
2018-07-19 13:24:43 +02:00
Juergen Hoeller 11fc086309 Prefer ArrayList/ArrayDeque over LinkedList for multi-element holders
LinkedList remains in place where a List is likely to remain empty or single-element (in order to avoid unused capacity).

Issue: SPR-17037

(cherry picked from commit 9c08a48)
2018-07-19 00:08:13 +02:00
Juergen Hoeller ed54895e53 Consistent exposure of nested parameter type in binding exceptions 2018-07-18 19:56:06 +02:00
Juergen Hoeller b72594d799 Find annotations on implemented generic interface methods as well
Issue: SPR-16060

(cherry picked from commit 23d4862)
2018-07-18 19:56:00 +02:00
Juergen Hoeller 4341838a21 Polishing 2018-07-18 14:53:19 +02:00
Brian Clozel 58f58e404e Avoid null signals when resolving handler arguments
Prior to this commit, resolving an argument for a WebFlux controller
that's missing from the request and not required by the handler would
throw a NullPointerException in some cases.

This involves the conversion of the parameter (a `String` parameter type
might not trigger this behavior) and sending a `null` within a reactive
stream, which is illegal per the RS spec.

We now rely on a `Mono.justOrEmpty()` to handle those specific cases.

Issue: SPR-17050
(Cherry-picked from a7f97a1669)
2018-07-18 14:48:06 +02:00
Juergen Hoeller c0040a5508 Polishing 2018-07-18 14:03:54 +02:00
Juergen Hoeller 55563c16b5 StringUtils.parseLocaleString detects variant without country
The parseLocale method also turns an empty locale into null now, compatible with parseLocaleString behavior.

Includes tests for parsing all available locales on the JVM, checking toString/toLanguageTag equality between parsed and original locale.

Issue: SPR-7598
Issue: SPR-16651

(cherry picked from commit cab35aa)
2018-07-18 14:03:30 +02:00
Juergen Hoeller ae1d500bc3 UrlBasedViewResolver exposes redirect prefix as bean name
Issue: SPR-17045

(cherry picked from commit b8d2a16)
2018-07-18 13:59:32 +02:00
Juergen Hoeller 9134588a82 Never return null from AnnotationMetadata.getMetaAnnotationTypes
Issue: SPR-17046

(cherry picked from commit cacd14c)
2018-07-18 13:59:11 +02:00
Juergen Hoeller d283424c82 Update ref doc references to Number/Currency/PercentStyleFormatter
Issue: SPR-17022

(cherry picked from commit 39d4550)
2018-07-18 13:58:45 +02:00
Andrew McCallum 6e019f9ed0 Correct method signature in code example
Closes gh-1887
2018-07-18 09:08:29 +02:00
Rossen Stoyanchev d9d41b4398 Polish 2018-07-17 17:41:44 -04:00
Rossen Stoyanchev eac0ddce13 Update URI Encoding section 2018-07-17 15:58:47 -04:00
Rossen Stoyanchev a363a229eb Update URI links section after encoding changes
Issue: SPR-17039
2018-07-16 21:25:27 -04:00
Rossen Stoyanchev 2bf7c18203 Add TEMPLATE_AND_VALUES mode to DefaultUriBuilderFactory
Issue: SPR-17039
2018-07-16 21:25:09 -04:00
Rossen Stoyanchev 9458186e83 Polish DefaultUriBuilderFactory 2018-07-16 21:24:52 -04:00
Rossen Stoyanchev d81ec55a60 Support for encode() in UriComponentsBuilder
The ability to request to encode before `build()`, and more importantly
before expanding, allows stricter encoding to be applied to URI vars
and consequently to neutralize the effect of characters with reserved
meaning in a URI.

Issue: SPR-17039
2018-07-16 21:24:16 -04:00
Stephane Nicoll 4c8d81bcb4 Fix typo
Issue: SPR-17042
2018-07-15 16:18:25 +02:00
Rossen Stoyanchev 6218db9831 Backport of InMemoryWebSession changes
- hooks to check expired sessions in both create and retrieve.
- maxSessions limit on the total number of sessions.
- getSessions method for management purposes
- removeExpiredSessions public API

Issue: SPR-17020, SPR-16713
2018-07-12 16:27:42 -04:00
Rossen Stoyanchev 7ea8ecb6ab Warn when SimpleAsyncTaskExecutor is used
Issue: SPR-16203
2018-07-11 11:21:49 -04:00
Guilherme Alan Ritter 8c1bc63c9d Fix typo
Closes gh-1880
2018-07-10 15:48:40 +02:00
Rossen Stoyanchev f179181b40 Polish Reactive Spring Web section 2018-07-09 15:58:35 -04:00
Juergen Hoeller eb3254d2a9 Polishing 2018-07-06 15:18:47 +02:00
Juergen Hoeller 6cae0650e6 Upgrade to Jackson 2.9.6 2018-07-06 01:42:07 +02:00
Juergen Hoeller 43868d2b72 Polishing 2018-07-06 01:39:34 +02:00
Juergen Hoeller a8b747c21c Polishing 2018-07-04 22:55:38 +02:00
Juergen Hoeller 490b78a3d3 Polishing 2018-07-04 20:58:27 +02:00
Juergen Hoeller 1ab9e2ceda Polishing 2018-07-04 15:46:52 +02:00
Juergen Hoeller a1d35c23aa ConcurrentModel.addAttribute javadoc: null value not supported
Issue: SPR-16831
2018-07-04 15:45:53 +02:00
Juergen Hoeller 99534a31ba MapSqlParameterSource.addValue declares nullable value parameter
Issue: SPR-16843

(cherry picked from commit d9c6318)
2018-07-04 15:45:32 +02:00
Sebastien Deleuze c6dbfe42d3 Upgrade to Kotlin 1.2.51 2018-07-04 11:25:01 +02:00
Juergen Hoeller acf9ea097a Polishing 2018-07-03 17:11:27 +02:00
Juergen Hoeller decbb43757 Upgrade to Apache Johnzon 1.1.8 2018-07-03 16:23:51 +02:00
Juergen Hoeller 0480e75785 Polishing 2018-07-03 16:23:43 +02:00
Juergen Hoeller ac1e2879e5 Consistent throwing of HttpMessageNotReadableException (5.0.x revision)
Includes specific fine-tuning of ProtobufHttpMessageConverter and JAXB2 based message converters, as well as revised javadoc for abstract base classes.

Issue: SPR-16995
2018-07-03 16:23:36 +02:00
Juergen Hoeller ce0323fa8c ConcurrentReferenceHashMap caches EntrySet in volatile field
Includes an efficient implementation of isEmpty(), not relying on a full entry count but rather backing out once a non-empty hash segment has been found.

Issue: SPR-16994
2018-07-03 16:23:28 +02:00
Juergen Hoeller 0052c899bd Same method filtering in ConstructorResolver and getTypeForFactoryMethod
Issue: SPR-16999

(cherry picked from commit f2787cf)
2018-07-03 16:23:20 +02:00
Juergen Hoeller 8c07c6d099 Polishing 2018-07-01 02:35:35 +02:00
Juergen Hoeller 214fa9c2a0 Polishing 2018-06-29 22:43:13 +02:00
Juergen Hoeller ea534b6820 Polishing 2018-06-29 20:07:53 +02:00
Juergen Hoeller 5a111125c1 Up-to-date coverage of task executor and scheduler variants
Includes a clarification of ThreadPoolExecutor configuration options and a note on early AsyncConfigurer initialization.

Issue: SPR-16944
Issue: SPR-16945

(cherry picked from commit d58c09b)
2018-06-29 20:07:44 +02:00
Juergen Hoeller ac48c64b1a Upgrade to Mockito 2.19 and Mockito Kotlin 1.6 2018-06-28 18:13:59 +02:00
Juergen Hoeller 9a20ec9284 Polishing 2018-06-28 18:13:40 +02:00
Juergen Hoeller 03beee7b68 Upgrade to Tomcat 8.5.32, RxJava 2.1.16, Selenium 3.13 2018-06-28 17:33:30 +02:00
Juergen Hoeller 4be6bcae74 Polishing 2018-06-28 17:30:55 +02:00
Juergen Hoeller 6d0f8bf145 Support for new JsonMappingException wording in Jackson 2.9
Issue: SPR-16947
2018-06-28 16:42:35 +02:00
Juergen Hoeller a631af80c1 Polishing
(cherry picked from commit 40efcc9)
2018-06-28 16:42:14 +02:00
Juergen Hoeller 3e64388b20 Conventions lazily retrieves shared ReactiveAdapterRegistry
Issue: SPR-16981

(cherry picked from commit b68e692)
2018-06-28 16:41:51 +02:00
Juergen Hoeller d3b06a15f2 StringUtils.cleanPath retains plain pointer to current directory
Issue: SPR-16908

(cherry picked from commit 7a02e43)
2018-06-28 16:41:44 +02:00
Juergen Hoeller 75f26eec98 Fix FreeMarker escaping regression for messages and separators
Issue: SPR-16951

(cherry picked from commit 08e1c8c)
2018-06-28 16:41:33 +02:00
Juergen Hoeller 4402336c44 MimeTypeUtils lazily initializes SecureRandom for multipart boundary
Issue: SPR-16974

(cherry picked from commit 847202c)
2018-06-28 16:41:18 +02:00
Juergen Hoeller e388ddfdde WebHttpHandlerBuilder retains ApplicationContext in copy constructor
Issue: SPR-16972

(cherry picked from commit 2a15962)
2018-06-28 16:41:13 +02:00
Napster f83a01e573 Undertow WebSocket sessions share ByteBufferPool
Issues: SPR-16957
2018-06-25 17:59:34 -03:00
Brian Clozel d1c9401dc2 WebClient writes Content-Length for Mono bodies
In SPR-16892, the `EncoderHttpMessageWriter` has been improved to write
`"Content-Length"` HTTP response headers if the response body is of type
`Mono` (i.e. the actual content length is easily accessible without
buffering a possibly large response body). That change was relying on
the fact that the server side is using a `ChannelSendOperator` to delay
the writing of the body until the first signal is received.

This strategy is not effective on the client side, since no such channel
operator is used for `WebClient`. This commit improves
`EncoderHttpMessageWriter` and delays, for `Mono` HTTP message bodies
only, the writing of the body so that we can write the
`"Content-Length"` header information once we've got the body resolved.

Issue: SPR-16949
(Cherry-picked from 4a26f93a0d)
2018-06-19 11:52:26 +02:00
Ryan Yin 60838dcd03 Fix broken link to CONTRIBUTING.md
Closes gh-1860
2018-06-19 09:08:13 +02:00
Rossen Stoyanchev 3526766635 Fix documentation issue 2018-06-18 20:35:57 -04:00
Rossen Stoyanchev 425c311d3c Correctly set maxAge and expires in ResponseCookie
Issue: SPR-16940
2018-06-14 13:16:55 -04:00
Rossen Stoyanchev 24acae1195 Polish ExchangeFilterFunction[s] 2018-06-13 17:15:47 -04:00
Rossen Stoyanchev 49f21ac3ac Polish form writer and converter 2018-06-13 17:15:36 -04:00
Rossen Stoyanchev 8339e7ade5 Use reflection for JdkFlowAdapter
To avoid compiler issues on Eclipse.
2018-06-13 09:41:10 -04:00
Spring Buildmaster 4560f096b9 Next Development Version 2018-06-12 15:09:58 +00:00
Rossen Stoyanchev 4ec9f5df5c Minor polishing for URI encoding docs 2018-06-12 10:15:43 -04:00
Juergen Hoeller 224fcc1712 Remove outdated Servlet environment constraints from annotation javadoc
Includes removal of PathVariable's MultiValueMap support claim.

Issue: SPR-16936

(cherry picked from commit 0b64bcd)
2018-06-12 11:35:55 +02:00
Brian Clozel 96eba8b997 Fix ResourceRegion HttpMessageConverter write checks
This commit fixes the write checks for
`ResourceRegionHttpMessageConverter`, which was previously not checking
properly the parameterized type (e.g. in case of a `List<Something>`).

Issue: SPR-16932
(Cherry-picked from 05ff8b722d)
2018-06-11 22:57:36 +02:00
Rossen Stoyanchev be5229949c Add HTTP caching to WebFlux section
Issue: SPR-16395
2018-06-11 16:44:35 -04:00
Rossen Stoyanchev 516937cfc5 Polish Spring MVC docs on HTTP Caching
Issue: SPR-16395
2018-06-11 16:44:25 -04:00
Brian Clozel dac97f1b7d Restrict HTTP methods on Reactive HiddenHttpMethodFilter
This commit restricts the allowed HTTP methods on HiddenHttpMethodFilter
(Reactive variant) to the following: PUT, DELETE, PATCH.

This filter is meant to be used to simulate those methods from HTML
forms sent by browsers, so no other methods are allowed.

Issue: SPR-16836
(Cherry-picked from a5cd01a4c8)
2018-06-11 19:17:00 +02:00
Brian Clozel f2694a8ed9 Restrict HTTP methods on Servlet HiddenHttpMethodFilter
This commit restricts the allowed HTTP methods on HiddenHttpMethodFilter
(Servlet variant) to the following: PUT, DELETE, PATCH.

This filter is meant to be used to simulate those methods from HTML
forms sent by browsers, so no other methods are allowed.

Issue: SPR-16836
(Cherry-picked from f64fa3dea1)
2018-06-11 19:16:44 +02:00
Juergen Hoeller 82f421bff8 Upgrade to Reactor Bismuth SR10 2018-06-11 18:09:01 +02:00
Juergen Hoeller a2765c009e Polishing 2018-06-11 18:08:39 +02:00
Juergen Hoeller 78d3164543 Remove outdated javadoc references to SpEL lambda functions
Issue: SPR-16930

(cherry picked from commit 6df7ba2)
2018-06-11 18:08:20 +02:00
Brian Clozel afcc430481 Remove dependency management noise from POMs
Prior to this commit, the generated POMs for Spring Framework modules
would contain unneeded/harmful information from the Spring Framework
build:

1. The BOM imports applied to each module by the dependency
management plugin, for example for Netty or Reactor Netty.
Spring should not export that opinion to its POMs.

2. The exclusion of "org.slf4:jcl-over-slf4j" from *all* dependencies,
which made the POMs much larger than necessary and suggested to
developers that they should exclude it as well when using all those
listed dependencies. In fact, only Apache Tiles currently brings that
transitively.

This commit removes that information from the POMs.
The dependencyManagement Gradle plugin is disabled for POM generation
and we manually resolve the dependency versions during the generation
phase.
The Gradle build is streamlined to exclude "org.slf4:jcl-over-slf4j"
only when necessary.

Issue: SPR-16893
(Cherry-picked from 417354da8a)
2018-06-11 16:02:11 +02:00
Juergen Hoeller 062a15fbd7 Latest applicable dependency updates (Jetty 9.4.11, Netty 4.1.25, Hibernate ORM 5.1.14, HSQLDB 2.4.1, Derby 10.14.2.0, HtmlUnit 2.31, Selenium 3.12) 2018-06-11 15:02:44 +02:00
Juergen Hoeller c04c8a2472 Polishing 2018-06-11 15:01:18 +02:00
Juergen Hoeller f39adcf865 AbstractMethodMessageHandler processes Error as MessageHandlingException
Issue: SPR-16912
2018-06-11 14:59:44 +02:00
Juergen Hoeller da049f480b ReflectivePropertyAccessor caches sorted methods per class
Issue: SPR-16882
2018-06-11 14:59:08 +02:00
Juergen Hoeller 455d8ac7b9 Correct code example for YamlProcessor.setDocumentMatchers
Issue: SPR-16849

(cherry picked from commit 7ece0e2)
2018-06-11 14:58:42 +02:00
Sebastien Deleuze b80c13b722 Deprecate JSONP and disable it by default in Jackson view
Issue: SPR-16798
2018-06-08 12:31:40 +02:00
Rossen Stoyanchev 7bfd683816 Eliminate the need for Encoder#getContentLength
Issue: SPR-16892
2018-06-04 16:01:48 -04:00
Jason Zhekov fe01e5114d Fix format typo in webmvc.adoc
Closes gh-1849
2018-06-04 20:56:55 +02:00
Stephane Nicoll b5595c3904 Fix faulty BeanPostProcessorChecker logs with @EnableCaching
Issue: SPR-16896
2018-06-04 15:01:57 +02:00
Violeta Georgieva 76678e9c6a Fix code examples for WebFlux functional endpoints
Closes gh-1844
2018-05-31 15:19:28 +02:00
Johnny Lim b3a34f8397 Polish doc
Closes gh-1843
2018-05-31 10:21:36 +02:00
Juergen Hoeller 79adffd214 Upgrade to Hibernate Validator 6.0.10, RxJava 2.1.14, Gson 2.8.5 2018-05-30 11:59:57 +02:00
Juergen Hoeller af0a82931e Polishing
(cherry picked from commit 1b728fb)
2018-05-30 11:59:30 +02:00
Juergen Hoeller bbe5124556 Polishing 2018-05-29 22:16:48 +02:00
Juergen Hoeller 5935b7aefe Doc: @EnableScheduling needs to be declared per application context
Issue: SPR-16852

(cherry picked from commit b39ce80)
2018-05-29 22:00:34 +02:00
Juergen Hoeller a2d7cc7a69 AbstractRequestLoggingFilter.isIncludeHeaders() declared as protected
Issue: SPR-16881

(cherry picked from commit c754232)
2018-05-29 22:00:24 +02:00
Juergen Hoeller 8a56db6e4e SimpleAliasRegistry logs info message for alias overriding
Issue: SPR-16871

(cherry picked from commit 74fcdea)
2018-05-29 22:00:14 +02:00
Juergen Hoeller 50d6d90ed8 Restore lenient null return value for ConditionContext.getBeanFactory()
Includes nullable return value for getClassLoader() with corresponding notes in applicable javadoc.

Issue: SPR-16866

(cherry picked from commit 46a89d9)
2018-05-29 22:00:05 +02:00
Arjen Poutsma a7ffe092ab Fix parent path variables in nested route functions
This commit fix an issue where path variables in a nested parent
RouterFunction were not committed to the request attributes.

Issue: SPR-16868

(cherry picked from commit 8c30b8e)
2018-05-29 15:57:52 +02:00
Sebastien Deleuze 6407cb9baf Fix PropertyResolverExtensions.kt location 2018-05-28 15:53:03 +02:00
Gary Russell 0bc0762577 Fix JMS Doc typo
There is no such class `ReplyQosSettings`.

Closes gh-1836
2018-05-25 16:32:09 +02:00
Rossen Stoyanchev 051ab05d32 Properly initialize URI/Matrix vars w/ urlDecode=false
Issue: SPR-16867
2018-05-24 15:10:55 -04:00
Rossen Stoyanchev 9d36fd0b68 Respect async request timeout of -1 in MockMvc
When falling back on the timeout associated with the async request,
a value of -1 must be treated as: never time out.

Issue: SPR-16869
2018-05-24 12:36:47 -04:00
Rossen Stoyanchev f078e057ce Update docs on WebClient filters 2018-05-24 07:20:24 -04:00
Rossen Stoyanchev 941186a359 Minor update to STOMP chapter
Issue: SPR-16681
2018-05-23 21:50:46 -04:00
Rossen Stoyanchev 27fc4d6053 ChannelInterceptor default methods + deprecate adapter 2018-05-23 21:50:34 -04:00
Rossen Stoyanchev 1943a1f5bd Fix error in WebFlux chapter on static resources
Issue: SPR-16864
2018-05-23 21:25:26 -04:00
Rossen Stoyanchev a158ff4c3d Return SslInfo only if X509Certificate[] present
Issue: SPR-16842
2018-05-23 14:58:23 -04:00
Rossen Stoyanchev a71bd7c03f Immutable Resource[Resolver|Transformer]Chains
Backport of #f121aa5e31, applied to spring-webflux only.

Issue: SPR-16862
2018-05-23 09:53:26 -04:00
Sebastien Deleuze 1fefe2ab0c Upgrade to Dokka 0.9.17 2018-05-22 17:44:28 +02:00
Rossen Stoyanchev 0b36c9437e CodecConfigurer internal refactoring
Improve how HTTP message writers are obtained for general use vs for
multipart requests.
2018-05-21 21:15:17 -04:00
Rossen Stoyanchev 72e7687b80 Polish CodecConfigurer related classes
Functionally equivalent updates to package private classes to improve
the code and make it easier to understand.
2018-05-21 21:15:05 -04:00
Rossen Stoyanchev e87355b29c STOMP client supports setting accept-version
Issue: SPR-16844
2018-05-18 15:13:14 -04:00
Rossen Stoyanchev 1dc8201df1 Polish ReactiveAdapterRegisry 2018-05-18 09:30:10 -04:00
Rossen Stoyanchev e3e975d7f9 Support for SslInfo in ServerHttpRequest#mutate
Issue: SPR-16830
2018-05-17 17:29:33 -04:00
Rossen Stoyanchev b385ff1d9f Polish WebFlux WebSocket docs
Issue: SPR-16820
2018-05-17 10:03:24 -04:00
Arjen Poutsma 3c88029dd3 Improve toString for filtered router function
Issue: SPR-16829

(cherry picked from commit f722f40)
2018-05-17 12:02:57 +02:00
Rossen Stoyanchev c7adf28f61 Expand WebFlux docs with WebSocketHandler examples
Issue: SPR-16820
2018-05-16 21:33:47 -04:00
Rossen Stoyanchev c555fef6f2 Improve TCP connection info logging.
After the recent changes to expose configuring TcpOperations, it no
longer makes sense to automatically log the relayHost/Port since that's
mutually exclusive with a custom TcpOperations.

Instead we delegate to TcpOperations.toString().

Issue: SPR-16801
2018-05-16 14:26:29 -04:00
Rossen Stoyanchev ab0b0b31fd Polish: simplify ControllerMethodResolver initialization 2018-05-16 10:04:08 -04:00
Arjen Poutsma d24546ad18 Improve toString for query param and path extension predicates
Issue: SPR-16829

(cherry picked from commit 7424ca5)
2018-05-16 11:16:11 +02:00
Juergen Hoeller 2818051aff Revised code examples for stored procedure type declarations
Issue: SPR-16811

(cherry picked from commit 765d18e)
2018-05-16 09:09:55 +02:00
Juergen Hoeller a3bcdbe371 SchedulerFactoryBean triggers shutdown after registration failure
Issue: SPR-16816

(cherry picked from commit 0098245)
2018-05-16 09:09:44 +02:00
Juergen Hoeller 3978d5500d Query termination for JPA 2.1 StoredProcedureQuery.execute() method
Issue: SPR-16826

(cherry picked from commit 3c8c996)
2018-05-16 09:09:35 +02:00
Juergen Hoeller 416dee7226 AspectJExpressionPointcut evaluates interface method on proxy as well
Issue: SPR-16803

(cherry picked from commit bba5dca)
2018-05-16 09:09:24 +02:00
Sebastien Deleuze 4d69ec48b1 Add StatusResultMatchers.isEqualTo Kotlin extension
Issue: SPR-16429
2018-05-15 15:42:25 +02:00
Sebastien Deleuze 14a9d291e1 Filter synthetic in ReflectionUtils#USER_DECLARED_METHODS
Issue: SPR-16823
2018-05-15 15:01:31 +02:00
Sebastien Deleuze 5183f71a78 Update Kotlin refdoc with the new tutorial 2018-05-14 10:54:10 +02:00
Rossen Stoyanchev fd36af6fcf Inject UriComponentsBuilder relative to webapp root
Issue: SPR-16813
2018-05-11 09:54:35 -04:00
Rossen Stoyanchev 9179a4fa30 Correct coordinates for Reactor Netty in STOMP chapter
Issue: SPR-16802
2018-05-10 16:47:17 -04:00
nkjackzhang 98335b41f7 Fix a typo in javadoc
Closes gh-1824
2018-05-10 17:32:58 +02:00
Rossen Stoyanchev e9f4dec08c Restore layout of docs zip with index.html at the top
Issue: SPR-16799
2018-05-09 17:29:38 -04:00
Spring Buildmaster 4ec695b4d9 Next Development Version 2018-05-08 08:34:28 +00:00
Juergen Hoeller 2da02ccbd0 Polishing
(cherry picked from commit 70424a7)
2018-05-08 00:25:46 +02:00
Juergen Hoeller f2cc70ecf9 Explicit coverage of root vs cause exception matching in MVC ref docs
Issue: SPR-16743

(cherry picked from commit a200df6)
2018-05-07 23:18:33 +02:00
Rossen Stoyanchev e2115594c0 Document throwExceptionIfNoHandlerFound property
Issue: SPR-16786
2018-05-07 16:12:25 -04:00
Juergen Hoeller 2008e04354 Upgrade to Servlet API 4.0.1 2018-05-07 14:38:16 +02:00
Juergen Hoeller b4f83dbdc3 Polishing 2018-05-07 14:30:50 +02:00
Juergen Hoeller 0795ae5c6a Polishing 2018-05-05 16:55:06 +02:00
Juergen Hoeller 41ab177b6c Fine-tuned assertions and related polishing 2018-05-05 14:59:13 +02:00
Juergen Hoeller 8848ec73ab Refined backport of gh-1817 2018-05-05 13:18:08 +02:00
Juergen Hoeller 9f9481ec7b Upgrade to Tomcat 8.5.31, Undertow 1.4.25, Jetty 9.4.10, Gson 2.8.4
Includes upgrade from Reactor snapshots to Bismuth SR9.
2018-05-05 13:17:44 +02:00
Juergen Hoeller f6275e009b YamlProcessor embraces SnakeYAML 1.18+ duplicate key handling
Includes deprecation of StrictMapAppenderConstructor.

Issue: SPR-16791

(cherry picked from commit 138b0d0)
2018-05-05 13:17:10 +02:00
Juergen Hoeller ed44262a71 ResponseEntityExceptionHandler rethrows unknown exception (for further processing in DispatcherServlet's HandlerExceptionResolver chain)
Issue: SPR-16743

(cherry picked from commit 7b894fe)
2018-05-05 13:17:00 +02:00
Johnny Lim a0d37ac29e Remove inconsistent spaces
(cherry picked from commit fb898e1)
2018-05-05 12:49:26 +02:00
Johnny Lim a39938d251 Polish DatabaseStartupValidator
(cherry picked from commit 8f21cb1)
2018-05-05 12:49:10 +02:00
nkjackzhang edb33331ed Task "docsZip" copies duplicate reference files
Specify task "docsZip" source directory.
Issue: SPR-16789
2018-05-03 16:39:51 -04:00
Arjen Poutsma a63f04df09 Clean up path variables after non match
This commit makes sure the nested path variables are only commited to
the attributes when all predicates match.

Issue: SPR-16692

(cherry picked from commit 51325af)
2018-05-03 12:06:06 +02:00
Juergen Hoeller 5a98516f6c Lenient fallback to plain getBundle call without Control handle
Issue: SPR-16776
2018-05-02 16:54:38 +02:00
Juergen Hoeller 30363c84bd Consistent SpelEvaluationException messages in findAccessorForMethod
Issue: SPR-16762
2018-05-02 16:53:55 +02:00
Juergen Hoeller fa27130b82 Upgrade to RxJava 2.1.13, Hibernate ORM 5.2.17, AspectJ 1.9.1 2018-05-02 16:32:55 +02:00
Juergen Hoeller be4c07fc32 Expose FactoryBean's raw object on retrieval during post-processing
Issue: SPR-16783

(cherry picked from commit 9281f82)
2018-05-02 16:32:18 +02:00
Juergen Hoeller 22f421cc51 Introspect originating bean definition as configuration class candidate
Issue: SPR-16756

(cherry picked from commit c8b6233)
2018-05-02 16:31:57 +02:00
Juergen Hoeller 9dc538a7c6 Nullable HttpMethod parameter only on internal doExecute delegate
Issue: SPR-15540

(cherry picked from commit f8c2d7a)
2018-05-02 16:31:33 +02:00
Juergen Hoeller d74a2730ec SimpleClientHttpResponse catches any Exception on close
Issue: SPR-16773

(cherry picked from commit 21fad8e)
2018-05-02 16:07:22 +02:00
Juergen Hoeller 3e47f4564d Fine-tuned assertions and related polishing in WebFlux builders
(cherry picked from commit 9bff5b4)
2018-05-02 16:04:51 +02:00
Juergen Hoeller a9548f93e4 Support for non-standard HTTP status in reactive ClientHttpResponse
Issue: SPR-16748

(cherry picked from commit a683472)
2018-05-02 16:04:01 +02:00
Juergen Hoeller f2e77c292d Consistent target method resolution for event and caching expressions
Issue: SPR-16779

(cherry picked from commit eaff2c2)
2018-05-02 16:02:46 +02:00
Juergen Hoeller 8b051ab06e AopUtils.getMostSpecificMethod exposes dynamic proxy class methods
Includes efficient canApply check for IntroductionAwareMethodMatcher.

Issue: SPR-16757

(cherry picked from commit aa11721)
2018-05-02 16:01:48 +02:00
Oleksandr Hasheniuk 5a1d7f9c4b Improve performance of StringUtils#trimWhitespace
Issue: SPR-16766

(cherry picked from commit 6545cab)
2018-05-02 16:01:04 +02:00
Sebastien Deleuze b55f69deb1 Support decoding Mono in Jaxb2XmlDecoder
Issue: SPR-16759
2018-05-02 11:57:40 +02:00
Rossen Stoyanchev de1eb343e7 Polish WebSocketIntegrationTests 2018-05-01 14:26:44 -04:00
Rossen Stoyanchev 417bb302c3 ReactorNettyWebSocketSession implements close properly
Issue: SPR-16774
2018-05-01 12:05:20 -04:00
Rossen Stoyanchev b0aa08a671 Consistent handling of URISyntaxException
Issue: SPR-16778
2018-04-30 21:05:08 -04:00
Sebastien Deleuze 9dc79982e2 Upgrade to Kotlin 1.2.41
Fixes KT-23973 critical regression
2018-04-30 10:48:23 +02:00
Stephane Nicoll 43f2334e82 Keep YAML entries that haven an empty array value
Prior to this commit, a YAML entry that define an empty array value was
lost. This commit makes sure to flag it with an empty String, which
corresponds as an empty comma separated list of entries in the
properties format.

Issue: SPR-16769
2018-04-29 11:15:53 +02:00
Nickloas 6c6e44b58e Fix typo
Closes gh-1813
2018-04-28 10:52:03 +02:00
Johnny Lim c6b60f0c00 Polish 2018-04-27 14:09:35 -04:00
sdeleuze 7aba6ca9d6 Fine tune WebFlux server logging verbosity
With this commit, WebFlux server uses warning instead of error log level
for request handling, and also just print the message instead of the
stacktrace which is mostly meaningless in reactive world.

Complementary to this change, Reactor Netty removed additional logging
as part of https://github.com/reactor/reactor-netty/issues/339.

Issue: SPR-16688
2018-04-27 10:36:06 +02:00
nkjackzhang dca77c0666 Fix broken anchor link in WebFlux refdoc 2018-04-27 08:49:51 +02:00
sdeleuze df6e690e33 Reuse PartBodyStreamStorageFactory in SynchronossPartGenerator
Issue: SPR-16727
2018-04-26 11:01:17 +02:00
nkjackzhang a702ef8074 Fix typos in Spring MVC refdoc
1. Consistent with "xml code" examples.
2. "xml()" is a static method and will use default builder config,
   so use createXmlMapper(true) instead.
3. Fix mvc namespace tag typo.
2018-04-26 10:03:27 +02:00
Rossen Stoyanchev f7376bdde3 Better assertion message in MockPart
Issue: SPR-16767
2018-04-25 10:00:18 -04:00
nkjackzhang f9e31b503c Fix typos
Closes gh-1806
2018-04-25 10:07:34 +02:00
hasheniuk 3551dd92fb Fix typo
Closes gh-1804
2018-04-24 10:06:49 +02:00
Rossen Stoyanchev c23297fe76 Add more detail to ISE in ServerEndpointExporter
Issue: SPR-16655
2018-04-23 17:04:16 -04:00
Rossen Stoyanchev a5622d0dd2 Validate contextPath in RedirectView
Issue: SPR-16752
2018-04-23 15:21:33 -04:00
Brian Clozel 72cfe41f30 Disable HTTP Range support for InputStreamResource
Prior to this commit, the `AbstractMessageConverterMethodProcessor`
would fail to convert `InputStreamResource` to `ResourceRegion` as
expected, since the content length cannot be read without consuming the
stream. This is enforced by the `HttpRange` class.

Now the method processor would still try to output HTTP range response
headers to provide range support information. This step is using the
resource content length and reads the input stream, leading to
exceptions such as "IllegalStateException: InputStream has already been
read".

This commit improves the return type detection and excludes early
`InputStreamResource` return types. With those types, HTTP range support
is now completely disabled.

Issue: SPR-16754
(cherry picked from commit e9a8a5065b)
2018-04-23 18:40:15 +02:00
sdeleuze 4ff595e2bc Upgrade Kotlin to 1.2.40 2018-04-23 15:31:31 +02:00
sdeleuze 2c766b9501 Enable KotlinScriptTemplateTests after KT-18833 fix 2018-04-23 15:31:31 +02:00
Dimitrios (Dimi) Liapis 2960a558d7 Fix typo
See gh-1803
2018-04-21 18:21:19 +02:00
Brian Clozel d69a281e5c Upgrade to Netty 4.1.24.Final 2018-04-21 09:31:29 +02:00
Rossen Stoyanchev d3ed7b624d In 5.0.x we don't have Flux/Mono error with Supplier
Issue: SPR-16726
2018-04-19 13:41:01 -04:00
Rossen Stoyanchev 66bd277671 Use StringDecoder to split SSE stream
ServerSentEventHttpMessageReader had logic to split on new lines
and buffer until an empty new line (start of a new event). To account
for random data chunking, it later re-assembled the lines for each
event and split again on new lines. However bufferUntil was still
unreliable a chunk may contain nothing but a newline, which doesn't
necessarily mean an empty newline in the overall SSE stream.

This commit simplifies the above by delegating the splitting of the
stream along newlines to StringDecoder.

Issue: SPR-16744
2018-04-19 11:38:43 -04:00
Rossen Stoyanchev 881343e928 Polish tests to use WebClient retrieve() 2018-04-19 11:38:43 -04:00
Daniel Kift 922fd1e785 Polish WebFlux reference documentation 2018-04-18 11:58:37 +02:00
nkjackzhang ea8317a1f9 Fix a typo in @Nullable Javadoc 2018-04-18 11:55:13 +02:00
Rossen Stoyanchev 053ffe808f Polish (minor) in AbstractMessageReaderArgumentResolver 2018-04-17 17:58:56 -04:00
Rossen Stoyanchev daa2d37ad4 Avoid creating Exception instance if not needed
Issue: SPR-16726
2018-04-17 17:58:46 -04:00
Juergen Hoeller f800df12e3 Correctly delegate to OrderUtils.getPriority for DecoratingProxy
Issue: SPR-16739

(cherry picked from commit 2f4010e)
2018-04-17 23:38:30 +02:00
Juergen Hoeller 26652a6b83 Avoid repeated superclass introspection in findAnnotation(Method,...)
Issue: SPR-16730

(cherry picked from commit d78e27f)
2018-04-17 17:06:31 +02:00
Juergen Hoeller 4cd43dc793 Workaround for generic parameter types on inner class constructors
Issue: SPR-16734
2018-04-17 15:32:03 +02:00
sdeleuze 91c8b62817 Make ResponseSpec.expectBody Kotlin extension usable
Prior to this commit, due to KT-5464 type inference issue there was not
proper way to provide body expectations with WebTestClient. This commit
provides a workaround by updating the existing Kotlin extension to
return a Kotlin compatible API.

Issue: SPR-15692
2018-04-17 14:58:12 +02:00
Juergen Hoeller 9d37c099a8 OperatorMatches flags misguided evaluation attempts as FLAWED_PATTERN
Issue: SPR-16731

(cherry picked from commit d4a55a2)
2018-04-17 13:35:01 +02:00
Juergen Hoeller eb573d8b9e Restore original MethodMapTransactionAttributeSource matching rules
Issue: SPR-16733

(cherry picked from commit c5b524d)
2018-04-17 13:34:38 +02:00
Rossen Stoyanchev b312a62f64 Selector header name is exposed for configuration
Issue: SPR-16732
2018-04-16 23:58:47 -04:00
Rossen Stoyanchev 567733d2a1 Restore handling of 0 bytes read
Issue: SPR-16728
2018-04-16 10:01:51 -04:00
Juergen Hoeller 0f91f4b960 Local XMLUnit dependency declarations with consistent version 2.5.1
Includes upgrade to Undertow 1.4.24.

(cherry picked from commit 0754833)
2018-04-14 21:23:33 +02:00
Juergen Hoeller c1385f52c2 Polishing
(cherry picked from commit de4ff4b)
2018-04-14 21:03:59 +02:00
Sam Brannen c3bc125093 Suppress warning in SpringFailOnTimeoutTests 2018-04-14 16:44:47 +02:00
Juergen Hoeller b5922f75bb AspectJExpressionPointcut consistently resolves superinterface methods
Includes efficient check for same ClassLoader in ClassUtils.isVisible, efficient MethodMatchers check for IntroductionAwareMethodMatcher, and supertype method resolution in MethodMapTransactionAttributeSource.

Issue: SPR-16723

(cherry picked from commit b95e05d)
2018-04-14 15:49:55 +02:00
nkjackzhang bbe850d33a Fix typo in javadoc
Closes gh-1791
2018-04-13 13:16:40 +02:00
Juergen Hoeller 295929cc16 Cache-safety check for sibling loaders resolving the same classes
Issue: SPR-16714
2018-04-12 21:08:25 +02:00
Juergen Hoeller 4763154193 Consistent getTypeForFactoryMethod result for parameterized method
Issue: SPR-16720

(cherry picked from commit 6184c4e)
2018-04-12 21:08:14 +02:00
Juergen Hoeller 8f7e5e7c1a Fine-tuned JCA MessageEndpoint exception logging and propagation
Issue: SPR-16717

(cherry picked from commit 8e1ecec)
2018-04-12 21:07:44 +02:00
Juergen Hoeller cd79966c52 Revised reference example for linkable controller method signature
Issue: SPR-16710

(cherry picked from commit 7ee6130)
2018-04-12 21:07:39 +02:00
Brian Clozel 7631aa6062 Switch to Reactor Bismusth SNAPSHOTs 2018-04-12 17:01:24 +02:00
Sam Brannen 02e09098e4 Expand scope of SpringFailOnTimeoutTests
Issue: SPR-16716
2018-04-12 11:00:45 +02:00
Igor Suhorukov 230c8f93e8 Throw exception from user code in SpringFailOnTimeout even if a timeout occurs
Issue: SPR-16717
2018-04-12 11:00:35 +02:00
Rossen Stoyanchev c4296fa785 Remove write pausing in Undertow response
Using the simple example shown in the ticket but switching from
Mono<String> to Flux<String> (and 5,000,000 onNext calls) shows that
constant pausing causes significant overhead and is not worth the
trouble vs ignoring the onWritePossible in REQUESTED state.

Issue: SPR-16702
2018-04-11 14:37:35 -04:00
Rossen Stoyanchev ab78854f1b Avoid inifinite recursion in UndertowServerHttpResponse
Undertow does not provide a way to check if we can write so with the
current implementation of isWritePossible, deep recursion can occur
when writing slows down. We now use a flag to keep track of write
ChannelListener callbacks.

This commit also addresses a related issue in
AbstractListenerWriteProcessor that went undected since #3c2d186
where after a large (single) buffer that is not written fully, the
completion signal is processed before the all data is written.

Issue: SPR-16702
2018-04-11 14:37:19 -04:00
Juergen Hoeller 96a465a749 Upgrade to Tomcat 8.5.30 2018-04-11 16:27:34 +02:00
Juergen Hoeller 861b9dc938 Proper exception for controller method return types that do not work with MvcUriComponentsBuilder (e.g. final classes)
Includes direct use of ControllerMethodInvocationInterceptor for return type Object, avoiding the attempt to generate an Object subclass.

Issue: SPR-16710

(cherry picked from commit f28a5d0)
2018-04-11 16:27:14 +02:00
sdeleuze eda2720471 Add default ctor to Reactive UrlBasedCorsConfigurationSource
Issue: SPR-16712
2018-04-11 14:41:06 +02:00
Juergen Hoeller 7fe28ce8b7 Upgrade to Netty 4.1.23 and TestNG 6.14.3 2018-04-11 13:29:37 +02:00
Juergen Hoeller de8c4179fb Polishing 2018-04-11 13:29:15 +02:00
Juergen Hoeller 433877e5cb AnnotationUtils.getAnnotation non-null check for synthesizeAnnotation
Issue: SPR-16708

(cherry picked from commit da80502)
2018-04-11 13:28:53 +02:00
Juergen Hoeller ffa4f03fd4 Unwind _TestTypes to top-level public test classes in AOP test suite
(cherry picked from commit cdaa247)
2018-04-11 13:28:39 +02:00
Juergen Hoeller 7068282e1f Remove bogus DataSource test from JpaTransactionManagerTests
(cherry picked from commit ff53d78)
2018-04-11 13:28:33 +02:00
sdeleuze 3879179927 Document why "charset=UTF-8" is specified for JSON
Issue: SPR-14715
2018-04-09 12:01:21 +02:00
KwonJH 007da2a58d Fix Java 9 link in the reference documentation 2018-04-09 11:13:25 +02:00
sdeleuze 1be585562f Improve Kotlin + bean validation documentation
Issue: SPR-16701
2018-04-09 10:18:06 +02:00
Rossen Stoyanchev 7a896d7d80 TestDispatcherServlet unwraps to find mock request
Issue: SPR-16695
2018-04-06 11:04:29 -04:00
sdeleuze be1aaa06e7 Cleanup settings.gradle pluginManagement configuration 2018-04-04 11:11:38 +02:00
sdeleuze 2fa060f0e9 Fix Dokka reference to Spring Framework's Javadoc
This commit specifies a local packageListUrl and defines that dokka task
must be executed after the api task in order to be able to build KDoc
during the release process when the Spring Framework's Javadoc is not
published yet.

Issue: SPR-16687
2018-04-04 11:11:17 +02:00
Stephane Nicoll 4d2d889142 Initiate 5.0.x branch 2018-04-03 23:07:03 +02:00
Spring Buildmaster 4b9bc50fd0 Release version 5.0.5.RELEASE 2018-04-03 20:11:16 +00:00
1144 changed files with 18816 additions and 13647 deletions
+2 -2
View File
@@ -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
+87 -79
View File
@@ -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.71" 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.28"
groovyVersion = "2.4.16"
hsqldbVersion = "2.4.1"
jackson2Version = "2.9.8"
jettyVersion = "9.4.14.v20181114"
junitJupiterVersion = "5.0.3"
junitPlatformVersion = "1.0.3"
junitVintageVersion = "4.12.3"
kotlinVersion = "1.2.71"
log4jVersion = "2.11.1"
nettyVersion = "4.1.32.Final"
reactorVersion = "Bismuth-SR15"
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.37"
undertowVersion = "1.4.26.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")
}
@@ -176,10 +188,12 @@ configure(allprojects) { project ->
"http://www.eclipse.org/aspectj/doc/released/aspectj5rt-api/",
"http://ehcache.org/apidocs/2.10.4",
"http://quartz-scheduler.org/api/2.2.1/",
"http://fasterxml.github.io/jackson-core/javadoc/2.8/",
"http://fasterxml.github.io/jackson-databind/javadoc/2.8/",
"http://fasterxml.github.io/jackson-dataformat-xml/javadoc/2.8/",
"http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/"
"http://fasterxml.github.io/jackson-core/javadoc/2.9/",
"http://fasterxml.github.io/jackson-databind/javadoc/2.9/",
"http://fasterxml.github.io/jackson-dataformat-xml/javadoc/2.9/",
"http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/",
"https://junit.org/junit4/javadoc/4.12/",
"https://junit.org/junit5/docs/${junitJupiterVersion}/api/"
] as String[]
}
@@ -209,7 +223,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 +233,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 +253,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 +260,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 +281,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.16.Final")
}
artifacts {
@@ -283,7 +292,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 +305,6 @@ configure(rootProject) {
"set GRADLE_OPTS=$gradleBatOpts %GRADLE_OPTS%\nset DEFAULT_JVM_OPTS=")
}
}
}
/*
@@ -310,7 +318,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
View File
@@ -1 +1 @@
version=5.0.5.BUILD-SNAPSHOT
version=5.0.12.RELEASE
+11 -5
View File
@@ -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"
}
+5
View File
@@ -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
View File
@@ -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"
}
+1 -1
View File
@@ -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)
@@ -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;
@@ -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
@@ -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;
}
@@ -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) {
@@ -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);
}
@@ -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));
}
}
@@ -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();
@@ -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
@@ -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);
@@ -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();
@@ -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();
}
@@ -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};
@@ -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
*/
@@ -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)) {
@@ -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();
@@ -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 {
@@ -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();
}
}
@@ -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 {
@@ -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));
@@ -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);
}
}
}
@@ -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 {}
}
@@ -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) {
}
}
@@ -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
}
}
}
@@ -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);
}
}
@@ -218,7 +218,7 @@ public class MethodInvocationProceedingJoinPointTests {
itb.unreliableFileOperation();
}
catch (IOException ex) {
// we don't realy care...
// we don't really care...
}
}
@@ -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) {
@@ -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())")
@@ -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();
@@ -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);
@@ -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());
}
@@ -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());
+2 -2
View File
@@ -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.2") // for JDK 9+ build compatibility
rt("org.aspectj:aspectjrt:1.9.2") // 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
@@ -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)
@@ -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)
@@ -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() {
+5 -7
View File
@@ -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);
}
@@ -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;
@@ -308,6 +314,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Class<?> getPropertyType() {
if (this.propertyType == null) {
try {
@@ -350,6 +357,9 @@ class ExtendedBeanInfo implements BeanInfo {
}
/**
* A simple {@link IndexedPropertyDescriptor}.
*/
static class SimpleIndexedPropertyDescriptor extends IndexedPropertyDescriptor {
@Nullable
@@ -379,8 +389,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;
@@ -415,6 +426,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Class<?> getPropertyType() {
if (this.propertyType == null) {
try {
@@ -450,6 +462,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Class<?> getIndexedPropertyType() {
if (this.indexedPropertyType == null) {
try {
@@ -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());
@@ -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 {
@@ -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);
}
@@ -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
@@ -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)
@@ -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;
@@ -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;
@@ -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.
@@ -244,7 +244,9 @@ public interface ListableBeanFactory extends BeanFactory {
/**
* Find all names of beans whose {@code Class} has the supplied {@link Annotation}
* type, without creating any bean instances yet.
* type, without creating corresponding bean instances yet.
* <p>Note that this method considers objects created by FactoryBeans, which means
* that FactoryBeans will get initialized in order to determine their object type.
* @param annotationType the type of annotation to look for
* @return the names of all matching beans
* @since 4.0
@@ -254,6 +256,8 @@ public interface ListableBeanFactory extends BeanFactory {
/**
* Find all beans whose {@code Class} has the supplied {@link Annotation} type,
* returning a Map of bean names with corresponding bean instances.
* <p>Note that this method considers objects created by FactoryBeans, which means
* that FactoryBeans will get initialized in order to determine their object type.
* @param annotationType the type of annotation to look for
* @return a Map with the matching beans, containing the bean names as
* keys and the corresponding bean instances as values
@@ -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.
@@ -46,24 +46,23 @@ public class AnnotationBeanWiringInfoResolver implements BeanWiringInfoResolver
}
/**
* Build the BeanWiringInfo for the given Configurable annotation.
* Build the {@link BeanWiringInfo} for the given {@link Configurable} annotation.
* @param beanInstance the bean instance
* @param annotation the Configurable annotation found on the bean class
* @return the resolved BeanWiringInfo
*/
protected BeanWiringInfo buildWiringInfo(Object beanInstance, Configurable annotation) {
if (!Autowire.NO.equals(annotation.autowire())) {
// Autowiring by name or by type
return new BeanWiringInfo(annotation.autowire().value(), annotation.dependencyCheck());
}
else if (!"".equals(annotation.value())) {
// Explicitly specified bean name for bean definition to take property values from
return new BeanWiringInfo(annotation.value(), false);
}
else {
if (!"".equals(annotation.value())) {
// explicitly specified bean name
return new BeanWiringInfo(annotation.value(), false);
}
else {
// default bean name
return new BeanWiringInfo(getDefaultBeanName(beanInstance), true);
}
// Default bean name for bean definition to take property values from
return new BeanWiringInfo(getDefaultBeanName(beanInstance), true);
}
}
@@ -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.
@@ -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 {
@@ -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)) {
@@ -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);
@@ -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) {
@@ -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;
}
@@ -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}.
@@ -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',
@@ -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();
@@ -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<>();
/**
@@ -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;
@@ -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
@@ -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);
}
@@ -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
*/
@@ -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;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,32 +28,26 @@ import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
import org.springframework.util.StringValueResolver;
/**
* {@link PlaceholderConfigurerSupport} subclass that resolves ${...} placeholders
* against {@link #setLocation local} {@link #setProperties properties} and/or system properties
* {@link PlaceholderConfigurerSupport} subclass that resolves ${...} placeholders against
* {@link #setLocation local} {@link #setProperties properties} and/or system properties
* and environment variables.
*
* <p>As of Spring 3.1, {@link org.springframework.context.support.PropertySourcesPlaceholderConfigurer
* PropertySourcesPlaceholderConfigurer} should be used preferentially over this implementation; it is
* more flexible through taking advantage of the {@link org.springframework.core.env.Environment Environment} and
* {@link org.springframework.core.env.PropertySource PropertySource} mechanisms also made available in Spring 3.1.
* more flexible through taking advantage of the {@link org.springframework.core.env.Environment} and
* {@link org.springframework.core.env.PropertySource} mechanisms also made available in Spring 3.1.
*
* <p>{@link PropertyPlaceholderConfigurer} is still appropriate for use when:
* <ul>
* <li>the {@code spring-context} module is not available (i.e., one is using Spring's
* {@code BeanFactory} API as opposed to {@code ApplicationContext}).
* <li>existing configuration makes use of the {@link #setSystemPropertiesMode(int) "systemPropertiesMode"} and/or
* {@link #setSystemPropertiesModeName(String) "systemPropertiesModeName"} properties. Users are encouraged to move
* away from using these settings, and rather configure property source search order through the container's
* {@code Environment}; however, exact preservation of functionality may be maintained by continuing to
* use {@code PropertyPlaceholderConfigurer}.
* <li>existing configuration makes use of the {@link #setSystemPropertiesMode(int) "systemPropertiesMode"}
* and/or {@link #setSystemPropertiesModeName(String) "systemPropertiesModeName"} properties.
* Users are encouraged to move away from using these settings, and rather configure property
* source search order through the container's {@code Environment}; however, exact preservation
* of functionality may be maintained by continuing to use {@code PropertyPlaceholderConfigurer}.
* </ul>
*
* <p>Prior to Spring 3.1, the {@code <context:property-placeholder/>} namespace element
* registered an instance of {@code PropertyPlaceholderConfigurer}. It will still do so if
* using the {@code spring-context-3.0.xsd} definition of the namespace. That is, you can preserve
* registration of {@code PropertyPlaceholderConfigurer} through the namespace, even if using Spring 3.1;
* simply do not update your {@code xsi:schemaLocation} and continue using the 3.0 XSD.
*
* @author Juergen Hoeller
* @author Chris Beams
* @since 02.10.2003
@@ -92,7 +86,6 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport
* Set the system property mode by the name of the corresponding constant,
* e.g. "SYSTEM_PROPERTIES_MODE_OVERRIDE".
* @param constantName name of the constant
* @throws java.lang.IllegalArgumentException if an invalid constant was specified
* @see #setSystemPropertiesMode
*/
public void setSystemPropertiesModeName(String constantName) throws IllegalArgumentException {
@@ -124,14 +117,9 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport
* against system environment variables. Note that it is generally recommended
* to pass external values in as JVM system properties: This can easily be
* achieved in a startup script, even for existing environment variables.
* <p><b>NOTE:</b> Access to environment variables does not work on the
* Sun VM 1.4, where the corresponding {@link System#getenv} support was
* disabled - before it eventually got re-enabled for the Sun VM 1.5.
* Please upgrade to 1.5 (or higher) if you intend to rely on the
* environment variable support.
* @see #setSystemPropertiesMode
* @see java.lang.System#getProperty(String)
* @see java.lang.System#getenv(String)
* @see System#getProperty(String)
* @see System#getenv(String)
*/
public void setSearchSystemEnvironment(boolean searchSystemEnvironment) {
this.searchSystemEnvironment = searchSystemEnvironment;
@@ -250,7 +238,7 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport
}
private class PropertyPlaceholderConfigurerResolver implements PlaceholderResolver {
private final class PropertyPlaceholderConfigurerResolver implements PlaceholderResolver {
private final Properties props;
@@ -261,7 +249,8 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport
@Override
@Nullable
public String resolvePlaceholder(String placeholderName) {
return PropertyPlaceholderConfigurer.this.resolvePlaceholder(placeholderName, props, systemPropertiesMode);
return PropertyPlaceholderConfigurer.this.resolvePlaceholder(placeholderName,
this.props, systemPropertiesMode);
}
}
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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)) {
@@ -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.
*
@@ -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<>();
/**
@@ -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();
}
/**
@@ -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.
@@ -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);
}
/**

Some files were not shown because too many files have changed in this diff Show More