Commit Graph

1788 Commits

Author SHA1 Message Date
Juergen Hoeller 6027be5a39 Ignore overridden factory methods for unique candidate resolution
See gh-27920
2022-10-06 15:06:53 +02:00
Stephane Nicoll 0d5c78d992 Polish 2022-10-06 13:33:58 +02:00
Juergen Hoeller b45a48461f Polishing 2022-10-06 12:03:25 +02:00
Juergen Hoeller aedef9321a Merge AOT constructor and factory method resolution into ConstructorResolver
This moves related code into the same class, unifies candidate determination for constructors and factory methods, and gets rid of the package cycle around the hard-coded Autowired annotation check (which is implicitly coming from AutowiredAnnotationBeanPostProcessor via the determineCandidateConstructors SPI now). The API entry point for AOT pre-resolution purposes is in RegisteredBean.

Closes gh-27920
2022-10-06 11:59:11 +02:00
Stephane Nicoll 2f20d6322b Enable cglib proxy for configuration classes if necessary
This commit updates code generation to customize the instantiation of
a configuration class that requires a proxy. Rather than instantiating
the raw class, the proxy is used.

Closes gh-29107
2022-10-04 16:54:44 +02:00
Stephane Nicoll 9820e3341d Fix handling of protected visibility
Previously, InstanceSupplierCodeGenerator used reflection if the target
visibility is either protected or private, and use direct access if the
target visibility is public or package private.

The previous arrangement already assumed that the code is generateed in
the same package as the target type. This means that protected can be
used as well so this commit only use reflection if the target visibility
is private.

Closes gh-29253
2022-10-04 16:49:13 +02:00
Stephane Nicoll 3b2b36d0b8 Allow AccessControl to determine visibility from a given type
This commit adapts AccessVisibility so that it can determine if the
member or type signature is accessible from a given package. This lets
implementers figure out if reflection is necessary without assuming that
package private visibility is OK.

Closes gh-29245
2022-10-03 17:56:19 +02:00
Brian Clozel 054579a892 Temporarily revert gh-29246
This new hint contribution triggers a GraalVM bug and breaks native
compilation for several samples, we need to temporarily revert this
change until a fix is available in GraalVM.

See gh-29246
2022-10-03 14:14:57 +02:00
Brian Clozel ff9792bae0 Polish
See gh-29246
2022-10-03 14:14:01 +02:00
Brian Clozel 332961f833 Contribute introspection hints on registered beans
As a follow up of #29205, we now need to contribute an "introspection on
declared method" reflection hint for all registered beans.

Closes gh-29246
2022-10-03 11:31:24 +02:00
Stephane Nicoll 0b5c3ec267 Polish javadoc 2022-10-03 10:05:27 +02:00
Sam Brannen f6d1806e30 Ensure DefaultListableBeanFactoryTests compiles in Eclipse IDE 2022-09-28 15:44:45 +02:00
Stephane Nicoll 38d91bafce Generate matching structure for configuration classes
This commit improves GeneratedClass to support inner classes, allowing
them to be registered by name with a type customizer, as
GeneratedClasses does for top level classes.

BeanDefinitionMethodGenerator leverages this feature to create a
matching structure for configuration classes that contain inner classes.

Closes gh-29213
2022-09-28 11:13:52 +02:00
Stephane Nicoll e6aef11b09 Allow target to be a ClassName rather than an existing Class
See gh-29207
2022-09-27 10:33:14 +02:00
Stephane Nicoll 8ef850ff91 Update ClassNameGenerator to work with a ClassName target
This commit updates ClassNameGenerator so that it uses a ClassName for
its default target. This makes sure that a target that has been
generated can be used.

See gh-29027
2022-09-27 10:33:13 +02:00
Adam Ostrožlík 0ccb64fe10 Replace Collectors.toList with Stream.toList
Closes gh-29203
2022-09-26 18:32:01 +02:00
Sam Brannen a975b9d5da Suppress "unused" warnings in tests 2022-09-26 14:27:32 +02:00
Sébastien Deleuze 9a180d1811 Add JMH benchmarks
Closes gh-24104
2022-09-26 10:23:06 +02:00
Sébastien Deleuze 8e73b57329 Refine Kotlin changes
This refinement ensures the constructor is properly
accessible, avoid duplicating current logic and
provide a slightly faster implementation of the
Kotlin codepath.

See gh-24104
2022-09-26 10:22:46 +02:00
stsypanov edcc559b4a Add fast-path in BeanUtils#instantiateClass
For no-args constructor.

See gh-24104
2022-09-26 10:21:28 +02:00
Stephane Nicoll c19cedede1 Revisit BeanRegistrationCodeFragments
This commit revisit BeanRegistrationCodeFragments to separate the
responsibility between the default implementation and the delegates. It
also reviews how customization are applied by improving the Javadoc and
the method name.

Closes gh-28865
2022-09-22 15:32:28 +02:00
Stephane Nicoll 84fd942712 Add support for Charset for property value code generation
Closes gh-29186
2022-09-21 19:27:05 +02:00
Stephane Nicoll 4625e92eb8 Break dependency between TestCompiler and AOT
This commit improves `TestCompiler` with a `with` function that allows
to customize a test compiler instance. Rather than `TestCompiler`
knowing about `TestGenerationContext`, the latter implements the
function so that it can be passed as is.

See gh-29175
2022-09-20 15:07:51 +02:00
Phillip Webb df9990f66b Relocate MockSpringFactoriesLoader
Closes gh-29176
2022-09-19 22:29:40 -07:00
Phillip Webb 52bffbff76 Move `TestCompiler` and related classes to `core.test.tools` package
Closes gh-29175
2022-09-19 22:29:40 -07:00
Phillip Webb cc7552ec61 Rename @CompileWithTargetClassAccess
Rename `@CompileWithTargetClassAccess` to
`@CompileWithForkedClassLoaderClassLoader`.

Closes gh-29173
2022-09-19 22:29:40 -07:00
Juergen Hoeller 50d34366bc Polishing 2022-09-14 12:55:53 +02:00
Stephane Nicoll 6cfbf391ec Merge branch '5.3.x' 2022-09-13 08:42:56 +02:00
Stephane Nicoll 0d2bfc926f Apply consistent ordering in hierarchical contexts
Previously, if `@Order` is specified on a `@Bean` method, and the
candidate bean is defined in a parent context, its order wasn't taken
into account when retrieving the bean from a child context.

This commit makes sure the metadata of a bean is taken into
consideration in all cases.

Closes gh-29105
2022-09-13 07:23:22 +02:00
Stephane Nicoll 58a2b79699 Harmonize hint registration
Previously, a shortcut method for the default ExecutableMode was
provided, but we found out that the shortcut makes it harder to
determine the intent.

This commit harmonizes hints registration for types, methods, and
fields. An ExecutableMode is now mandatory to register a method or
constructor. Previous methods that infer a mode or provided a
customizer of the builder are deprecated.

Closes gh-29135
2022-09-12 14:51:04 +02:00
Stephane Nicoll 042a4f3518 Polish "Adapt FieldHint to recent GraalVM versions"
See gh-29130
2022-09-12 14:50:28 +02:00
Stephane Nicoll 2b45fd4388 Allow bean factory initialization to have a more flexible signature
This commit allows bean factory initialization to use a more flexible
signature than just consuming the DefaultListableBeanFactory. The
environment and the resource loader can now be specified if necessary.

See gh-29005
2022-09-12 10:07:35 +02:00
Stephane Nicoll ae706f3954 Allow MethodReference to define a more flexible signature
This commit moves MethodReference to an interface with a default
implementation that relies on a MethodSpec. Such an arrangement avoid
the need of specifying attributes of the method such as whether it is
static or not.

The resolution of the invocation block now takes an
ArgumentCodeGenerator rather than the raw arguments. Doing so gives
the opportunity to create more flexible signatures.

See gh-29005
2022-09-12 10:07:31 +02:00
Stephane Nicoll 8a4a89b9d9 Allow a MethodReference to be produced from a GeneratedMethod
This commit updates GeneratedMethod and its underlying infrastructure
to be able to produce a MethodReference. This simplifies the need when
such a reference needs to be created manually and reuses more of what
MethodReference has to offer.

See gh-29005
2022-09-12 10:07:13 +02:00
Stephane Nicoll 6f5344ab5c Polish 2022-09-09 11:40:09 +02:00
Stephane Nicoll 2d4f308cc1 Provide more context when the code of a value cannot be generated
Closes gh-29118
2022-09-09 11:40:09 +02:00
Sébastien Deleuze 9cfe79186d Stop using RuntimeHintsUtils
Due to gh-29053, we can stop using RuntimeHintsUtils to
register SynthesizedAnnotation proxies.

Closes gh-29059
2022-09-07 10:10:07 +02:00
Sébastien Deleuze b8c1fc9202 Revert "Remove RuntimeHintsUtils"
This reverts commit 3e327f5641.
2022-09-06 18:21:34 +02:00
Sébastien Deleuze 3e327f5641 Remove RuntimeHintsUtils
Due to gh-29053, we can stop using RuntimeHintsUtils to
register SynthesizedAnnotation proxies.

Closes gh-29058
Closes gh-29059
2022-09-06 15:31:02 +02:00
Stephane Nicoll 903078a5b2 Do not silently return null when no constructor candidate is found
This commit updates ConstructorOrFactoryMethodResolver to throw an
exception if no constructor or factory method can be found for a given
bean definition.

This prevents code generation to happen on an incomplete view of the
bean to instantiate.

Closes gh-29052
2022-09-06 15:26:39 +02:00
Stephane Nicoll 6e93f1187c Move TestCompiler from generator to generate
This commit harmonizes the package space by moving the TestCompiler
infrastructure from the now outdated "generator" package to "generate".

Closes gh-29082
2022-09-05 16:30:19 +02:00
Stephane Nicoll 58b0251af1 Relocate TestGenerationContext to spring-core-test
This commit moves the test implementation for GenerationContext in
spring-core-test. This also removes the copy we had in testfixtures

See gh-28877
2022-09-05 16:21:17 +02:00
Brian Clozel 7ace1f9dc5 Align RuntimeHintsPredicates with new FieldMode
Closes gh-29063
2022-09-02 18:16:43 +02:00
Brian Clozel 4368e2563f Reinstate RuntimeHintsAgent tests
Closes gh-29062
2022-09-02 18:16:43 +02:00
Sam Brannen 69f23095b8 Deprecate SynthesizedAnnotation and related methods
Since Spring no longer adds the SynthesizedAnnotation interface to the
JDK dynamic proxy used to synthesize an annotation, this commit
officially deprecates SynthesizedAnnotation and related methods in
RuntimeHintsUtils.

See gh-29041, gh-29054
Closes gh-29053
2022-09-02 12:04:17 +02:00
Phillip Webb 505da5c602 Migrate hint registration to shortcuts
Migrate code to make use of the `MemberCategory` and `FieldMode`
shortcuts.

See gh-29011
2022-09-01 17:26:06 -07:00
Phillip Webb da1005cd66 Add FieldMode for field hints and ensure that it cannot be downgraded
Add a `FieldMode` enum analogous to `ExecutableHint` and update
`FieldHint` to ensure that registration cannot downgrade `WRITE`
to `READ`.

Fixes gh-29055
2022-09-01 17:25:43 -07:00
Johnny Lim 706c1ec8dd Polish 2022-08-31 23:59:51 +09:00
Sam Brannen 98c74059e0 Polish Javadoc 2022-08-31 16:35:13 +02:00
Sam Brannen 593bd064e1 Polishing 2022-08-25 13:23:04 +02:00
Stephane Nicoll 5aa8583159 Add shortcut to register an executable with a mode
See gh-29011
2022-08-24 19:32:02 +02:00
Stephane Nicoll c164b918c0 Apply consistent RuntimeHints defaults
This commit harmonizes the registration of an executable so that
the default method and the method that takes an empty customizer
produces the same hint. The same applies to the readable flag of
a field hint.

Rather than returning a list of executable modes, the "highest" mode
is retained.

See gh-29011
2022-08-24 19:32:01 +02:00
Stephane Nicoll c6bcf79c0e Add hint for use of Qualifier in meta-annotations
Closes gh-29000
2022-08-23 14:31:09 +02:00
Stephane Nicoll 455715899d Infer proxy on `@Lazy`-annotated injection points
This commit makes use of the new `getLazyResolutionProxyClass` on
`AutowireCandidateResolver` to detect if a injection point requires
a proxy.

Closes gh-28980
2022-08-22 20:48:02 +02:00
Stephane Nicoll 40de029bf8 Polish 2022-08-22 16:32:53 +02:00
Juergen Hoeller 4eb84a0537 Introduce getLazyResolutionProxyClass mechanism in AutowireCandidateResolver SPI
See gh-28980
2022-08-22 16:24:37 +02:00
Juergen Hoeller 427e5f5899 Final merged bean definition clearing in freezeConfiguration
Instead of individual last-minute clearing in markBeanAsCreated, the factory clears all merged bean definitions in freezeConfiguration, retaining the changes of merged bean definition post-processing after that point (in particular in refreshForAotProcessing).

Closes gh-28948
2022-08-19 17:30:59 +02:00
Stephane Nicoll 4f0c879778 Rationalize hints required for annotations
This commit updates RuntimeHintsUtils to focus on registering a JDK
proxy only as annotations of annotated elements that have at least
an introspection hints are visible out-of-the-box.

This commit also removes unnecessary hints and adapt `@Reflective` to
detect if a hint is required using the introduced
MergedAnnotation#isSynthesizable.

See gh-28967
2022-08-16 15:42:52 +02:00
Juergen Hoeller 38c9e7f629 Polishing 2022-08-10 23:30:27 +02:00
Juergen Hoeller b31a15851e Support for pre-generated CGLIB proxy classes (in AOT scenarios)
Includes runtime storing of generated classes to a directory specified by the "cglib.generatedClasses" system property. Avoids lazy CGLIB fast-class generation and replaces generated Enhancer and MethodWrapper key classes with equivalent record types. Introduces support for early type determination in InstantiationStrategy, AopProxy and SmartInstantiationAwareBeanPostProcessor - in order to trigger CGLIB class generation in refreshForAotProcessing (through early determineBeanType calls for bean definitions).

Closes gh-28115
2022-08-10 23:30:19 +02:00
Stephane Nicoll 0a9db7cc47 Revert "Make sure inferred destroy method is set on the original bean definition"
This reverts commit 2e1538a20b.
2022-08-09 11:31:56 +02:00
Stephane Nicoll 2e1538a20b Make sure inferred destroy method is set on the original bean definition
This commit updates InitDestroyAnnotationBeanPostProcessor to mutate
the original bean definition rather than the merged one that can be
recreated without it if the cache gets stale.

See gh-28215
2022-08-08 14:33:00 +02:00
Stephane Nicoll 3c76437868 Update RegisteredBean to take a ConfigurableListableBeanFactory
This allows to have access to `getBeanDefinition` if the original
bean definition needs to be retrieved.

See gh-28936
2022-08-08 14:00:49 +02:00
Stephane Nicoll 832889d801 Polish 2022-08-08 11:31:38 +02:00
Stephane Nicoll dcad3beeb9 Polish 2022-08-03 11:03:28 +02:00
Stephane Nicoll c9faff7491 Apply property hints to FactoryBean if necessary
This commit handles a BeanDefinition that configures the FactoryBean
as the "beanClass", while exposing the actual type in "resolvedType".
While unusual, this is required in certain cases when the factory
bean exposes generic information itself.

Previously, the hints for properties injection were applied on the
user type.

Closes gh-28913
2022-08-03 10:58:41 +02:00
Stephane Nicoll e79a8f6733 Polish 2022-08-03 10:53:57 +02:00
Sam Brannen ad99add429 Polish AOT support 2022-07-30 10:51:14 +03:00
Stephane Nicoll 8e7faab4f6 Polish 2022-07-28 16:37:08 +02:00
Phillip Webb 24fafc2fb7 Document that AOT processors are initialized during AOT processing
Closes gh-28866
2022-07-28 14:30:26 +01:00
Phillip Webb 9413383d72 Enforce BeanRegistrationExcludeFilter beans are also AOT processors
Update `BeanDefinitionMethodGeneratorFactory` to enforce that any
`BeanRegistrationExcludeFilter` filter that is from a bean factory
also implements an AOT processor interface.

See gh-28866
2022-07-28 14:29:28 +01:00
Phillip Webb a4f3d1d6e8 Track the sources used to load AOT services
Update `AotServices` so that it tracks which source was used to
provide a given instance.

See gh-28866
2022-07-28 14:28:37 +01:00
Phillip Webb 5218cf4c16 Fix BeanFactoryInitializationAotProcessor javadoc
Update javadoc since BeanRegistrationExcludeFilter is not longer an
exclude signal

See gh-28833
2022-07-28 14:25:56 +01:00
Phillip Webb e928943d1a Don't use BeanRegistrationExcludeFilter as an exclude signal
Closes gh-28833
2022-07-27 19:26:11 +01:00
Phillip Webb 472c23455a Add AotServices class to replace AotFactoriesLoader
Add an `AotServices` class to replace `AotFactoriesLoader`. The
replacement class allow instances to be loaded from just the
`aot.factories` file if required. It also retains a link to the bean
names so that a `findByBeanName(...)` method can be provided.

See gh-28833
2022-07-27 19:25:28 +01:00
Stephane Nicoll 88e29689b6 Polish 2022-07-27 15:10:09 +02:00
Stephane Nicoll f0f7f72de9 Do not write BeanDefinition attributes by default
This commit flips the default strategy for BeanDefinition attributes so
that they are not generated in AOT-optimized contexts.

Closes gh-28516
2022-07-27 15:01:50 +02:00
Stephane Nicoll 735051bf7d Resolve infer destroy method at build-time
This commit allows a RootBeanDefinition to resolve its infer destroy
method if necessary. Contrary to BeanInstanceAdapter that uses the
actual bean instance, the new method works against the type exposed
in the bean definition.

The AOT contribution of InitDestroyAnnotationBeanPostProcessor uses
the new method to make sure the special '(inferred)' placeholder is
handled prior to code generation.

Closes gh-28215
2022-07-27 11:48:13 +02:00
Stephane Nicoll 3d5003ad63 Introduce TestGenerationContext
This commit polishes DefaultGenerationContext to make the method
that flushes generated classes more explicit. It now throws an
IOException and TestGenerationContext has been updated to handle
that to ease its use in code that can't throw such an exception.

As this use case is likely to happen outside the Spring Framework,
this commit adds such a convenience to spring-test as well.

Closes gh-28877
2022-07-26 17:56:17 +02:00
Stephane Nicoll 60d2d16b2b Polish 2022-07-26 15:18:35 +02:00
Stephane Nicoll c1738aab0d Improve target detection for FactoryBeans with generic
Closes gh-28809
2022-07-22 13:10:44 +02:00
Stephane Nicoll bbcc269487 Polish 2022-07-22 12:09:16 +02:00
Stephane Nicoll c09eb633db Rename test fixture to avoid class with existing TestBean class 2022-07-22 12:03:00 +02:00
Stephane Nicoll ba5ab1ad9d Polish 2022-07-22 09:36:45 +02:00
Phillip Webb cfb61d2a17 Add generics to BeanInstanceSupplier
Update `BeanInstanceSupplier` to support a generic type.

See gh-28748
2022-07-21 13:29:15 +01:00
Phillip Webb 069d6d3280 Propagate getFactoryMethod() when using InstanceSupplier.andThen()
Update `InstanceSupplier.andThen` to propagate the result of
`getFactoryMethod()`.

See gh-28748
2022-07-20 18:56:57 +01:00
Phillip Webb 3ae1b9ba57 Polish CodeBlock joining logic
Consistently use `CodeBlock.joining(", ")` when generating code.
2022-07-20 10:25:45 +01:00
Stephane Nicoll 85173b5de3 Polish "Handle inferred init/destroy method consistently"
See gh-28843
2022-07-20 10:45:51 +02:00
Olga Maciaszek-Sharma 68e28a5f59 Handle inferred init/destroy method consistently
See gh-28843
2022-07-20 10:40:51 +02:00
Stephane Nicoll d6345db7c9 Use target of the FactoryBean only if the FactoryBean is public
This commit polishes 85d4a79 so that the target type of factory bean
is only considered if the FactoryBean is accessible. If the FactoryBean
requires protected access, we still generate the code in the package of
the FactoryBean.

Those two commits combined are actually providing a fix for the use
case described in gh-28809.

Closes gh-28809
2022-07-19 21:02:24 +02:00
Stephane Nicoll 978cdfff46 Formatting 2022-07-19 17:57:28 +02:00
Stephane Nicoll 1acb41ff43 Add AOT support for by-type RuntimeBeanReference
Closes gh-28841
2022-07-19 17:57:12 +02:00
Stephane Nicoll 85d4a79cdc Improve location of generated bean definitions of FactoryBeans
This commit improves the location of generated bean definitions for
FactoryBean implementations by checking the type that the factory
bean generates, rather than the factory bean implementation itself.

Closes gh-28812
2022-07-19 15:17:31 +02:00
Phillip Webb 578f155809 Polishing 2022-07-18 15:01:51 +01:00
Phillip Webb 87b83e8291 Make MethodName package-private
Closes gh-28832
2022-07-18 11:20:43 +01:00
Phillip Webb 0ea4ee163c Polishing 2022-07-18 10:54:30 +01:00
Stephane Nicoll 75ab47b57c Link factoryMethod consistently in AOT-generated bean definitions
Closes gh-28748
2022-07-18 10:06:48 +01:00
Phillip Webb f2d31b7a20 Migrate AOT tests to use GeneratedClasses and refine/polish AOT APIs
Migrate all AOT tests to make use of `GeneratedClasses` rather than
directly generating Java files. This commit also refines and polishes
AOT APIs to being greater consistency.

Specifically:

	- The `MethodGenerator` interface has been removed in favor of
	  working directly with `GeneratedMethods`.
	- The visibility of several constructors and methods has been
	  reduced to package-private.
	- The `using(...)` and `builder` methods have been removed in
	  favor of setting the `Consumer` callbacks directly as
	  constructor arguments.
	- Variable names for builders are now named `type` or `method`
	  depending on what they're building.

Closes gh-28831
2022-07-18 08:40:59 +01:00
Sam Brannen 1f3ea5133f Polishing 2022-07-15 15:28:47 +02:00
Sam Brannen 0fb9de5d0e Merge branch '5.3.x' 2022-07-13 16:36:01 +02:00
Marc Wrobel bd3499671c Fix typos in test code
This commit fixes typos in test class names, test method names, and
test variable names.

Closes gh-28807
2022-07-13 16:24:11 +02:00
Sam Brannen 8242897c81 Merge branch '5.3.x' 2022-07-13 16:13:49 +02:00
Sam Brannen 2e4d7e4ef9 Polishing 2022-07-13 16:13:09 +02:00
Marc Wrobel c112bb0ae1 Fix and improve Javadoc in spring-beans
See gh-28803
2022-07-13 16:12:51 +02:00
Stephane Nicoll 2c92d7da8f Harmonize RuntimeHintsRegistrar implementations
Closes gh-28801
2022-07-12 18:30:23 +02:00
Stephane Nicoll 54a3f66d1d Move RuntimeHints predicate support to a dedicated package
This commit moves `RuntimeHintsPredicate` and its support classes that
form a cohesive concept in a dedicated `.predicate` package.

Closes gh-28799
2022-07-12 16:16:12 +02:00
Sam Brannen 2af08cf163 Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/test/java/org/springframework/core/annotation/TypeMappedAnnotationTests.java
#	spring-test/src/test/java/org/springframework/test/context/junit4/TimedSpringRunnerTests.java
#	spring-test/src/test/java/org/springframework/test/util/MetaAnnotationUtilsTests.java
#	spring-test/src/test/java/org/springframework/test/util/OverriddenMetaAnnotationAttributesTests.java
2022-07-09 16:24:04 +02:00
Sam Brannen d274e893a6 Remove superfluous static declaration for enum, annotation, & interface 2022-07-09 16:16:13 +02:00
Sam Brannen 338609a168 Merge branch '5.3.x' 2022-07-04 19:31:47 +02:00
Sam Brannen 2c3243c93c Trim string input in PropertyEditors where whitespace is irrelevant
Closes gh-28755
2022-07-04 19:24:58 +02:00
Juergen Hoeller d2e27ad754 Support by-type constructor references via RuntimeBeanReference
Closes gh-28728
2022-06-29 17:02:33 +02:00
Juergen Hoeller a21b27e6d9 Use isAssignableValue instead of isInstanceOf for argument resolution
Includes related nullability refinements.

Closes gh-28727
2022-06-29 17:01:04 +02:00
Stephane Nicoll 6199835d6e Harmonize generated class name conventions
This commit moves the responsibility of naming classes to the
GenerationContext. This was already largely the case before, except that
the concept of a "mainTarget" and "featureNamePrefix" was specific
to bean factory initialization contributors.

ClassNameGenerator should now be instantiated with a default target
and an optional feature name prefix. As a result, it does no longer
generate class names in the "__" package.

GeneratedClasses can now provide a new, unique, GeneratedClass or
offer a container for retrieving the same GeneratedClass based on an
identifier. This lets all contributors use this facility rather than
creating JavaFile manually. This also means that ClassNameGenerator
is no longer exposed.

Because the naming conventions are now part of the GenerationContext, it
is required to be able to retrieve a specialized version of it if a
code generation round needs to use different naming conventions. A new
withName method has been added to that effect.

Closes gh-28585
2022-06-23 16:05:23 +02:00
Stephane Nicoll 0f4205adbf Polish assertions 2022-06-21 08:03:26 +02:00
Sam Brannen 789329fa3b Revise signature of SpringFactoriesLoader.forResourceLocation(...)
When an overloaded method accepts additional "optional" arguments, we
typically declare the optional arguments after the required arguments.
For example, see the constructors for ClassPathResource.

This commit therefore revises the signature of the overloaded
forResourceLocation() method so that the optional ClassLoader argument
follows the required `String resourceLocation` argument.
2022-06-20 17:39:01 +02:00
Stephane Nicoll 4cb9e65353 Polish 2022-06-20 14:56:28 +02:00
Stephane Nicoll 90759fb38f Relocate duplicated mock implementations to test fixtures
Closes gh-28659
2022-06-20 08:55:52 +02:00
Stephane Nicoll 365481379d Fix hint generation for Autowired fields
Close gh-28655
2022-06-19 11:18:54 +02:00
Sam Brannen 360767bb50 Merge branch '5.3.x'
# Conflicts:
#	spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java
2022-06-14 17:11:27 +02:00
Sam Brannen eeac150030 Polish contribution
See gh-28616
2022-06-14 16:42:51 +02:00
Fabian Gonzalez 0ce9516aef Avoid eager instantiation of non-singleton FactoryBean in getBeanNamesForType
Closes gh-28616
2022-06-14 16:42:31 +02:00
Sam Brannen e47cc44947 Polish DefaultListableBeanFactoryTests 2022-06-14 16:38:11 +02:00
Juergen Hoeller a14650e0dc findAnnotationOnBean only falls back to bean class in case of no factory method
Most importantly, static @Bean methods do not expose their @Configuration class-level annotations anymore, aligned with the behavior for non-static @Bean methods.

Closes gh-28298
2022-06-14 14:01:38 +02:00
Juergen Hoeller 4e1b9f1492 Replace deep exception message nesting with custom inclusion of cause messages
Includes deprecation of NestedServletException, whereas NestedCheckedException and NestedRuntimeException remain as base classes with several convenience methods.

Closes gh-25162
2022-06-14 14:00:28 +02:00
Brian Clozel 7e8b1ed401 Polish
Move hints registration to spring-beans, where the actual behavior is
implemented. We chose not to move this to
`AutowiredAnnotationBeanPostProcessor` for now, as this would require it
to implement another AOT-related interface and add too much noise for
this.

See gh-28614
2022-06-14 10:08:06 +02:00
Brian Clozel 9c9b2356ce Add RuntimeHints predicates generator
The `RuntimeHints` API allows to describe hints for the reflection,
proxies and resources behavior at runtime. The need for a particular
behavior can be covered by several types of hints, at different levels.
This knowledge can be important in several cases:

* before contributing additional hints, infrastructure can check if an
  existing hint already covers the behavior
* this can be used in test suites and test infrastructure

This commit adds a new RuntimeHintsPredicates that generates `Predicate`
instances for testing `RuntimeHints` against a desired runtime behavior
for reflection, resources or proxies.

Closes gh-28555
2022-06-10 18:55:14 +02:00
Phillip Webb 46a2f2d71c Allow @CompileWithTargetClassAccess to work with all classes
Switch from `MethodHandles.privateLookupIn` to a reflection based
approach to that target classes to not need to be explicitly listed.

Closes gh-28580
2022-06-07 14:12:15 -07:00
Phillip Webb c01a2e897d Fix null assignment to non-nullable field
Update `BeanRegistrationCodeFragments` package-private constructor
to set `codeFragments` to `this` rather than `null`. The field
is never actually read by `DefaultBeanRegistrationCodeFragments` since
all methods are overridden.

Closes gh-28578
2022-06-07 10:09:08 -07:00
Stephane Nicoll 92961d75f0 Polish tests 2022-06-07 12:03:50 +02:00
Stephane Nicoll ad0573a91e Polish 2022-06-07 11:52:40 +02:00
Phillip Webb 305055d6b1 Pass GenerationContext to customizeBeanRegistrationCodeFragments
Update `customizeBeanRegistrationCodeFragments` so that it can access
the `GenerationContext`.

See gh-28557
2022-06-05 18:59:02 -07:00
Phillip Webb 9a9c3ea00e Filter single inferred init/destroy methods
Update `BeanDefinitionPropertiesCodeGenerator` to not add
init/destroy method calls for a single inferred name.

Closes gh-28570
2022-06-05 16:14:40 -07:00
Phillip Webb 172102d225 Refine ApplicationContextAotGenerator class name generation
Refine the class name logic so that the name is passed in rather
than using `ApplicationContext.getId()`. Also propagate the name
so that the generated classes use it.

See gh-28565
2022-06-04 12:26:00 -07:00
Phillip Webb 4bd33cb6e0 Allow ApplicationContextAotGenerator to generated better class names
Update `ApplicationContextAotGenerator` so that it can generate class
names based on a `target` class and using the ID of the application
context. Prior to this commit, the generated class name was always
`__.BeanFactoryRegistrations`.

Closes gh-28565
2022-06-03 18:15:37 -07:00
Stephane Nicoll 3aefa88d3c Add test to validate AOT infrastructure registration
See gh-28561
2022-06-03 14:30:36 +02:00
Phillip Webb 8d79ec0b67 Allow AOT contributions to customize code fragments.
Update the `BeanRegistrationAotContribution` interface to allow
it to customize `BeanRegistrationCodeFragments`. This change
allows us to drop the `BeanRegistrationCodeFragmentsCustomizer`
interface since an `BeanRegistrationAotProcessor` can now be
used instead.

Closes gh-28557
2022-06-02 18:07:47 -07:00
Sam Brannen bc3b3d01ee Polishing 2022-06-01 14:57:16 +02:00
Sam Brannen ee209de9cf Merge branch '5.3.x'
# Conflicts:
#	spring-beans/src/test/java/org/springframework/beans/factory/support/security/CallbacksSecurityTests.java
#	spring-context/src/test/java/org/springframework/ejb/access/LocalSlsbInvokerInterceptorTests.java
#	spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteSlsbInvokerInterceptorTests.java
#	spring-web/src/test/java/org/springframework/remoting/jaxws/JaxWsSupportTests.java
#	spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolutionIntegrationTests.java
2022-05-31 14:15:36 +02:00
Sam Brannen 1beb7068f6 Use new AssertJ exception assertions 2022-05-31 14:08:28 +02:00
Sam Brannen 720261db26 Use List.of() and Set.of() where feasible 2022-05-30 18:42:48 +02:00
Sam Brannen ad46f0295c Apply "instanceof pattern matching" 2022-05-30 18:41:25 +02:00
Phillip Webb 6f71328ba6 Don't implicitly filter all AOT processor beans
Update `BeanDefinitionMethodGeneratorFactory` to not implicitly filter
AOT processor beans if they also implement
`BeanRegistrationExcludeFilter`.

Most AOT processor beans generate code that replaces themselves, so
implicitly filtering them is the right thing to do. However, some beans
may need to perform AOT processing and still get registered when the
AOT processed application runs. These beans can now additionally
implement `BeanRegistrationExcludeFilter` to signal that they should
not be implicitly filtered.

Closes gh-28526
2022-05-26 20:59:50 -07:00
Phillip Webb efa8ffb728 Polish 2022-05-26 20:56:06 -07:00
Sam Brannen 65066bd1e1 Fix Java 17 compiler warning about varargs 2022-05-17 15:44:55 +02:00
Sam Brannen 70415b1781 Merge branch '5.3.x' 2022-05-17 15:41:08 +02:00
Sam Brannen a1c3efbb5f Polish ManagedList[Tests] and ManagedSet[Tests] 2022-05-17 15:36:31 +02:00
Sam Brannen fe7c6f075b Polishing 2022-05-16 10:53:35 +02:00
Juergen Hoeller fc8e6705d6 Move AutowiredArguments support classes to beans.factory.aot
This reduces the package cycle between aot and annotation to an Autowired annotation reference in ConstructorOrFactoryMethodResolver, to be resolved along with gh-27920.

See gh-28414
2022-05-12 13:15:08 +02:00
izeye 6c8de96992 Add Javadoc since tag for RootBeanDefinition(ResolvableType) constructor
This commit also removes unnecessary super() invocations.

See gh-28418
Closes gh-28449
2022-05-11 16:42:28 +02:00
Juergen Hoeller 8b6dcb9ccc Merge branch '5.3.x' 2022-05-11 08:52:05 +02:00
Juergen Hoeller 83186b689f Refine CachedIntrospectionResults property introspection
Closes gh-28445
2022-05-11 08:32:06 +02:00
Sam Brannen eb50a6f4a0 Further polishing regarding JDK baseline upgrade
See gh-28440
2022-05-10 17:01:40 +02:00
lihan a892ce80c1 Polishing regarding JDK baseline upgrade
Closes gh-28440
2022-05-10 17:01:40 +02:00
Sam Brannen d8f650e3ca Polishing 2022-05-10 12:18:45 +02:00
evgeny.bovykin 7cb6ac0a02 Make inner classes static when feasible (on main)
A static nested class does not keep an implicit reference to its
enclosing instance.

This prevents a common cause of memory leaks and uses less memory per
instance of the class.

Closes gh-28433
2022-05-10 11:45:18 +02:00
Phillip Webb 3df3bc2aa0 Generate native hints for property values
Update `BeanDefinitionPropertiesCodeGenerator` so that hints are
generated for property values. This restores functionality that was
inadvertently removed during refactoring.

See gh-28414
2022-05-09 12:29:56 -07:00
CharlieYu 432fce9db3
Polish Javadoc and inline comments
Closes gh-28426
2022-05-09 20:26:06 +02:00
Sam Brannen 5f8a4bcdc5 Merge branch '5.3.x'
# Conflicts:
#	spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java
#	spring-context/src/main/java/org/springframework/scripting/support/StandardScriptFactory.java
2022-05-09 20:08:37 +02:00
Sam Brannen e26d8839b3 Stop referring to features as Java 6/7 features where unnecessary 2022-05-09 19:09:06 +02:00
evgeny.bovykin 06e1cc2f9b Use Arrays.toString for initMethodNames and destroyMethodNames arrays in AbstractBeanDefinition#toString 2022-05-09 10:18:25 +02:00
Phillip Webb 7700570253 Don't consider singleton instances when deducing bean class
Update `RegisteredBean` bean class detection to not consider
singletons. Prior to this commit, any beans that had been instantiated
could return the wrong class, especially if they were implemented using
a lambda.

See gh-28414
2022-05-06 09:53:37 -07:00
Phillip Webb 16e7f1f212 Complete refactor of AOT concepts
Remove the AOT code that now has an alternative API.

Closes gh-28414
2022-05-05 13:34:52 -07:00
Phillip Webb 7664a54c93 Update InitDestroyAnnotationBeanPostProcessor AOT support
Update `InitDestroyAnnotationBeanPostProcessor` so that it provides
AOT contributions via the `BeanRegistrationAotProcessor` interface.

See gh-28414
2022-05-05 13:25:36 -07:00
Phillip Webb 77c5a6f18d Update AutowiredAnnotationBeanPostProcessor AOT support
Update `AutowiredAnnotationBeanPostProcessor` so that it provides
AOT contributions via the `BeanRegistrationAotProcessor` interface.

See gh-28414
2022-05-05 13:25:36 -07:00
Phillip Webb 4d87071f3a Add AOT interfaces and classes to support bean factories
Add AOT processor and contribution interfaces and classes to
support the generation of code that can re-hydrate a bean
factory.

See gh-28414
2022-05-05 13:25:36 -07:00
Phillip Webb f2cf78c525 Add programmatic autowiring support classes
Add resolver utilities that can be used to perform programmatic
autowiring of fields, methods, constructors and factory methods.

The resolvers are designed to work in an AOT environment and
allows the actual injection to be performed using functional
interfaces. This allows leaner images to be created since
`introspection` hints are required rather than full `invocation`
hints.

The resolvers also provide a reflection based fallback that can
used when the functional interface cannot work. For example, a
reflection based solution is required for private fields, methods
and constructors.

See gh-28414
2022-05-05 12:35:21 -07:00
Phillip Webb 3209d7f126 Add InstanceSupplier and RegisteredBean support
Add a new `InstanceSupplier` interface that can be used as an
alternative to a regular bean `Supplier` when details about the
bean being supplied are required to instantiate it. The new
interface accepts a `RegisteredBean` instance which provides
access to the bean name, the bean factory creating the bean
and the bean definition.

This interface is primarily designed to allow AOT generated code
to autowire dependencies into the instance.

See gh-28414
2022-05-05 12:35:21 -07:00
Phillip Webb d31eb4c0f1 Add RootBeanDefinition constructor that accepts a ResolvableType
Add a new convenience constructor to `RootBeanDefinition` that allow
it to be created with a `ResolvableType`.

Closes gh-28418
2022-05-05 12:35:21 -07:00
Phillip Webb 58c441f961 Support multiple SpringFactoriesLoader files
Update `SpringFactoriesLoader` so that it can load files from
arbitrary locations. An instance of the loader class itself is now
returned from static factory methods that accept different
locations.

The recent `ArgumentResolver` and `FailureHandler` `loadFactories`
variants are now no longer available as static methods. They are
still available as instance methods.

The `loadFactories` static method remains to provide
back-compatibility with Spring Framework 5.x

See gh-28416
2022-05-05 12:35:21 -07:00
Juergen Hoeller bf4e3975fb Merge branch '5.3.x'
# Conflicts:
#	build.gradle
2022-05-05 18:07:39 +02:00
Juergen Hoeller e441832e99 Accept WritableResource as required dependency type as well
Closes gh-15284
2022-05-05 18:04:13 +02:00
Sam Brannen 0a9271e721 Suppress warning in test 2022-05-03 12:30:46 +02:00
Sam Brannen f934c09211 Polish ExtendedBeanInfo 2022-05-02 17:05:25 +02:00
Stephane Nicoll 5378572b00 Clarify lambda code block methods 2022-04-26 15:13:43 +02:00
Stephane Nicoll 7ea0cc3da2 Allow BeanRegistrationContributionProvider to access the BeanFactory
Closes gh-28384
2022-04-26 15:02:54 +02:00
Stephane Nicoll 26054fd3d4 AOT contribution for @PersistenceContext and @PersistenceUnit
Closes gh-28364
2022-04-25 11:01:09 +02:00
Stephane Nicoll 10d254983f Refine MultiStatement#toClodeBlock
Closes gh-28363
2022-04-25 09:13:50 +02:00
Stephane Nicoll 95f24c0897 Merge branch '5.3.x' 2022-04-14 14:11:41 +02:00
Stephane Nicoll 3017955eff Update copyright year of changed file
See gh-28340
2022-04-14 14:09:54 +02:00
Koen Punt 22c82ff206 Fix method reference in Kotlin documentation
See gh-28340
2022-04-14 14:09:02 +02:00
Sam Brannen 1574fed90b Merge branch '5.3.x' 2022-04-13 10:08:31 +02:00
Sam Brannen a7cf19cec5 Improve documentation and matching algorithm in data binders 2022-04-13 09:55:40 +02:00
Juergen Hoeller 8744952424 Merge branch '5.3.x' 2022-04-13 00:28:22 +02:00
Juergen Hoeller 949c3d450c Align plain accessor check 2022-04-13 00:24:06 +02:00
Juergen Hoeller 7e1782ea22 Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	spring-core/src/main/java/org/springframework/core/convert/Property.java
2022-04-08 13:10:34 +02:00
Juergen Hoeller 9f91168396 Restore ability to configure setClassLoader methods
Closes gh-28269
2022-04-08 13:02:53 +02:00
Brian Clozel afbff391d8 Merge branch '5.3.x' 2022-03-31 10:33:51 +02:00
Brian Clozel 002546b3e4 Refine PropertyDescriptor filtering
Restrict property paths under `Class` and properties of types
`ClassLoader` or `ProtectionDomain`.
2022-03-31 10:21:30 +02:00
izeye f55bff50b6 Add Javadoc since for BeanDefinitionValueResolver.resolveInnerBean()
See gh-28217
2022-03-22 16:52:51 +01:00
Sam Brannen d11389e783 Merge branch '5.3.x' 2022-03-21 17:13:30 +01:00
Sam Brannen 8fc744f4f4 Improve Javadoc for BeanExpressionResolver 2022-03-21 16:57:27 +01:00
Sam Brannen 3da7a48a17 Explicitly close ApplicationContexts and clean up warnings in tests 2022-03-20 13:19:25 +01:00
Stephane Nicoll 0cbea29517 Polish 2022-03-18 18:25:30 +01:00
Sam Brannen 64b64d9ba0 Stop referring to features as "Java 5" features
With a Java 8 baseline in place for quite some time now, it no longer
makes sense to refer to features such as annotations as "Java 5
annotations".

This commit also removes old `Tiger*Tests` classes, thereby avoiding
duplicate execution of various tests.
2022-03-18 16:32:30 +01:00
Sébastien Deleuze ae1956cac7 Merge branch '5.3.x' 2022-03-15 18:35:59 +01:00
danthonywalker 50771237cc Fix ListableBeanFactory#findAnnotationOnBean extension return type
Closes gh-26908
2022-03-15 18:33:35 +01:00
Sam Brannen 1392b0f557 Merge branch '5.3.x' 2022-03-15 17:13:10 +01:00
Sam Brannen 9fbf5dc945 Use String#lastIndexOf(int) where possible 2022-03-15 17:03:20 +01:00
Sam Brannen 5598f99816 Merge branch '5.3.x' 2022-03-14 20:27:05 +01:00
Sam Brannen 6e2e45d18f Apply @SafeVarargs to ManagedMap.ofEntries(...) 2022-03-14 20:24:57 +01:00
Sam Brannen 2ab871fbc3 Merge branch '5.3.x' 2022-03-12 18:16:26 +01:00
Sam Brannen 887389d341 Clarify behavior for generics support in BeanUtils.copyProperties()
Since Spring Framework 5.3, BeanUtils.copyProperties() honors generics
in the source and target property types (see gh-24187); however, this
refinement of the contract was not properly documented prior to this
commit. In addition, the refinement can be a breaking change for users
who were relying on the previous unreliable behavior.

This commit therefore clarifies the behavior for generics support in
BeanUtils.copyProperties() and introduces a table of example matches
and mismatches when generics are involved.

Closes gh-27259
2022-03-12 18:12:23 +01:00
Stephane Nicoll 672555a568 Add support of init and destroy methods
This commit updates InitDestroyBeanPostProcessor so that it contributes
init or destroy method names to the `RootBeanDefinition`. This is then
used by the generator to provide these methods to the optimized AOT
context.

Invocation of those init methods still happen using reflection so
dedicated hints are contributed for them.

Closes gh-28151
2022-03-12 13:35:56 +01:00
Stephane Nicoll 1742e121e7 Update bean registration contribution tests to use TestCompiler 2022-03-10 16:06:52 +01:00
Stephane Nicoll 93a2651417 Make sure method injection handles ambiguous signatures
This commit updates InjectionGenerator to request a resolved attribute
with a dedicated type if multiple methods with the same name and the
same number of arguments exist. This was previously done already for
constructors and this commit harmonizes the algorithms to methods as
well

Closes gh-28154
2022-03-10 15:34:53 +01:00
Stephane Nicoll a0061b7fb9 Remove cast on AbstractFactoryBean
Closes gh-28153
2022-03-10 11:50:24 +01:00
Stephane Nicoll 9809752c3c Stop generating unnecessary reference to field type
This commit updates the generator to stop specifying a field type when
reflection is necessary, or when a reference to a field should be
retrieved as its name alone suffices.

This could trigger package protected issues if the field type is not
public.

See gh-28047
2022-03-09 11:17:21 +01:00
Stephane Nicoll 9b07457d06 Introduce ApplicationContextAotGenerator
This commit introduces a way to process a GenericApplicationContext
ahead of time. Components that can contribute in that phase are
invoked, and their contributions are recorded in the
GeneratedTypeContext.

This commit also expands BeanFactoryContribution so that it can exclude
bean definitions that are no longer required.

Closes gh-28150
2022-03-09 11:17:21 +01:00
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