Skip to content

Commit c6459b4

Browse files
committed
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
1 parent bdc4ecd commit c6459b4

File tree

95 files changed

+2880
-522
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+2880
-522
lines changed

framework-docs/framework-docs.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ dependencies {
7979
api("org.aspectj:aspectjweaver")
8080
api("io.projectreactor.netty:reactor-netty-http")
8181
api("org.eclipse.jetty.websocket:jetty-websocket-jetty-api")
82+
api("javax.cache:cache-api")
83+
api("jakarta.resource:jakarta.resource-api")
84+
api("org.apache.activemq:activemq-ra:6.1.2")
8285

8386
implementation(project(":spring-core-test"))
8487
implementation("org.assertj:assertj-core")

framework-docs/modules/ROOT/pages/integration/cache/annotations.adoc

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -518,41 +518,9 @@ disable it by removing only one configuration line rather than all the annotatio
518518
your code).
519519

520520
To enable caching annotations add the annotation `@EnableCaching` to one of your
521-
`@Configuration` classes:
521+
`@Configuration` classes or use the `cache:annotation-driven` element with XML:
522522

523-
[source,java,indent=0,subs="verbatim,quotes"]
524-
----
525-
@Configuration
526-
@EnableCaching
527-
public class AppConfig {
528-
529-
@Bean
530-
CacheManager cacheManager() {
531-
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
532-
cacheManager.setCacheSpecification(...);
533-
return cacheManager;
534-
}
535-
}
536-
----
537-
538-
Alternatively, for XML configuration you can use the `cache:annotation-driven` element:
539-
540-
[source,xml,indent=0,subs="verbatim,quotes"]
541-
----
542-
<beans xmlns="http://www.springframework.org/schema/beans"
543-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
544-
xmlns:cache="http://www.springframework.org/schema/cache"
545-
xsi:schemaLocation="
546-
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
547-
http://www.springframework.org/schema/cache https://www.springframework.org/schema/cache/spring-cache.xsd">
548-
549-
<cache:annotation-driven/>
550-
551-
<bean id="cacheManager" class="org.springframework.cache.caffeine.CaffeineCacheManager">
552-
<property name="cacheSpecification" value="..."/>
553-
</bean>
554-
</beans>
555-
----
523+
include-code::./CacheConfiguration[tag=snippet,indent=0]
556524

557525
Both the `cache:annotation-driven` element and the `@EnableCaching` annotation let you
558526
specify various options that influence the way the caching behavior is added to the

framework-docs/modules/ROOT/pages/integration/cache/store-configuration.adoc

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,7 @@ The JDK-based `Cache` implementation resides under
1313
`org.springframework.cache.concurrent` package. It lets you use `ConcurrentHashMap`
1414
as a backing `Cache` store. The following example shows how to configure two caches:
1515

16-
[source,xml,indent=0,subs="verbatim,quotes"]
17-
----
18-
<!-- simple cache manager -->
19-
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
20-
<property name="caches">
21-
<set>
22-
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="default"/>
23-
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="books"/>
24-
</set>
25-
</property>
26-
</bean>
27-
----
16+
include-code::./CacheConfiguration[tag=snippet,indent=0]
2817

2918
The preceding snippet uses the `SimpleCacheManager` to create a `CacheManager` for the
3019
two nested `ConcurrentMapCache` instances named `default` and `books`. Note that the
@@ -52,26 +41,12 @@ of Caffeine.
5241

5342
The following example configures a `CacheManager` that creates the cache on demand:
5443

55-
[source,xml,indent=0,subs="verbatim,quotes"]
56-
----
57-
<bean id="cacheManager"
58-
class="org.springframework.cache.caffeine.CaffeineCacheManager"/>
59-
----
44+
include-code::./CacheConfiguration[tag=snippet,indent=0]
6045

6146
You can also provide the caches to use explicitly. In that case, only those
6247
are made available by the manager. The following example shows how to do so:
6348

64-
[source,xml,indent=0,subs="verbatim,quotes"]
65-
----
66-
<bean id="cacheManager" class="org.springframework.cache.caffeine.CaffeineCacheManager">
67-
<property name="cacheNames">
68-
<set>
69-
<value>default</value>
70-
<value>books</value>
71-
</set>
72-
</property>
73-
</bean>
74-
----
49+
include-code::./CustomCacheConfiguration[tag=snippet,indent=0]
7550

7651
The Caffeine `CacheManager` also supports custom `Caffeine` and `CacheLoader`.
7752
See the https://github.com/ben-manes/caffeine/wiki[Caffeine documentation]
@@ -97,15 +72,7 @@ implementation is located in the `org.springframework.cache.jcache` package.
9772
Again, to use it, you need to declare the appropriate `CacheManager`.
9873
The following example shows how to do so:
9974

100-
[source,xml,indent=0,subs="verbatim,quotes"]
101-
----
102-
<bean id="cacheManager"
103-
class="org.springframework.cache.jcache.JCacheCacheManager"
104-
p:cache-manager-ref="jCacheManager"/>
105-
106-
<!-- JSR-107 cache manager setup -->
107-
<bean id="jCacheManager" .../>
108-
----
75+
include-code::./CacheConfiguration[tag=snippet,indent=0]
10976

11077

11178
[[cache-store-configuration-noop]]
@@ -119,18 +86,7 @@ cache declarations (which can prove tedious), you can wire in a simple dummy cac
11986
performs no caching -- that is, it forces the cached methods to be invoked every time.
12087
The following example shows how to do so:
12188

122-
[source,xml,indent=0,subs="verbatim,quotes"]
123-
----
124-
<bean id="cacheManager" class="org.springframework.cache.support.CompositeCacheManager">
125-
<property name="cacheManagers">
126-
<list>
127-
<ref bean="jdkCache"/>
128-
<ref bean="gemfireCache"/>
129-
</list>
130-
</property>
131-
<property name="fallbackToNoOpCache" value="true"/>
132-
</bean>
133-
----
89+
include-code::./CacheConfiguration[tag=snippet,indent=0]
13490

13591
The `CompositeCacheManager` in the preceding chains multiple `CacheManager` instances and,
13692
through the `fallbackToNoOpCache` flag, adds a no-op cache for all the definitions not

framework-docs/modules/ROOT/pages/integration/email.adoc

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,7 @@ JavaMail features, such as MIME message support to the `MailSender` interface
4141

4242
Assume that we have a business interface called `OrderManager`, as the following example shows:
4343

44-
[source,java,indent=0,subs="verbatim,quotes"]
45-
----
46-
public interface OrderManager {
47-
48-
void placeOrder(Order order);
49-
50-
}
51-
----
44+
include-code::./OrderManager[tag=snippet,indent=0]
5245

5346
Further assume that we have a requirement stating that an email message with an
5447
order number needs to be generated and sent to a customer who placed the relevant order.
@@ -60,70 +53,11 @@ order number needs to be generated and sent to a customer who placed the relevan
6053
The following example shows how to use `MailSender` and `SimpleMailMessage` to send an
6154
email when someone places an order:
6255

63-
[source,java,indent=0,subs="verbatim,quotes"]
64-
----
65-
import org.springframework.mail.MailException;
66-
import org.springframework.mail.MailSender;
67-
import org.springframework.mail.SimpleMailMessage;
68-
69-
public class SimpleOrderManager implements OrderManager {
70-
71-
private MailSender mailSender;
72-
private SimpleMailMessage templateMessage;
73-
74-
public void setMailSender(MailSender mailSender) {
75-
this.mailSender = mailSender;
76-
}
77-
78-
public void setTemplateMessage(SimpleMailMessage templateMessage) {
79-
this.templateMessage = templateMessage;
80-
}
81-
82-
public void placeOrder(Order order) {
83-
84-
// Do the business calculations...
85-
86-
// Call the collaborators to persist the order...
87-
88-
// Create a thread-safe "copy" of the template message and customize it
89-
SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
90-
msg.setTo(order.getCustomer().getEmailAddress());
91-
msg.setText(
92-
"Dear " + order.getCustomer().getFirstName()
93-
+ order.getCustomer().getLastName()
94-
+ ", thank you for placing order. Your order number is "
95-
+ order.getOrderNumber());
96-
try {
97-
this.mailSender.send(msg);
98-
}
99-
catch (MailException ex) {
100-
// simply log it and go on...
101-
System.err.println(ex.getMessage());
102-
}
103-
}
104-
105-
}
106-
----
56+
include-code::./SimpleOrderManager[tag=snippet,indent=0]
10757

10858
The following example shows the bean definitions for the preceding code:
10959

110-
[source,xml,indent=0,subs="verbatim,quotes"]
111-
----
112-
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
113-
<property name="host" value="mail.mycompany.example"/>
114-
</bean>
115-
116-
<!-- this is a template message that we can pre-load with default state -->
117-
<bean id="templateMessage" class="org.springframework.mail.SimpleMailMessage">
118-
<property name="from" value="[email protected]"/>
119-
<property name="subject" value="Your order"/>
120-
</bean>
121-
122-
<bean id="orderManager" class="com.mycompany.businessapp.support.SimpleOrderManager">
123-
<property name="mailSender" ref="mailSender"/>
124-
<property name="templateMessage" ref="templateMessage"/>
125-
</bean>
126-
----
60+
include-code::./MailConfiguration[tag=snippet,indent=0]
12761

12862

12963
[[mail-usage-mime]]

framework-docs/modules/ROOT/pages/integration/jms/annotated.adoc

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,7 @@ declarations to it.
3737
To enable support for `@JmsListener` annotations, you can add `@EnableJms` to one of
3838
your `@Configuration` classes, as the following example shows:
3939

40-
[source,java,indent=0,subs="verbatim,quotes"]
41-
----
42-
@Configuration
43-
@EnableJms
44-
public class AppConfig {
45-
46-
@Bean
47-
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
48-
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
49-
factory.setConnectionFactory(connectionFactory());
50-
factory.setDestinationResolver(destinationResolver());
51-
factory.setSessionTransacted(true);
52-
factory.setConcurrency("3-10");
53-
return factory;
54-
}
55-
}
56-
----
40+
include-code::./JmsConfiguration[tag=snippet,indent=0]
5741

5842
By default, the infrastructure looks for a bean named `jmsListenerContainerFactory`
5943
as the source for the factory to use to create message listener containers. In this
@@ -67,22 +51,6 @@ container factory. See the javadoc of classes that implement
6751
{spring-framework-api}/jms/annotation/JmsListenerConfigurer.html[`JmsListenerConfigurer`]
6852
for details and examples.
6953

70-
If you prefer xref:integration/jms/namespace.adoc[XML configuration], you can use the `<jms:annotation-driven>`
71-
element, as the following example shows:
72-
73-
[source,xml,indent=0,subs="verbatim,quotes"]
74-
----
75-
<jms:annotation-driven/>
76-
77-
<bean id="jmsListenerContainerFactory"
78-
class="org.springframework.jms.config.DefaultJmsListenerContainerFactory">
79-
<property name="connectionFactory" ref="connectionFactory"/>
80-
<property name="destinationResolver" ref="destinationResolver"/>
81-
<property name="sessionTransacted" value="true"/>
82-
<property name="concurrency" value="3-10"/>
83-
</bean>
84-
----
85-
8654

8755
[[jms-annotated-programmatic-registration]]
8856
== Programmatic Endpoint Registration

framework-docs/modules/ROOT/pages/integration/jms/jca-message-endpoint-manager.adoc

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,62 +7,13 @@ automatically determine the `ActivationSpec` class name from the provider's
77
`ResourceAdapter` class name. Therefore, it is typically possible to provide
88
Spring's generic `JmsActivationSpecConfig`, as the following example shows:
99

10-
[source,xml,indent=0,subs="verbatim,quotes"]
11-
----
12-
<bean class="org.springframework.jms.listener.endpoint.JmsMessageEndpointManager">
13-
<property name="resourceAdapter" ref="resourceAdapter"/>
14-
<property name="activationSpecConfig">
15-
<bean class="org.springframework.jms.listener.endpoint.JmsActivationSpecConfig">
16-
<property name="destinationName" value="myQueue"/>
17-
</bean>
18-
</property>
19-
<property name="messageListener" ref="myMessageListener"/>
20-
</bean>
21-
----
10+
include-code::./JmsConfiguration[tag=snippet,indent=0]
2211

2312
Alternatively, you can set up a `JmsMessageEndpointManager` with a given
2413
`ActivationSpec` object. The `ActivationSpec` object may also come from a JNDI lookup
2514
(using `<jee:jndi-lookup>`). The following example shows how to do so:
2615

27-
[source,xml,indent=0,subs="verbatim,quotes"]
28-
----
29-
<bean class="org.springframework.jms.listener.endpoint.JmsMessageEndpointManager">
30-
<property name="resourceAdapter" ref="resourceAdapter"/>
31-
<property name="activationSpec">
32-
<bean class="org.apache.activemq.ra.ActiveMQActivationSpec">
33-
<property name="destination" value="myQueue"/>
34-
<property name="destinationType" value="jakarta.jms.Queue"/>
35-
</bean>
36-
</property>
37-
<property name="messageListener" ref="myMessageListener"/>
38-
</bean>
39-
----
40-
41-
Using Spring's `ResourceAdapterFactoryBean`, you can configure the target `ResourceAdapter`
42-
locally, as the following example shows:
43-
44-
[source,xml,indent=0,subs="verbatim,quotes"]
45-
----
46-
<bean id="resourceAdapter" class="org.springframework.jca.support.ResourceAdapterFactoryBean">
47-
<property name="resourceAdapter">
48-
<bean class="org.apache.activemq.ra.ActiveMQResourceAdapter">
49-
<property name="serverUrl" value="tcp://localhost:61616"/>
50-
</bean>
51-
</property>
52-
<property name="workManager">
53-
<bean class="org.springframework.jca.work.SimpleTaskWorkManager"/>
54-
</property>
55-
</bean>
56-
----
57-
58-
The specified `WorkManager` can also point to an environment-specific thread pool --
59-
typically through a `SimpleTaskWorkManager` instance's `asyncTaskExecutor` property.
60-
Consider defining a shared thread pool for all your `ResourceAdapter` instances
61-
if you happen to use multiple adapters.
62-
63-
In some environments, you can instead obtain the entire `ResourceAdapter` object from JNDI
64-
(by using `<jee:jndi-lookup>`). The Spring-based message listeners can then interact with
65-
the server-hosted `ResourceAdapter`, which also use the server's built-in `WorkManager`.
16+
include-code::./AlternativeJmsConfiguration[tag=snippet,indent=0]
6617

6718
See the javadoc for {spring-framework-api}/jms/listener/endpoint/JmsMessageEndpointManager.html[`JmsMessageEndpointManager`],
6819
{spring-framework-api}/jms/listener/endpoint/JmsActivationSpecConfig.html[`JmsActivationSpecConfig`],

0 commit comments

Comments
 (0)