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
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.
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
Includes deprecation of NestedServletException, whereas NestedCheckedException and NestedRuntimeException remain as base classes with several convenience methods.
Closes gh-25162
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
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
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
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
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
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
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
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
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
Update `BeanDefinitionPropertiesCodeGenerator` so that hints are
generated for property values. This restores functionality that was
inadvertently removed during refactoring.
See gh-28414
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
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
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