Commit Graph

32657 Commits

Author SHA1 Message Date
rstoyanchev
fd8823819f MapMethodProcessor supportsParameter is more specific
Closes gh-33160
2024-12-11 12:22:56 +00:00
Sam Brannen
3256bf436a Merge branch '6.2.x' 2024-12-11 12:12:57 +01:00
Sam Brannen
7206b28272 Implement toString() in TestBeanOverrideHandler
Closes gh-34072
2024-12-11 12:12:35 +01:00
Brian Clozel
11db31a8ee Merge branch '6.2.x' 2024-12-10 22:36:01 +01:00
Brian Clozel
0c688742e1 Fix custom scheduler support for @Scheduled methods
This commit fixes a regression introduced by gh-24560, when adding
execution metadata support for scheduled tasks. The
`OutcomeTrackingRunnable` would delegate to the actual runnable but
could also hide whether it implements the `SchedulingAwareRunnable`
contract.

This commit ensures that `OutcomeTrackingRunnable` always implements
that contract and delegates to the runnable if possible, or return
default values otherwise.

Fixes gh-34058
2024-12-10 22:33:20 +01:00
Juergen Hoeller
41f8ac6b59 Merge branch '6.2.x' 2024-12-10 22:16:46 +01:00
Juergen Hoeller
7de1dc826a Consistently handle generics in TypeDescriptor.equals
Properly processes recursive types through always comparing generics via the top-level ResolvableType (rather than through nested TypeDescriptors with custom ResolvableType instances).

Closes gh-33932
2024-12-10 22:16:10 +01:00
Juergen Hoeller
3d19d78461 Merge branch '6.2.x' 2024-12-10 16:26:56 +01:00
Juergen Hoeller
3e3ca74020 Log provider setup failure at info level without stacktrace
Closes gh-33979
2024-12-10 16:25:57 +01:00
Juergen Hoeller
66da5d7ab9 Restore original override behavior when override allowed
Closes gh-33920
2024-12-10 16:25:49 +01:00
Stéphane Nicoll
1c435c0f47 Merge branch '6.2.x' 2024-12-10 14:09:18 +01:00
Stéphane Nicoll
68d6cb9d35 Upgrade to Reactor 2024.0.1
Closes gh-34051
2024-12-10 14:06:07 +01:00
Stéphane Nicoll
6649a6e0f7 Upgrade to Micrometer 1.14.2
Closes gh-34050
2024-12-10 14:05:43 +01:00
Sam Brannen
2d4baec2b1 Merge branch '6.2.x' 2024-12-10 12:52:32 +01:00
Sam Brannen
54948a4e88 Log warning when one Bean Override overrides another Bean Override
It is currently possible for one Bean Override to override another
logically equivalent Bean Override.

For example, a @⁠TestBean can override a @⁠MockitoBean, and vice versa.

In fact, it's also possible for a @⁠MockitoBean to override another
@⁠MockitoBean, for a @⁠TestBean to override a @⁠TestBean, etc.

However, there may be viable use cases for one override overriding
another override. For example, one may have a need to spy on a bean
created by a @⁠TestBean factory method.

In light of that, we do not prohibit one Bean Override from overriding
another Bean Override; however, with this commit we now log a warning
to help developers diagnose issues in case such an override is
unintentional.

For example, given the following test class, where TestConfig registers
a single bean of type MyService named "myService"...

@⁠SpringJUnitConfig(TestConfig.class)
class MyTests {

  @⁠TestBean(methodName = "example.TestUtils#createMyService")
  MyService testService;

  @⁠MockitoBean
  MyService mockService;

  @⁠Test
  void test() {
    // ...
  }
}

... running that test class results in a log message similar to the
following, which has been formatted for readability.

WARN - Bean with name 'myService' was overridden by multiple handlers:
[
 [TestBeanOverrideHandler@44b21f9f
  field = example.MyService example.MyTests.testService,
  beanType = example.MyService,
  beanName = [null],
  strategy = REPLACE_OR_CREATE
 ],
 [MockitoBeanOverrideHandler@7ee8130e
  field = example.MyService example.MyTests.mockService,
  beanType = example.MyService,
  beanName = [null],
  strategy = REPLACE_OR_CREATE,
  reset = AFTER,
  extraInterfaces = set[[empty]],
  answers = RETURNS_DEFAULTS, serializable = false
 ]
]

NOTE: The last registered BeanOverrideHandler wins. In the above
example, that means that @⁠MockitoBean overrides @⁠TestBean, resulting
in a Mockito mock for the MyService bean in the test's
ApplicationContext.

Closes gh-34056
2024-12-10 12:49:48 +01:00
Sébastien Deleuze
83517d05d0 Merge branch '6.2.x' 2024-12-10 11:51:19 +01:00
Sébastien Deleuze
a00ba8dbcf Revert "Reuse NoTransactionInContextException instances"
This reverts commit 8e3846991d.

Closes gh-34048
2024-12-10 11:47:56 +01:00
Stéphane Nicoll
2546f63824 Merge branch '6.2.x' 2024-12-10 07:48:01 +01:00
Stéphane Nicoll
4f815b0055 Merge pull request #33891 from youabledev
* pr/33891:
  Polish

Closes gh-33891
2024-12-10 07:47:52 +01:00
youable
5494d78018 Polish
See gh-33891
2024-12-10 07:47:42 +01:00
Sam Brannen
cd25a64ac0 Merge branch '6.2.x' 2024-12-09 16:01:07 +01:00
Sam Brannen
cd60a0013b Reject identical Bean Overrides
Prior to this commit, the Bean Override feature in the Spring
TestContext Framework (for annotations such as @⁠MockitoBean and
@⁠TestBean) silently allowed one bean override to override another
"identical" bean override; however, Spring Boot's @⁠MockBean and
@⁠SpyBean support preemptively rejects identical overrides and throws
an IllegalStateException to signal the configuration error to the user.

To align with the behavior of @⁠MockBean and @⁠SpyBean in Spring Boot,
and to help developers avoid scenarios that are potentially confusing
or difficult to debug, this commit rejects identical bean overrides in
the Spring TestContext Framework.

Note, however, that it is still possible for a bean override to
override a logically equivalent bean override. For example, a
@⁠TestBean can override a @⁠MockitoBean, and vice versa.

Closes gh-34054
2024-12-09 16:00:24 +01:00
Sam Brannen
2137750591 Improve Bean Override by-name integration tests 2024-12-09 13:01:42 +01:00
Brian Clozel
78f28fda54 Merge branch '6.2.x' 2024-12-09 11:18:28 +01:00
Brian Clozel
13df9058a4 Introduce "unsafeAllocated" flag in TypeHint
This metadata information is required for supporting libraries using
`sun.misc.Unsafe#allocateInstance(Class<?>)`, even though Spring
Framework is not using this feature.

Closes gh-34055
2024-12-09 11:08:48 +01:00
Brian Clozel
810da11bb5 Remove deprecated web APIs
This commit also marks for removal APIs that were deprecated a long time
ago but were not marked for removal.

See gh-33809
2024-12-08 22:50:54 +01:00
Brian Clozel
5044b70a40 Remove deprecated MediaType entries
See gh-33809
2024-12-08 21:01:11 +01:00
Brian Clozel
ff28d2d47a Polishing MediaType Javadoc
Closes gh-34047
2024-12-08 20:44:57 +01:00
Brian Clozel
3edb256298 Update websocket reference docs
See gh-33744
2024-12-08 20:12:57 +01:00
Sam Brannen
2015a93823 Merge branch '6.2.x' 2024-12-08 18:41:37 +01:00
Sam Brannen
aee52b53a1 Introduce MockitoAssertions 2024-12-08 18:41:10 +01:00
Sam Brannen
92bbaa21e0 Improve test coverage for @⁠MockitoSpyBean use cases 2024-12-08 18:41:10 +01:00
Stéphane Nicoll
b904753a25 Merge branch '6.2.x' 2024-12-08 10:53:16 +01:00
Stéphane Nicoll
837579c2e5 Start building against Reactor 2024.0.1 snapshots
See gh-34051
2024-12-08 10:49:57 +01:00
Stéphane Nicoll
03a75cf03a Start building against Micrometer 1.14.2 snapshots
See gh-34050
2024-12-08 10:48:45 +01:00
Sam Brannen
0e50fe4f6a Merge branch '6.2.x' 2024-12-07 16:56:23 +01:00
Sam Brannen
aa7b459803 Fix Phantom Read problem for Bean Overrides in the TestContext framework
To make an analogy to read phenomena for transactional databases, this
commit effectively fixes the "Phantom Read" problem for Bean Overrides.

A phantom read occurs when the BeanOverrideBeanFactoryPostProcessor
retrieves a set of bean names by-type twice and a new bean definition
for a compatible type has been created in the BeanFactory by a
BeanOverrideHandler between the first and second retrieval.

Continue reading for the details...

Prior to this commit, the injection of test Bean Overrides (for
example, when using @⁠MockitoBean) could fail in certain scenarios if
overrides were created for nonexistent beans "by type" without an
explicit name or qualifier. Specifically, if an override for a SubType
was created first, and subsequently an attempt was made to create an
override for a SuperType (where SubType extends SuperType), the
override for the SuperType would "override the override" for the
SubType, effectively removing the override for the SubType.
Consequently, injection of the override instance into the SubType field
would fail with an error message similar to the following.

BeanNotOfRequiredTypeException: Bean named 'Subtype#0' is expected to
be of type 'Subtype' but was actually of type 'Supertype$Mock$XHb7Aspo'

This commit addresses this issue by tracking all generated bean names
(in a generatedBeanNames set) and ensuring that a new bean override
instance is created for the current BeanOverrideHandler if a previous
BeanOverrideHandler already created a bean override instance that now
matches the type required by the current BeanOverrideHandler.

In other words, if the generatedBeanNames set already contains the
beanName that we just found by-type, we cannot "override the override",
because we would lose one of the overrides. Instead, we must create a
new override for the current handler. In the example given above, we
must end up with overrides for both SuperType and SubType.

Closes gh-34025
2024-12-07 16:51:16 +01:00
Sam Brannen
03fe1f0df3 Improve documentation for BeanOverrideBeanFactoryPostProcessor 2024-12-07 16:05:54 +01:00
Stéphane Nicoll
f8fd6da10b Merge branch '6.2.x' 2024-12-06 15:42:15 +01:00
Stéphane Nicoll
0d72477742 Restore user type in generated root bean definitions
This commit restores the user class in generated RootBeanDefinition
instances. Previously the CGLIB subclass was exposed. While this is
important in regular runtime as the configuration class parser operates
on the bean definition, this is not relevant for AOT as this information
is internal and captured in the instance supplier.

Closes gh-33960
2024-12-06 15:34:00 +01:00
Stéphane Nicoll
6d28ac6b2c Merge branch '6.2.x' 2024-12-06 09:44:05 +01:00
Stéphane Nicoll
d26ee8f852 Merge pull request #34031 from ngocnhan-tran1996
* pr/34031:
  Fix link to MockMvcBuilders in reference documentation

Closes gh-34031
2024-12-06 09:44:01 +01:00
Tran Ngoc Nhan
47c66f4352 Fix link to MockMvcBuilders in reference documentation
See gh-34031
2024-12-06 09:43:41 +01:00
Juergen Hoeller
5e62ae19a9 Merge branch '6.2.x' 2024-12-05 17:42:45 +01:00
Juergen Hoeller
b5dd0a60f8 Restore lenient match against unresolvable wildcard
Closes gh-33982
2024-12-05 17:41:49 +01:00
Stéphane Nicoll
b8cdef6d29 Merge branch '6.2.x' 2024-12-05 17:01:50 +01:00
Stéphane Nicoll
e618f922c2 Resolve nested placeholders with a fallback having one
This commit fixes a regression in PlaceHolderParser where it would no
longer resolve nested placeholders for a case where the fallback has a
placeholder itself.

This is due to the Part implementations and how they are structure, and
this commit makes sure that nested resolution happens consistently.

Closes gh-34020
2024-12-05 16:59:30 +01:00
Sébastien Deleuze
c2822a6b23 Add .kotlin directory to .gitignore
See gh-33629
2024-12-05 16:02:23 +01:00
Stéphane Nicoll
086d7081f8 Merge branch '6.2.x' 2024-12-05 15:57:57 +01:00
Stéphane Nicoll
81a9f3d50b Restore public type for generated instance supplier of CGLIB proxy
This commit restores the signature of instance suppliers that are
exposing a CGLIB proxy. While calling the CGLIB proxy itself, and
making it available in BeanInstanceSupplier, is needed internally, such
type should not be exposed as it is an internal concern.

This was breaking InstanceSupplier.andThen as it expects the public
type of the bean to be exposed, not it's eventual CGLIB subclass.

Closes gh-33998
2024-12-05 15:48:49 +01:00