Commit Graph

1530 Commits

Author SHA1 Message Date
Stephane Nicoll 9ba927215e Add support for ImportAware callback
This commit adds a way for a BeanFactoryPostProcessor to participate to
AOT optimizations by contributing code that replaces its runtime
behaviour.

ConfigurationClassPostProcessor does implement this new interface and
computes a mapping of the ImportAware configuration classes. The mapping
is generated for latter reuse by ImportAwareAotBeanPostProcessor.

Closes gh-2811
2022-03-09 11:17:21 +01:00
Stephane Nicoll ec6a19fc6b Add BeanFactoryContribution for bean registrations
This commits adds an implementation that takes care of contributing
code for each bean definition in the bean factory, invoking
BeanRegistrationContributionProvider to determine the best candidate to
use.

Closes gh-28088
2022-03-09 11:17:21 +01:00
Stephane Nicoll 5bc701d4fe Introduce BeanFactoryContribution
This commit introduces an infrastructure to contribute generated code
ahead of time to initialize a BeanFactory. Code and hints can be
contributed to a BeanFactorInitialization, with the ability to write to
other packages if necessary.

An implementation of that new interface that registers a BeanDefinition
is also included in this commit. It delegates to a
BeanInstantiationGenerator for geenerating the instance supplier that
creates the bean instance.

For corner cases, a BeanRegistrationContributionProvider can be
implemented. It allows to return a custom BeanFactoryContribution for
a particualr bean definition. This usually uses the default
implementation with a custom instance supplier.

Note that this commit adds an temporary executable resolution that is
meant to be replaced by the use of ConstructorResolver

See gh-28088
2022-03-09 11:17:21 +01:00
Stephane Nicoll cc57b55c61 Expose a way to resolved a merged inner bean definition
This commit extracts the logic of resolving a merged bean definition for
an inner bean to a public method so that other components can reuse it.

Closes gh-28093
2022-03-09 11:17:21 +01:00
Stephane Nicoll c541bde513 Simplify the generation of inner bean definitions
See gh-28047
2022-03-09 11:17:21 +01:00
Stephane Nicoll 97986b368a Harmonize use of generate
This commit harmonizes the use of the "generate" keyword for anything
related to code generation. Previously, there was a mix of "generate"
and "write."

See gh-28047
2022-03-09 11:17:21 +01:00
Stephane Nicoll ea19b92deb Clarify the scope of AotContributingBeanPostProcessor
This commit updates AotContributingBeanPostProcessor so that it
explicitly extends from PriorityOrdered. This makes it more apparent
that AOT contributing bean post processors are meant to be invoked
early with the regular runtime, and shouldn't be post-processed
themselves.

See gh-28047
2022-03-09 11:17:20 +01:00
Stephane Nicoll 20b17f02a2 Rename BeanInstantiationContributor to Contribution
This commit polishes the contribution model where an AOT contributing
bean post processor can return a contribution, rather than a
contributor. This makes it easier to return `null` if no contribution
can be produced now that it is named this way.

See gh-28047
2022-03-09 11:17:20 +01:00
Stephane Nicoll 572d017370 Add missing package-info
See gh-28047
2022-03-09 11:17:20 +01:00
Sam Brannen 66e9095ee9 Fix links and tests broken during merge
See gh-28083
2022-03-01 17:03:59 +01:00
Sam Brannen 466dd825ac Merge branch '5.3.x'
# Conflicts:
#	spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java
#	spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
#	spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java
#	spring-context/src/test/java/org/springframework/context/annotation/Spr3775InitDestroyLifecycleTests.java
2022-03-01 16:48:24 +01:00
Sam Brannen d67034f99b Document semantics for externally managed init/destroy methods
This commit introduces Javadoc to explain the difference between
init/destroy method names when such methods are private, namely that a
private method is registered via its qualified method name; whereas, a
non-private method is registered via its simple name.

See gh-28083
2022-03-01 16:18:46 +01:00
Sam Brannen f96872404d Ensure private init/destroy method is invoked only once
Closes gh-28083
2022-03-01 15:03:10 +01:00
Sam Brannen a7d5fbfbea Fix log messages for init/destroy method registration 2022-03-01 15:03:10 +01:00
Stephane Nicoll b4eb895927 Polish naming
Co-authored-by: Andy Wilkinson <wilkinsona@vmware.com>
2022-02-22 16:07:52 +01:00
Sam Brannen 6a73d2655f Polishing 2022-02-19 14:59:54 +01:00
Sam Brannen 8c6d59aaaf Polish contribution
See gh-28014
2022-02-19 14:43:26 +01:00
a.yazychyan c5c926726d Use enhanced switch expressions where feasible
Closes gh-28014
2022-02-19 14:34:05 +01:00
Phillip Webb 42d114534b Polish BeanDefinitionRegistrar 2022-02-18 17:13:07 +01:00
Juergen Hoeller 41ee23345d Support for registering multiple init/destroy methods on AbstractBeanDefinition
Closes gh-28013
2022-02-17 18:14:09 +01:00
Stephane Nicoll 2141373c43 Introduce AOT variant of BeanPostProcessor
This commit introduces an optional interface that a BeanPostProcessor
can implement to opt-in for providing a generated code equivalent of
what it does with a regular runtime.

This commit has a first implementation of this interface with
AutowiredAnnotationBeanPostProcessor replacing its processing of
autowired annotations by generated code.

Closes gh-27921
2022-02-15 13:27:07 +01:00
Stephane Nicoll 5bbc7dbce2 Polish ProtectedAccess options
This commit improves how protected access analysis operates. Rather than
providing a static boolean, a function callback for the member to
analyse is used. This permits to change the decision whether reflection
can be used, or if the return type is assigned.

Both of those are already applicable, with InjectionGenerator relying
on reflection for private fields, and DefaultBeanInstanceGenerator
assigning the bean instance if additional contributors are present.

This commit also moves the logic of computing the options where the code
is actually generated.

See gh-28030
2022-02-15 13:16:39 +01:00
Stephane Nicoll c5e1a774a5 Add bean instance generator infrastructure
This commit provides the necessary infrastructure to let components
contribute statements that are used to fully instantiate a bean
instance.

To ease code generation, a dedicated infrastructure to register bean
definition is provided in the o.s.beans.factory.generator package.
BeanDefinitionRegistrar offers a builder style API that provides a way
to hide how injected elements are resolved at runtime and let
contributors provide code that may throw a checked exception.

BeanInstanceContributor is the interface that components can implement
to contribute to a bean instance setup. DefaultBeanInstanceGenerator
generates, for a particular bean definition, the necessary statements
to instantiate a bean.

Closes gh-28047
2022-02-14 17:01:32 +01:00
Stephane Nicoll d64f8c1a05 Make BeanDefinitionValueResolver public
Closes gh-28029
2022-02-10 15:01:58 +01:00
Stephane Nicoll 7a2c9b80c2 Merge branch '5.3.x' 2022-02-10 13:15:39 +01:00
Stephane Nicoll d2c7dfb79e Add convenience factory method for Managed[List|Set|Map]
Closes gh-28026
2022-02-10 12:37:19 +01:00
Sam Brannen 669b05dc1d Allow AutowiredAnnotationBeanPostProcessor to compile on JDK 11 2022-02-08 14:06:27 +01:00
Juergen Hoeller 3eb9886724 Merge branch '5.3.x'
# Conflicts:
#	spring-context-support/src/main/java/org/springframework/scheduling/commonj/WorkManagerTaskExecutor.java
#	spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java
#	spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java
#	spring-tx/src/main/java/org/springframework/jca/work/SimpleTaskWorkManager.java
#	spring-tx/src/main/java/org/springframework/jca/work/WorkManagerTaskExecutor.java
2022-02-04 23:24:21 +01:00
Juergen Hoeller bc9cd9a687 Find interface method even for late-bound interface declaration in subclass
Closes gh-27995
2022-02-04 23:21:27 +01:00
Juergen Hoeller 6b1c2dc944 Consistently override (and prevent overriding for) aliases with bean definitions
Closes gh-27866
2022-02-04 21:12:42 +01:00
Juergen Hoeller 9688e61e20 Upgrade to Groovy 4.0
Closes gh-27985
2022-02-04 21:01:02 +01:00
Sam Brannen b3f786728e Use modern language features in tests 2022-02-03 15:35:32 +01:00
Sam Brannen 54565e95b5 Merge branch '5.3.x' 2022-02-03 14:58:36 +01:00
Sam Brannen f8a5a8d7be Use modern language features in tests 2022-02-03 14:50:10 +01:00
Sam Brannen f64cc08b62 Apply "instanceof pattern matching" in additional core classes 2022-01-26 13:49:50 +01:00
Sam Brannen a6deac3ffe Polish contribution
See gh-27945
2022-01-21 10:33:32 +01:00
Dave Syer f7c3706361 Port GroovyDynamicElementReader to Java
Prior to this commit, GroovyDynamicElementReader was implemented in
Groovy, which required that developers have Groovy language support
installed and configured in their IDEs.

This commit ports GroovyDynamicElementReader from Groovy to Java,
making the compilation much simpler and allowing developers to open the
project in Eclipse or VSCode (or other IDEs without Groovy support)
without compiler errors.

This commit also converts related tests from Groovy to Java.

Closes gh-27945
2022-01-20 17:42:17 +01:00
Sam Brannen d57bc176f2 Merge branch '5.3.x' 2022-01-10 14:21:25 +01:00
Sam Brannen df263d01b9 Use idiomatic AssertJ assertions for true, false, and null 2022-01-10 14:15:55 +01:00
Sam Brannen 2ed7268ded Remove deprecated AbstractBeanDefinitionReader.getBeanFactory() method
The getBeanFactory() method (which is deprecated since Spring Framework
5.3.15) has been obsolete for more than 13 years since it was superseded
by the getRegistry() method in the BeanDefinitionReader interface.

Closes gh-27875
2022-01-04 12:55:13 +01:00
Sam Brannen 7311620915 Merge branch '5.3.x' 2022-01-04 12:51:23 +01:00
Sam Brannen f04e9a8366 Deprecate getBeanFactory() method in AbstractBeanDefinitionReader
The getBeanFactory() method has been obsolete for more than 13 years
since it was superseded by the getRegistry() method in the
BeanDefinitionReader interface.

Closes gh-27875
2022-01-04 12:45:11 +01:00
Sam Brannen c1606c5a5e Polishing 2022-01-04 12:39:28 +01:00
Marten Deinum 941b6af9ac Use Collection factory methods when applicable
This commit replaces the use of Collections.unmodifiableList/Set/Map
with the corresponding 'of(...)' factory methods introduced in Java 9.

Closes gh-27824
2022-01-04 12:01:13 +01:00
Stephane Nicoll f1fe16e3cd Polish "Reuse ResolvableType in getDependencyType"
See gh-24525
2021-12-21 11:17:53 +01:00
陈其苗 b69ab8d568 Reuse ResolvableType in getDependencyType
See gh-24525
2021-12-21 11:17:31 +01:00
dramatist efaccd6356 Apply "instanceof pattern matching" in spring-beans 2021-12-15 13:14:42 +01:00
Juergen Hoeller bfdb93b406 Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	src/docs/asciidoc/integration.adoc
2021-12-14 16:51:00 +01:00
Juergen Hoeller ca84559588 Provide findAnnotationOnBean variant with allowFactoryBeanInit flag
Closes gh-27796
2021-12-14 16:47:12 +01:00
izeye 49c4d310b5 Polish
See gh-27799
2021-12-13 14:53:54 +01:00
Arjen Poutsma 81af7330f6 Deprecate StringUtils::trimWhitespace and variants
This commits deprecates
- StringUtils::trimWhitespace in favor of String::strip
- StringUtils::trimLeadingWhitespace in favor of String::stripLeading
- StringUtils::trimTrailingWhitespace in favor of String::stripTrailing

Closes gh-27769
2021-12-06 13:37:16 +01:00
Juergen Hoeller 7f43128a0e Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	spring-web/src/main/java/org/springframework/web/server/MediaTypeNotSupportedStatusException.java
#	spring-web/src/main/java/org/springframework/web/util/ContentCachingRequestWrapper.java
#	spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java
2021-12-03 22:42:05 +01:00
Juergen Hoeller 14f24f43d7 Polishing 2021-12-03 22:36:31 +01:00
Juergen Hoeller d7e0eed8d2 Clarify getBeanProvider(ResolvableType) semantics for unresolved generics
Closes gh-27727
2021-12-03 22:33:50 +01:00
김보배(Bobae Kim)/Platform Engineering팀/11ST 804b343cab Use parseInt without substring method 2021-11-25 16:14:59 +01:00
Juergen Hoeller 4750a9430c Early removal of 5.x-deprecated code
Closes gh-27686
2021-11-18 09:18:06 +01:00
Christoph Dreis 5c972fcc54 Use Charset variants of URLEncoder and URLDecoder methods 2021-11-10 16:12:11 +01:00
Juergen Hoeller 2fba0bc272 Allow BeanUtils#instantiateClass inlining with native
Closes gh-27072
2021-11-10 15:20:56 +01:00
Juergen Hoeller 0e1ba7aae5 Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	spring-context/src/main/java/org/springframework/context/annotation/Lazy.java
2021-11-09 22:39:58 +01:00
Juergen Hoeller b167e1a93f Remove unnecessary final declarations (for consistency) 2021-11-09 22:35:24 +01:00
최유진(Yujin Choi)/Platform Engineering팀/11ST 8dd385b440 Use toUnmodifiableSet and toList instead of collectingAndThen
Since Spring Framework 6 uses JDK 17 for its baseline, we can make use
of toList() and toUnmodifiableSet() which were introduced in JDK 16 and
JDK 10, respectively.

Closes gh-27618
2021-10-28 16:37:41 +02:00
Sam Brannen e9fc35495e Merge branch '5.3.x' 2021-10-22 14:36:43 +02:00
Сергей Цыпанов e5475d698a Iterate over Map's entrySet() instead of keySet() in PropertyEditorRegistrySupport
Closes gh-27591
2021-10-22 14:15:33 +02:00
Sam Brannen 401c0d220a Apply "instanceof pattern matching" Eclipse clean-up in spring-beans
This commit also applies additional clean-up tasks such as the following.

- final fields
- diamond operator (<>) for anonymous inner classes
- Comparator.comparing

This has only been applied to `src/main/java`.
2021-10-14 16:50:19 +02:00
Juergen Hoeller da457abd5b Merge branch '5.3.x' 2021-10-12 15:19:40 +02:00
Juergen Hoeller eda3ca5fbc Remove unnecessary final declarations at method level 2021-10-12 15:17:44 +02:00
Sam Brannen 2d1e0d5e38 Merge branch '5.3.x' 2021-10-06 12:13:21 +02:00
Sam Brannen 41ae9632d1 Upgrade to Checkstyle 9.0 and spring-javaformat 0.0.29
This commit upgrades the Gradle build to use Checkstyle 9.0 and
spring-javaformat 0.0.29 (which internally uses Checkstyle 8.45.1).

Closes gh-27520
2021-10-06 12:11:19 +02:00
Sam Brannen 381b7d035a Merge branch '5.3.x' 2021-10-05 14:55:22 +02:00
Sam Brannen 48a507a993 Clean up warnings 2021-10-05 14:35:32 +02:00
Juergen Hoeller e314a79fb0 Merge branch '5.3.x'
# Conflicts:
#	spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java
2021-10-01 13:29:46 +02:00
Juergen Hoeller f632165dec Invoke bean-derived (Auto)Closeable.close() method directly
Closes gh-27504
2021-10-01 13:26:25 +02:00
Sam Brannen 030ba52805 Merge branch '5.3.x' 2021-09-29 16:56:33 +02:00
Sam Brannen 96e4d3a530 Fail Gradle build for Javadoc warnings
In order to catch Javadoc errors in the build, we now enable the
`Xwerror` flag for the `javadoc` tool. In addition, we now use
`Xdoclint:syntax` instead of `Xdoclint:none` in order to validate
syntax within our Javadoc.

This commit fixes all resulting Javadoc errors and warnings.

This commit also upgrades to Undertow 2.2.12.Final and fixes the
artifact names for exclusions for the Servlet and annotations APIs.

The incorrect exclusion of the Servlet API resulted in the Servlet API
being on the classpath twice for the javadoc task, which resulted in the
following warnings in previous builds.

javadoc: warning - Multiple sources of package comments found for package "javax.servlet"
javadoc: warning - Multiple sources of package comments found for package "javax.servlet.http"
javadoc: warning - Multiple sources of package comments found for package "javax.servlet.descriptor"
javadoc: warning - Multiple sources of package comments found for package "javax.servlet.annotation"

Closes gh-27480
2021-09-29 14:02:37 +02:00
Juergen Hoeller 3ad796e913 Keep getEffectiveAnnotatedParameter for user code compiled with javac 8 2021-09-29 09:56:29 +02:00
Juergen Hoeller f32f04d841 Code cleanup on new baseline 2021-09-28 19:02:44 +02:00
Sam Brannen 3dc84c2d92 Merge branch '5.3.x' 2021-09-28 11:48:50 +02:00
Sam Brannen bfdc99ab79 Fix Javadoc errors
See gh-27480
2021-09-28 11:44:12 +02:00
Sam Brannen 16bf39ea1b Merge branch '5.3.x' 2021-09-28 10:35:18 +02:00
Sam Brannen 2567b20949 Upgrade to spring-javaformat 0.0.28 and downgrade to Checkstyle 8.41
In order to be able to use text blocks and other new Java language
features, we are upgrading to a recent version of Checkstyle.

The latest version of spring-javaformat-checkstyle (0.0.28) is built
against Checkstyle 8.32 which does not include support for language
features such as text blocks. Support for text blocks was added in
Checkstyle 8.36.

In addition, there is a binary compatibility issue between
spring-javaformat-checkstyle 0.0.28 and Checkstyle 8.42. Thus we cannot
use Checkstyle 8.42 or higher.

In this commit, we therefore upgrade to spring-javaformat-checkstyle
0.0.28 and downgrade to Checkstyle 8.41.

This change is being applied to `5.3.x` as well as `main` in order to
benefit from the enhanced checking provided in more recent versions of
Checkstyle.

Closes gh-27481
2021-09-28 10:29:31 +02:00
Juergen Hoeller b3f6d60dc9 Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java
#	spring-core/src/test/java/org/springframework/core/ReactiveAdapterRegistryTests.java
#	src/docs/asciidoc/web-reactive.adoc
2021-09-27 17:26:26 +02:00
Juergen Hoeller 211f0bbf88 Fix invalid characters in source files
Closes gh-27475
2021-09-27 16:57:54 +02:00
Juergen Hoeller 9ff0d717f2 Restore lenient fallback in case of several non-public constructors
See gh-27437
2021-09-27 16:52:11 +02:00
Juergen Hoeller 0241c5ebb3 Merge branch '5.3.x'
# Conflicts:
#	spring-core/spring-core.gradle
2021-09-23 15:59:32 +02:00
Juergen Hoeller 58898de542 Provide accessors for externallyManagedConfigMembers and Init/DestroyMethods
Closes gh-27449
2021-09-23 15:54:40 +02:00
Juergen Hoeller f9d63e7bb1 BeanUtils.getResolvableConstructor falls back to single non-public constructor
Closes gh-27437
2021-09-23 15:53:54 +02:00
Juergen Hoeller 774583dfa7 Retain support for legacy PostConstruct/PreDestroy/Inject variants
Also removes JAX-WS support from CommonAnnotationBeanPostProcessor.

Closes gh-27444
See gh-27422
2021-09-21 17:07:42 +02:00
Sam Brannen 070d087dbc Reinstate -Werror for Groovy compilation
This commit partially reverts cf2429b0f0
in order to reinstate -Werror for Groovy compilation in spring-beans.

The `decorating` field in GroovyDynamicElementReader has been changed
from boolean to Boolean in order to avoid the JDK 17 deprecation warning
for use of `new Boolean(false)` which the Groovy compiler apparently
uses behind the scenes when compiling Groovy source code.
2021-09-21 11:30:30 +02:00
Juergen Hoeller d84ca2ba90 Jakarta EE 9 migration
Upgrades many dependency declarations; removes old EJB 2.x support and outdated Servlet-based integrations (Commons FileUpload, FreeMarker JSP support, Tiles).

Closes gh-22093
Closes gh-25354
Closes gh-26185
Closes gh-27423
See gh-27424
2021-09-17 09:14:07 +02:00
Juergen Hoeller cf2429b0f0 Remove support for deprecated Java SecurityManager (-> JDK 17 build compatibility)
Includes hard JDK 9+ API dependency in CGLIB ReflectUtils (Lookup.defineClass) and removal of OutputStream spy proxy usage (avoiding invalid Mockito proxy on JDK 17)

Closes gh-26901
2021-09-15 15:30:25 +02:00
Sam Brannen f07e6a1b9d Support char primitive default values in BeanUtils.instantiateClass()
Closes gh-27390
2021-09-14 16:12:21 +02:00
Sam Brannen 5cc09849ce Introduce test for gh-27390 2021-09-14 16:05:41 +02:00
takeaction21 92cd680a2c Support float and double primitive default values in BeanUtils.instantiateClass()
See gh-27390
2021-09-14 16:05:41 +02:00
Juergen Hoeller 6c17e9375b Reduce log statement for non-unique JavaBean property to debug level
Closes gh-27372
2021-09-13 18:13:41 +02:00
Brian Clozel cecc0849a8 Upgrade to Gradle 7.2
This commit upgrades Gradle to 7.2.
Gradle configuration names are updated accordingly.
This also upgrades Gradle build plugins.

See gh-26870
2021-09-13 09:37:35 +02:00
Juergen Hoeller b2eaa7c1c3 Polishing 2021-09-02 22:59:33 +02:00
Juergen Hoeller b6c2c11805 Polishing 2021-09-02 22:21:27 +02:00
Sam Brannen 6177f00a63 Polish PropertyAccessor tests 2021-08-18 17:10:40 +02:00
Juergen Hoeller 44951873f9 Introduce accessors for allowCircularReferences/allowRawInjectionDespiteWrapping
Closes gh-27289
2021-08-17 17:19:21 +02:00
Stephane Nicoll 31b651a114 Polish contribution
See gh-27248
2021-08-08 11:33:26 +02:00
Syuziko eaf9deedfd Polish tests
See gh-27248
2021-08-07 18:53:47 +02:00
Stephane Nicoll a90ed957be Support ResolvableType in BeanDefinitionBuilder
Closes gh-27160
2021-07-12 14:07:25 +02:00
Johnny Lim 925edf28fc Add Javadoc since to BeanDefinitionBuilder.setSynthetic()
See gh-27155
2021-07-12 08:22:09 +02:00
diguage 564c6f7f86 improve the performance of iteration 2021-07-09 15:10:18 +02:00
Juergen Hoeller 8680fdb8bc Polishing 2021-07-09 13:26:46 +02:00
Juergen Hoeller 74f91339e2 BeanCreationException message includes declaring class of constructor/factory method
Closes gh-27139
2021-07-09 13:22:50 +02:00
Stephane Nicoll fed1a426b6 Improve BeanDefinitionBuilder to handle the synthetic flag
Closes gh-27141
2021-07-07 16:13:19 +02:00
Stephane Nicoll cf78895ba0 Polish 2021-07-07 16:11:48 +02:00
Sam Brannen a2ef6badc4 Use StringBuilder.append(char) where possible
To slightly improve performance, this commit switches to
StringBuilder.append(char) instead of StringBuilder.append(String)
whenever we append a single character to a StringBuilder.

Closes gh-27098
2021-06-25 10:44:28 +02:00
Juergen Hoeller 4bb88f3b1d Remove logging dependency in BeanUtils
Closes gh-27070
2021-06-22 15:26:48 +02:00
Sam Brannen 29fa9c1728 Polish contribution
See gh-27034
2021-06-08 17:52:07 +02:00
Beca-se 39660710f6 Cross-ref additional *Aware APIs in BeanFactory Javadoc
Closes gh-27034
2021-06-08 17:47:47 +02:00
Sam Brannen f0f450a18d Polishing 2021-06-07 13:24:46 +02:00
Juergen Hoeller b3dcb64ff1 Generic bean type resolution for lookup methods
Closes gh-26998
2021-05-28 17:23:52 +02:00
Sam Brannen ffbc537835 Polish ConcurrentBeanWrapperTests 2021-05-23 18:50:50 +02:00
Elvys Soares 9295bcc4a4
Refactor ConcurrentBeanWrapperTests to use @RepeatedTest
Closes gh-26968
2021-05-23 18:40:36 +02:00
Florian Kirmaier b5d6e53e50 Avoid memory leak when PropertyComparator is reused
This commit fixes a potential memory leak, since PropertyComparator
previously kept an indirect reference to the value it last compared.

Closes gh-26869
2021-04-30 15:08:32 +02:00
Sam Brannen 5d297c6387 Polishing 2021-04-16 11:44:48 +02:00
Juergen Hoeller e05b584623 Ignore testWindowsAbsoluteFilePath exception if not on Windows
See gh-26702
2021-04-12 23:46:27 +02:00
Juergen Hoeller 4b6b12bf2f Bypass root path resolution for "file:" prefix only
Closes gh-26702
2021-04-12 22:40:53 +02:00
Brian Clozel a8d553218c Introduce Gradle Toolchain support in build
Prior to this commit, the Spring Framework build would rely on
setting a custom Java HOME for building all sources and tests
with that JDK.

This approach is not flexible enough, since we would be testing
the source compatibility against a recent JDK, but not a common
case experienced by the community: compiling and running
application code with a recent JDK and the official, JDK8-based
Framework artifacts.
This method is also limiting our choice of JDKs to the ones
currently supported by Gradle itself.

This commit introduces the support of Gradle JVM Toolchains in
the Spring Framework build.

We can now select a specific JDK for compiling the main
SourceSets (Java, Groovy and Kotlin) and another one for
compiling and running the test SourceSets:

`./gradlew check -PmainToolChain=8 -PtestToolchain=15`

Gradle will automatically find the JDKs present on the host or
download one automcatically. You can find out about the ones
installed on your host using:

`./gradlew -q javaToolchains`

Finally, this commit also refactors the CI infrastructure to:

* only have a single CI image (with all the supported JDKs)
* use this new feature to compile with JDK8 but test it
against JDK11 and JDK15.

Closes gh-25787
2021-03-15 14:33:41 +01:00
drgnchan bc261fd995
Remove duplicate word in Javadoc
Closes gh-26676
2021-03-15 11:47:17 +01:00
Juergen Hoeller 530fb0808d Polishing 2021-03-08 23:45:56 +01:00
Juergen Hoeller b5147a034c Polishing
See gh-26574
See gh-26575
2021-02-25 18:08:04 +01:00
Craig Andrews ebf6fff312 Fix handling of file: paths to non-existent files
For setAsText, if the text argument is a file: URL for a path that does not exist, Paths.get(text) is called where text is a file: URL, which doesn't work - the result is an InvalidPathException.

To fix this issue, also check that the resource isn't a file before calling Paths.get(). That way, resources that are files skip to the other branch.
2021-02-25 17:55:55 +01:00
Sam Brannen 8baf404893 Polish contribution
See gh-26600
2021-02-25 11:41:11 +01:00
nullzl a33eac3ec0 Correctly set auto-growing array's element
Prior to this commit, the implementation of processKeyedProperty() in
AbstractNestablePropertyAccessor resulted in a
`java.lang.IllegalArgumentException: array element type mismatch` when
the property expression had more than one property key and the last key
should cause the array to grow automatically.

For example, given a property `int[][] multiArray` and property
expression `multiArray[1][3]`, the `processKeyedProperty()` method
created a new array object and assigned it to `multiArray`; whereas,
the new array object should have be assigned to `multiArray[1]`.

This commit fixes this issue.

Closes gh-26600
2021-02-25 11:25:54 +01:00
Sam Brannen a78c12b8d3 Fix Javadoc for PlaceholderConfigurerSupport 2021-02-22 17:02:01 +01:00
Sébastien Deleuze 3524401bf1 Introduce a NativeDetector utility class
With the introduction of the -H:+InlineBeforeAnalysis native image
compiler flag in GraalVM 21.0.0, it is now possible to use an utility method and get code
removal at build time.

This flag will be enabled as of Spring Native 0.9.0.

closes gh-25795
2021-02-15 16:36:23 +01:00
Juergen Hoeller df977a2fd2 Nullability refinements and related polishing 2021-02-14 17:57:32 +01:00
Juergen Hoeller 99a1388bbd Re-resolve cached arguments in case of NoSuchBeanDefinitionException
Closes gh-26517
2021-02-14 17:57:22 +01:00
Juergen Hoeller 809813dd52 Preserve resolved destroy method name in RootBeanDefinition
Closes gh-26498
2021-02-14 17:57:05 +01:00
Juergen Hoeller d5e5dcb7e1 Consider non-initialized holders as equal to empty holders
Closes gh-26433
2021-02-14 17:56:52 +01:00
Juergen Hoeller defc2466b0 Fail early FactoryBean instantiation for LinkageError
Closes gh-26425
2021-02-14 17:56:38 +01:00
Sam Brannen 667256adf9 Ignore generics when Proxy is supplied to BeanUtils.copyProperties()
gh-24281 introduced support to honor generic type information in
BeanUtils.copyProperties(), but that introduced a regression.
Specifically, if the supplied source or target object lacked generic
type information for the return type of the read-method or the
parameter type of the write-method for a given property, respectively,
the two properties would be considered a mismatch and ignored. This can
occur if the source or target object is a java.lang.reflect.Proxy since
the dynamically generated class for the proxy loses the generic type
information from interfaces that the proxy implements.

This commit fixes this regression by ignoring generic type information
if either the source or target property is lacking generic type
information.

Closes gh-26531
2021-02-11 18:18:57 +01:00
Brian Clozel 58e9b187fe Enforce standard Java types in YamlProcessor
`spring-beans` ships a `YamlProcessor` that's used as a base class by
`YamlMapFactoryBean` and `YamlPropertiesFactoryBean`. These
implementations have a clear use case: mapping application-internal Yaml
documents for configuration or infrastructure purposes.

Since this use case rarely requires extended types support from the
underlying library, and since we're offering ways to list custom types
(since #25152), we'll restrict to java standard types only by default.
This simplifies the setup and focuses the abstract class on the core
use cases.

Closes gh-26530
2021-02-09 15:05:53 +01:00
heqiang bd8e682c51
Simplify BeanUtils.findPrimaryConstructor()
Closes gh-26519
2021-02-08 13:45:40 +01:00
Sam Brannen 872255a591 Fix ConcurrentBeanFactoryBenchmark 2021-01-12 10:59:57 +01:00
Juergen Hoeller 00b56c026a Consistent handling of NullBean instances in resolveNamedBean
Closes gh-26271
2020-12-16 22:27:41 +01:00
Juergen Hoeller 2a47751fcd Defensively handle loadClass null result in BeanUtils.findEditorByConvention
Closes gh-26252
2020-12-10 16:24:32 +01:00
Juergen Hoeller 622d0831a3 Polishing 2020-11-27 21:46:45 +01:00
Juergen Hoeller 56dbe06d9b Register @Bean definitions as dependent on containing configuration class
Closes gh-26167
2020-11-27 17:00:16 +01:00
Sam Brannen bd4e915abf Assert same instance returned for cached merged BeanDefinition 2020-11-12 14:57:05 +01:00
fengyuanwei 6eec1acdac Make tests meaningful in DefaultListableBeanFactoryTests 2020-11-12 13:50:30 +01:00
izeye bc32d513d9 Polish Javadoc for InjectionMetadata.forElements() 2020-11-12 13:50:00 +01:00
Сергей Цыпанов e1f51b4bf8 Avoid multiple volatile reads/writes in a row where only one is enough 2020-11-05 12:25:24 +01:00
Juergen Hoeller 6d67bdf04f Polishing 2020-11-04 23:43:43 +01:00
Juergen Hoeller 97c8628bd6 Suppress NotWritablePropertyException in case of ignoreUnknown=true
Closes gh-25986
2020-11-04 23:42:37 +01:00
Juergen Hoeller 412aa06d86 Reliably refresh metadata for dynamically changing prototype bean class
Closes gh-26019
2020-11-04 16:48:54 +01:00
hzmpay f781c459b4 Simplify AbstractBeanFactory.registerCustomEditors()
This commit avoids an unnecessary non-null check in
registerCustomEditors().

Closes gh-26022
2020-11-03 14:52:23 +01:00
Sam Brannen 705cf09ad7 Merge branch '5.2.x' 2020-10-26 15:05:35 +01:00
Sam Brannen 449377908f Fix JUnit 4 to AssertJ migration bugs
The migration from JUnit 4 assertions to AssertJ assertions resulted in
several unnecessary casts from int to long that actually cause
assertions to pass when they should otherwise fail.

This commit fixes all such bugs for the pattern `.isNotEqualTo((long)`.
2020-10-26 14:53:09 +01:00
Sam Brannen c524849774 Deleted unused field in DefaultListableBeanFactoryTests 2020-10-23 17:06:26 +02:00
Juergen Hoeller 621295dbd8 Deprecate StringUtils.isEmpty(Object) and replace remaining usage
Closes gh-25945
2020-10-21 16:09:26 +02:00
Juergen Hoeller 702a05e926 Merge branch '5.2.x' 2020-10-16 15:33:37 +02:00
Juergen Hoeller d77ecb26a9 Fail on warnings with compileGroovy (since it compiles Java code as well) 2020-10-16 15:18:48 +02:00
Сергей Цыпанов 8a04910bdd Drop explicit zeroing at instantiation of Atomic* objects 2020-10-06 15:45:12 +02:00
Brian Clozel 61d893257e Rewrite "performance" test to JMH benchmarks
This commit rewrites the remaining "fastEnough" performance tests into
proper JMH benchmarks.

See gh-24830
2020-09-25 13:43:38 +02:00
Juergen Hoeller 6c631e3d5c Merge branch '5.2.x'
# Conflicts:
#	spring-messaging/src/main/java/org/springframework/messaging/converter/MappingJackson2MessageConverter.java
2020-09-25 11:36:18 +02:00
Juergen Hoeller 21cb9e8bff Translate NullBean result to null for lookup method with bean name
Closes gh-25806
2020-09-25 11:24:50 +02:00
Juergen Hoeller d5fed34642 Merge branch '5.2.x' 2020-09-15 10:09:18 +02:00
Juergen Hoeller f010368a66 Polishing 2020-09-15 10:08:01 +02:00
Juergen Hoeller e20bff9c64 Consistent data class constructor resolution with clear error message
MVC data class processor constructs target instance even in case of binding failure, as long as the corresponding method parameter is not marked as optional.

Closes gh-24372
2020-09-01 19:10:32 +02:00
Juergen Hoeller d62202f464 Polishing 2020-09-01 10:27:36 +02:00
tristeza 61311248bf change assert in replaceOverride constructor from methodName to methodReplacerBeanName 2020-09-01 10:10:08 +02:00
Juergen Hoeller 8f369ffed5 Merge branch '5.2.x'
# Conflicts:
#	build.gradle
2020-08-31 18:07:04 +02:00
Juergen Hoeller d8c420ab75 Avoid full singleton lock for getSingleton(beanName, false)
Closes gh-25667
2020-08-31 18:00:51 +02:00
Сергей Цыпанов 1f3e52d932 gh-25650 Replace remaining usage of LinkedList with ArrayList in tests 2020-08-31 14:33:14 +02:00
Juergen Hoeller c4f4fbc003 Polishing 2020-08-28 20:14:24 +02:00
Juergen Hoeller bb9e79daa7 Polishing 2020-08-28 19:58:56 +02:00
Juergen Hoeller d37eaa5941 Introduce DataClassRowMapper with record-style constructor binding support
Closes gh-24695
2020-08-28 18:52:35 +02:00
Juergen Hoeller d4192b9d35 Expose record-style accessor methods for instance fields as bean properties
Closes gh-24391
2020-08-28 18:51:27 +02:00
Juergen Hoeller 0f2cc53be7 Merge branch '5.2.x'
# Conflicts:
#	build.gradle
2020-08-27 17:32:20 +02:00
Juergen Hoeller 71e70aed14 Polishing 2020-08-27 17:13:33 +02:00
Juergen Hoeller 2080878d82 Merge branch '5.2.x'
# Conflicts:
#	spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java
2020-08-27 14:40:54 +02:00
Juergen Hoeller a8b295c516 Consistent javadoc for ParseState and its entry classes 2020-08-27 14:37:42 +02:00
Juergen Hoeller cf2e0c7959 Selected use of ArrayList instead of LinkedList in common places
See gh-25652
2020-08-27 14:14:44 +02:00
Juergen Hoeller 589060d10f Avoid LinkedList performance issues through use of ArrayDeque
Closes gh-25652
2020-08-27 14:14:08 +02:00
Juergen Hoeller 874574513c Replace remaining usage of LinkedList with ArrayList/ArrayDeque
Closes gh-25650
2020-08-26 18:32:08 +02:00
Juergen Hoeller ff11467a0c Avoid resizing of fixed-size HashMap/LinkedHashMap variants
Closes gh-25349
2020-08-25 19:26:18 +02:00
Juergen Hoeller 5d96a2dc9e Defensive null handling for exception message
See gh-24878
2020-08-25 16:26:23 +02:00
Juergen Hoeller 7324140d20 Merge branch '5.2.x' 2020-08-25 16:21:00 +02:00
Juergen Hoeller 04df9b8f49 Efficient checks for empty strings and single character matches
Closes gh-25552
Closes gh-25553
2020-08-25 16:17:12 +02:00
Marten Deinum 74a014743a Call StartupStep.end in finally block
Prior to this commit it was possible that a StartupStep was
started but never ended. This was the case when an exception
occured during bean initializing. To always call the method
regardless of the outcome, the call to StartupStep.end has
been moved to a finally block.

When an exception occurs the StartupStep is also enriched with
the exception class and message for diagnostic purposes.

See gh-22776
Closes gh-25572
2020-08-24 09:48:54 +02:00
Sam Brannen c558391e2c Declare interfaces as @FunctionalInterface where feasible
This commit declares each of the following public interfaces as a
@FunctionalInterface.

- org.springframework.context.ApplicationContextInitializer
- org.springframework.test.web.servlet.DispatcherServletCustomizer
- org.springframework.validation.MessageCodeFormatter
- org.springframework.util.IdGenerator
- org.springframework.beans.factory.config.YamlProcessor.MatchCallback
- org.springframework.beans.factory.config.YamlProcessor.DocumentMatcher

Closes gh-25580
2020-08-11 17:01:03 +02:00
Juergen Hoeller 7b6e1c957f Merge branch '5.2.x' 2020-08-10 14:44:22 +02:00
Juergen Hoeller 7d56c303a4 Use getType with allowFactoryBeanInit=false during advisor retrieval
Closes gh-25546
2020-08-10 14:43:02 +02:00
Juergen Hoeller a6af1def57 Polishing 2020-08-07 13:31:21 +02:00
Juergen Hoeller f4c0ceb1cc Merge branch '5.2.x'
# Conflicts:
#	build.gradle
#	spring-tx/src/main/java/org/springframework/dao/support/PersistenceExceptionTranslationInterceptor.java
#	spring-web/src/main/java/org/springframework/web/bind/support/WebRequestDataBinder.java
#	spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java
#	spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java
2020-08-07 13:15:36 +02:00
Juergen Hoeller 692c5f292d Polishing 2020-08-07 13:11:48 +02:00
Juergen Hoeller 8dd285f877 Polishing 2020-08-07 13:02:43 +02:00
Juergen Hoeller b345019415 Introduce getBeanProvider variants with allowEagerInit flag
Closes gh-25559
2020-08-07 12:07:13 +02:00
Sam Brannen dded51fa80 Merge branch '5.2.x' 2020-08-05 17:47:44 +02:00
Sam Brannen 96da1ff9ea Support @RestControllerAdvice in Standalone MockMvc again
Since Spring Framework 5.2, @RestControllerAdvice registered with
MockMvc when using MockMvcBuilders.standaloneSetup() has no longer been
properly supported if annotation attributes were declared in the
@RestControllerAdvice annotation. Prior to 5.2, this was not an issue.

The cause for this regression is two-fold.

1. Commit 50c257794f refactored
   DefaultListableBeanFactory so that findAnnotationOnBean() supports
   merged annotations; however, that commit did not refactor
   StaticListableBeanFactory#findAnnotationOnBean() to support merged
   annotations.

2. Commit 978adbdae7 refactored
   ControllerAdviceBean so that a merged @ControllerAdvice annotation
   is only looked up via ApplicationContext#findAnnotationOnBean().

The latter relies on the fact that findAnnotationOnBean() supports
merged annotations (e.g., @RestControllerAdvice as a merged instance of
@ControllerAdvice). Behind the scenes, MockMvcBuilders.standaloneSetup()
creates a StubWebApplicationContext which internally uses a
StubBeanFactory which extends StaticListableBeanFactory. Consequently,
since the implementation of findAnnotationOnBean() in
StaticListableBeanFactory was not updated to support merged annotations
like it was in DefaultListableBeanFactory, we only see this regression
with the standalone MockMvc support and not with MockMvc support for an
existing WebApplicationContext or with standard Spring applications
using an ApplicationContext that uses DefaultListableBeanFactory.

This commit fixes this regression by supporting merged annotations in
StaticListableBeanFactory#findAnnotationOnBean() as well.

Closes gh-25520
2020-08-05 17:40:16 +02:00
Sam Brannen 3dc4f43852 Merge branch '5.2.x' 2020-08-04 15:13:35 +02:00
Sam Brannen 7a31885ae5 Fix bug in StaticListableBeanFactory.isSingleton()
Prior to this commit, StaticListableBeanFactory.isSingleton() returned
false for singleton beans unless they were created by a FactoryBean.

StaticListableBeanFactory.isSingleton() now properly returns true for
all beans not created by a FactoryBean.

Closes gh-25522
2020-08-04 15:13:10 +02:00
Brian Clozel be801fc5fc Polish
See gh-24878
2020-07-28 14:48:25 +02:00
Juergen Hoeller adce6593af Move metrics package to org.springframework.core
See gh-24878
2020-07-28 11:28:10 +02:00
Brian Clozel 9301d7a294 Add application startup metrics support
This commit adds a new `StartupStep` interface and its factory
`ApplicationStartup`. Such steps are created, tagged with metadata and
thir execution time can be recorded - in order to collect metrics about
the application startup.

The default implementation is a "no-op" variant and has no side-effect.
Other implementations can record and collect events in a dedicated
metrics system or profiling tools. We provide here an implementation for
recording and storing steps with Java Flight Recorder.

This commit also instruments the Spring application context to gather
metrics about various phases of the application context, such as:

* context refresh phase
* bean definition registry post-processing
* bean factory post-processing
* beans instantiation and post-processing

Third part libraries involved in the Spring application context can
reuse the same infrastructure to record similar metrics.

Closes gh-24878
2020-07-27 22:37:14 +02:00
Juergen Hoeller 718d46adac Check for alias overriding bean definition of same name
Closes gh-25430
2020-07-22 18:42:53 +02:00