Commit Graph

1478 Commits

Author SHA1 Message Date
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