Commit Graph

473 Commits

Author SHA1 Message Date
Simon Baslé
d5c7a5e2db Bean overriding by type uses isAutowireCandidate for matching
This commit uses the bean factory `isAutowiredCandidate` method directly
in `BeanOverrideBeanFactoryPostProcessor` to select a single match among
multiple candidates when matching by type.

The expected consequence, in most cases, is that this will delegate to
a `@Qualifier`-aware `QualifierAnnotationAutowireCandidateResolver`.
In that sense, bean overriding by-type matching is now potentially
taking Qualifier annotations or meta-annotations into account.

It also changes the way existing bean definitions are checked in case
a bean name has been specified: factory beans are now taken into account
when checking the type of an existing definition matches the expected
bean override type.

Closes gh-32822
2024-05-21 14:06:52 +02:00
Brian Clozel
4d4b343815 Support Content Negotiation with @ExceptionHandler
Prior to this commit, `@ExceptionHandler` annotated controller methods
could be mapped using the exception type declaration as an annotation
attribute, or as a method parameter.
While such methods support a wide variety of method arguments and return
types, it was not possible to declare the same exception type on
different methods (in the same controller/controller advice).

This commit adds a new `produces` attribute on `@ExceptionHandler`; with
that, applications can vary the HTTP response depending on the exception
type and the requested content-type by the client:

```
@ExceptionHandler(produces = "application/json")
public ResponseEntity<ErrorMessage> handleJson(IllegalArgumentException exc) {
	return ResponseEntity.badRequest().body(new ErrorMessage(exc.getMessage(), 42));
}

@ExceptionHandler(produces = "text/html")
public String handle(IllegalArgumentException exc, Model model) {
	model.addAttribute("error", new ErrorMessage(exc.getMessage(), 42));
	return "errorView";
}
```

This commit implements support in both Spring MVC and Spring WebFlux.

Closes gh-31936
2024-05-20 17:22:30 +02:00
Sébastien Deleuze
268043a28c Merge branch '6.1.x' 2024-05-20 10:24:42 +02:00
Sébastien Deleuze
2a2ef443a5 Refine CDS documentation
Closes gh-32843
2024-05-20 10:24:29 +02:00
SharadK10
a3b62a80bc Improve wording in Spring Framework Overview documentation
Closes gh-32829
2024-05-15 19:00:27 +02:00
Sam Brannen
6cdb34410b Register DynamicPropertyRegistry as singleton bean in test ApplicationContext
Prior to this commit, DynamicPropertyRegistry could only be used with a
static @⁠DynamicPropertySource method in an integration test class;
however, it can also be useful to be able to register a "dynamic
property" from within a test's ApplicationContext -- for example, in a
@⁠Bean method in a @⁠Configuration class that is specific to testing
scenarios.

To support such use cases, this commit updates the dynamic property
source infrastructure so that a DynamicPropertyRegistry is always
registered as a singleton bean in a test's ApplicationContext. This
allows DynamicPropertyRegistry to be autowired into a @⁠Configuration
class or supplied to a @⁠Bean method as an argument as shown in the
following example.

@⁠Bean
@⁠DynamicPropertySource
ApiServer apiServer(DynamicPropertyRegistry registry) {
	ApiServer apiServer = new ApiServer();
	registry.add("api.url", apiServer::getUrl);
	return apiServer;
}

Note that the use of @⁠DynamicPropertySource on the @⁠Bean method is
optional and results in the corresponding bean being eagerly
initialized so that other singleton beans in the context can be given
access to the dynamic properties sourced from that bean when those
other beans are initialized.

Side note: DynamicPropertySourceBeanInitializer temporarily implements
LoadTimeWeaverAware since doing so is currently the only way to have a
component eagerly initialized before the
ConfigurableListableBeanFactory.preInstantiateSingletons() phase.
However, we plan to introduce a first-class callback to support such
use cases in the future.

Closes gh-32271
2024-05-15 17:09:03 +02:00
Sam Brannen
d625b3de27 Document SpEL IndexAccessor support in the reference manual
Closes gh-32735
2024-05-15 11:47:42 +02:00
Juergen Hoeller
7c534eeeeb Merge branch '6.1.x'
# Conflicts:
#	framework-platform/framework-platform.gradle
2024-05-14 22:02:32 +02:00
Juergen Hoeller
e509385eae Add InputStreamResource(InputStreamSource) constructor for lambda expressions
Includes notes for reliable InputStream closing, in particular with Spring MVC.

Closes gh-32802
2024-05-14 21:59:42 +02:00
Simon Baslé
a86612a254 Use by-type semantics in bean overriding if no explicit name is provided
This change switches default behavior of `@TestBean`, `@MockitoBean` and
`@MockitoSpyBean` to match the bean definition / bean to override by
type in the case there is no explicit bean name provided via the
annotation. The previous behavior of using the annotated field's name
is still an option for implementors, but no longer the default.

Closes gh-32761
2024-05-14 16:42:11 +02:00
Brian Clozel
80ec951fcf Merge branch '6.1.x' 2024-05-13 13:15:01 +02:00
Brian Clozel
09b8feadc2 Document streaming/collecting behavior for Flux return values
Closes gh-32630
2024-05-13 13:12:53 +02:00
rstoyanchev
10e3d3b434 Merge branch '6.1.x' 2024-05-13 11:41:22 +01:00
rstoyanchev
d03ea0bf19 Update docs on HandlerInterceptor
Closes gh-32729
2024-05-13 11:40:32 +01:00
rstoyanchev
1b60b86bb2 Update MockMvc section on Streaming in the docs
Closes gh-32687
2024-05-13 11:40:32 +01:00
Brian Clozel
5cb4985234 Merge branch '6.1.x' 2024-05-13 10:44:09 +02:00
Brian Clozel
89ce63f1f3 Replace RFC7807 by RFC9457 in documentation
This commit updates all references to RFC7807 by RFC9457 since the
former is now obsolete.

Closes gh-32806
2024-05-13 10:42:35 +02:00
Juergen Hoeller
7b16988ec9 Merge branch '6.1.x' 2024-05-08 17:52:42 +02:00
Juergen Hoeller
22b6d66a28 Document @Order behavior on @Configuration classes versus @Bean methods
Includes brief note on self injection (extracted from qualifiers section).

Closes gh-30177
Closes gh-28299
2024-05-08 17:52:02 +02:00
Juergen Hoeller
9376e6322d Revise IoC container introduction for modern configuration styles
Includes @Configuration(proxyBeanMethods=false) documentation.

Closes gh-32429
2024-05-08 17:51:25 +02:00
Juergen Hoeller
0eb937a866 Document limitations of CGLIB proxy class generation in JPMS module setups
Includes extended exception messages with common hints and explanations.

Closes gh-32671
2024-05-08 17:51:17 +02:00
Sam Brannen
ac0136b75c Clarify supported targets for annotations in the TestContext framework
Closes gh-32772
2024-05-07 16:45:12 +03:00
Sébastien Deleuze
39889744b0 Polish JdbcTemplate Best Practices section 2024-05-06 18:28:54 +02:00
Sébastien Deleuze
04944a1f56 Modernize the lazy-initialized beans refdoc section
Closes gh-32767
2024-05-06 17:08:49 +02:00
Sébastien Deleuze
c6459b40e4 Modernize the integration section of the refdoc
This commit adds Java and Kotlin tabs to XML code snippets where
relevant, and leverages code includes.

Closes gh-32600
2024-05-06 16:05:35 +02:00
Sébastien Deleuze
a8430878ca Merge branch '6.1.x' 2024-05-02 11:08:30 +02:00
Sébastien Deleuze
f17527a48b Use expectBody<Person>() in WebTestClient documentation
Closes gh-32733
2024-05-02 11:07:36 +02:00
Sam Brannen
512ff7ce3c Merge branch '6.1.x' 2024-04-30 18:09:41 +03:00
Seungrae Kim
32c80d5ae6 Fix incorrect class reference syntax in Kotlin code sample
Closes gh-32733
2024-04-30 18:09:02 +03:00
Juergen Hoeller
f1a1190700 Merge branch '6.1.x'
# Conflicts:
#	framework-docs/modules/ROOT/pages/data-access/transaction/declarative/annotations.adoc
2024-04-30 15:47:48 +02:00
Juergen Hoeller
7263771552 Add documentation for CompletableFuture-driven rollback
Closes gh-32709
2024-04-30 15:45:56 +02:00
Juergen Hoeller
fab3633c75 Add notes on constructor and factory method overloading
Closes gh-32091
2024-04-30 15:45:46 +02:00
Sébastien Deleuze
b232aefdeb Use lowercase package in code snippets
Closes gh-32734
2024-04-30 15:05:15 +02:00
Sam Brannen
00da781c44 Merge branch '6.1.x' 2024-04-24 15:33:19 +03:00
Sam Brannen
546ca9b834 Polishing 2024-04-24 15:32:57 +03:00
Stéphane Nicoll
a77895bd90 Merge branch '6.1.x' 2024-04-23 15:34:49 +02:00
Johnny Lim
cc73ccefef Polish
See gh-32696
2024-04-23 15:31:48 +02:00
Stéphane Nicoll
af4a986256 Merge branch '6.1.x' 2024-04-23 12:43:40 +02:00
Stéphane Nicoll
40596d444c Provide a more explicit link to URI composition examples
Closes gh-32685
2024-04-23 12:43:15 +02:00
Stéphane Nicoll
4e1b8f9be3 Merge branch '6.1.x' 2024-04-23 11:04:02 +02:00
Stéphane Nicoll
cb5b9dcaed Document AOT limitation of creating beans with custom arguments
Closes gh-32690
2024-04-23 11:03:28 +02:00
Simon Baslé
a985c0bb35 Polishing: fix link fragments in test bean override annotation pages 2024-04-18 14:54:57 +02:00
Michael Kunze
00c7002354 Fix typo in class name
Closes gh-32664
2024-04-18 09:32:10 +02:00
Sam Brannen
8727d723f3 Polish "Bean Overriding in Tests" support 2024-04-16 17:08:15 +02:00
Arjen Poutsma
051fd2ae4f Merge branch '6.1.x' 2024-04-16 11:44:02 +02:00
Arjen Poutsma
3971632415 Reintroduce SimpleClientHttpRequestFactory limitations
Closes gh-32641
2024-04-16 11:43:09 +02:00
Simon Baslé
02ee5de470 Document bean override in TestContext framework section of the manual
This change splits the documentation in the reference manual: the
`@TestBean`, `@MockitoBean` and `@MockitoSpyBean` annotations are kept
in the appendix and the general documentation about the feature is moved
into a dedicated sub-section of the TCF section.

Close gh-32490
2024-04-15 17:07:14 +02:00
Sam Brannen
43cc18a5a1 Use literal monospace in SpEL templating section
Prior to this commit, the text `#{ }` was displayed as { } with a bright
green background.

This commit addresses this by making use of Asciidoc's literal monospace
feature: `+#{ }+`.
2024-04-11 14:00:46 +02:00
Stéphane Nicoll
2e3a923225 Polish 2024-04-11 08:45:26 +02:00
Simon Baslé
2d33aac350 Improve Bean Overriding support, testing and documentation
This commit improves on the bean overriding feature in several ways:
the API is simplified and polished (metadata and processor contracts,
 etc...).

The commit also reworks infrastructure classes (context customizer,
test execution listener, BeanOverrideBeanFactoryPostProcessor, etc...).
Parsing of annotations is now fully stateless.

In order to avoid OverrideMetadata in bean definition and to make a
first step towards AOT support, the BeanOverrideBeanFactoryPostProcessor
now delegates to a BeanOverrideRegistrar to track classes to parse,
the metadata-related state as well as for the field injection methods
for tests.

Lastly, this commit increases the test coverage for the provided
annotations and adds integration tests and fixes a few `@TestBean`
issues.
2024-04-10 18:16:43 +02:00