If set parent bean factory to self, once try to get an undefined bean, bellow condition
if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {
...
}
will always be true and StackOverflowError will be thrown.
Sometimes, this issue is hard to detect during runtime, if self-reference is not allowed here, error will be found at the early time of startup.
Also, a self-reference parent bean factory is valueless.
Motivation
----------
The Spring MVC ModelAttributeMethodProcessor includes many helpful
extension methods that allow developers to extend and enhance the data
binding capabilities of the class. Unfortunately, Spring WebFlux's
equivalent class, the ModelAttributeMethodArgumentResolver, does not
include these same extension methods. I am leveraging these extension
methods, specifically the bindRequestParameters method, to provide
valuable enhancements to my application. I would like to provide these
same enhancements to the WebFlux portion of my application and am
unable to do so at this time. I would like to update the WebFlux
ModelAttributeMethodArgumentResolver to add the bindRequestParameters
method.
Modifications
-------------
I created a new method called bindRequestParameters and encapsulated
the WebExchangeDataBinder bind call inside of it. This method is
marked as protected as it should only be used by children of this
class. This change mirrors the behavior in the equivalent Spring MVC
class (ModelAttributeMethodProcessor).
Result
------
The WebFlux ModelAttributeMethodArgumentResolver can now accept
alternative data binding implementations mirroring the Web MVC
behavior.
Prior to the introduction of the MergedAnnotation API in Spring Framework
5.2, our SynthesizedAnnotationInvocationHandler utilized a cache for
annotation attribute values; whereas, the new
SynthesizedMergedAnnotationInvocationHandler has no such caching in
place.
Issues such as gh-24961 indicate a regression in performance caused by
the lack of such an attribute value cache. For example, the required
attribute in @RequestParam is looked up using the internal meta-model
in the MergedAnnotation API twice per request for each @RequestParam in
a given controller handler method.
This commit reintroduces the attribute value cache to avoid the
unnecessary performance overhead associated with multiple lookups of
the same attribute in a synthesized annotation. This applies not only
to direct attribute method invocations but also to invocations of
equals() and hashCode() on a synthesized annotation.
Note, however, that this commit does NOT address multiple lookups of
annotation attribute values for invocations of toString(). That behavior
currently remains unchanged in the implementation of
org.springframework.core.annotation.TypeMappedAnnotation.toString().
Closes gh-24970
Commit 31fa1569c5 introduced initial support for avoiding unnecessary
annotation synthesis in the MergedAnnotation API; however, it only
avoided synthesis for annotations that do not declare any attributes.
This commit reworks this support to avoid unnecessary annotation
synthesis for annotations that declare attributes.
Specifically, this commit introduces a new `isSynthesizable()` method
in AnnotationTypeMapping that allows the "synthesizable" flag to be
computed once and cached along with the other metadata already cached
in AnnotationTypeMapping instances. TypeMappedAnnotation now delegates
to this new method when determining whether it should synthesize an
annotation.
Closes gh-24861
As of gh-24952, `PathPatternParser` will strictly reject patterns with
`"**"` in the middle of them. `"**"` is only allowed at the end of the
pattern for matching multiple path segments until the end of the path.
Currently, if `"**"` is used in the middle of a pattern it will be
considered as a single `"*"` instead. Rejecting such cases should
clarify the situation.
This commit prepares for that upcoming change and:
* logs a warning message if such a case is used by an application
* expands the MVC and WebFlux documentation about URI matching in
general
Closes gh-24958
Prior to Spring Framework 5.2, some of our annotation utilities would
not synthesize an annotation if it was already synthesized or not
synthesizable (i.e., did not declare local aliases via @AliasFor and
did not declare attributes that could override attributes in the
meta-annotation hierarchy above the given annotation); however, we lost
most of this functionality with the introduction of the new
MergedAnnotations API.
This commit revises the implementation of createSynthesized() in
TypeMappedAnnotation so that, for invocations of
MergedAnnotation.synthesize() and indirectly for invocations of
AnnotatedElementUtils.findMergedAnnotation(), etc.:
1. An annotation that was previously synthesized will not be
synthesized again.
2. An annotation that is not "synthesizable" will not be synthesized.
For both of the above use cases, the original annotation is now
returned from createSynthesized().
Closes gh-24861
According to the Javadoc for ServletRequest's getServerName() method,
when the `Host` header is set, the server name is "the value of the
part before ':' in the Host header value ...". For a value representing
an IPV6 address such as `[::ffff:abcd:abcd]`, the enclosing square
brackets should therefore not be stripped from the enclosed IPV6
address.
However, the changes made in conjunction with gh-16704 introduced a
regression in Spring Framework 4.1 for the getServerName() method in
MockHttpServletRequest by stripping the enclosing brackets from the
IPV6 address in the `Host` header. Similarly, the changes made in
conjunction with gh-20686 introduced a regression in Spring Framework
4.3.13 and 5.0.2 in the getRequestURL() method in
MockHttpServletRequest by delegating to the getServerName() method
which strips the enclosing brackets.
This commit fixes the implementation of getServerName() so that the
enclosing brackets are no longer stripped from an IPV6 address in the
`Host` header. The implementation of getRequestURL() is therefore also
fixed.
In addition, in order to avoid a NullPointerException, the
implementations of getServerName() and getServerPort() now assert that
an IPV6 address present in the `Host` header correctly contains an
opening and closing bracket and throw an IllegalStateException if that
is not the case.
Closes gh-24916