You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduce Java-based Spring Integration configuration as an
alternative to the existing XML configuration. The new
EnricherConfiguration class uses `@Configuration` and Integration
DSL to define three enricher flows demonstrating different
enrichment strategies.
The UserGateway interface uses `@MessagingGateway` to provide a
simple interface for clients to invoke enricher flows. The
application.properties file sets `java-config` as the default
profile, allowing users to run the sample with Java configuration
out of the box.
The Main class now supports profile-based configuration switching
to load either Java or XML configuration. Tests have been updated
to verify both configuration modes work correctly, with helper
methods extracted to reduce code duplication.
The XML configuration remains available by explicitly activating
the `xml-config` profile, maintaining backward compatibility.
All samples can now run using gradlew :enricher:run. Was broken before
Copy file name to clipboardExpand all lines: basic/enricher/README.md
+49-10Lines changed: 49 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,34 +3,73 @@ Spring Integration - Enricher Sample
3
3
4
4
# Overview
5
5
6
-
This sample demonstrates how the Enricher components can be used.
6
+
This sample demonstrates how the Content Enricher pattern can be used in Spring Integration. The Content Enricher allows you to augment a message with additional data from an external source without requiring the original sender to know about the enrichment process.
7
+
8
+
This sample supports both **XML-based** and **Java-based** Spring Integration configurations. You can select which configuration to use by setting the active Spring profile.
9
+
10
+
## Configuration Options
11
+
12
+
This sample supports two configuration modes:
13
+
14
+
***Java Configuration** (`java-config` profile) - Uses Java `@Configuration` classes from the `config` package. This is the **default** mode.
15
+
***XML Configuration** (`xml-config` profile) - Uses XML configuration files from `META-INF/spring/integration/`
16
+
17
+
### Profile Selection
18
+
19
+
Only one configuration profile should be active at a time. The `java-config` and `xml-config` profiles are mutually exclusive.
20
+
21
+
* If no profile is explicitly provided, `java-config` is used by default (as configured in `application.properties`).
22
+
* To use XML configuration, explicitly activate the `xml-config` profile at runtime.
7
23
8
24
# Getting Started
9
25
10
-
You can run the sample application by either
26
+
## Using Java Configuration (Default)
11
27
12
-
* running the "Main" class from within STS (Right-click on Main class --> Run As --> Java Application)
13
-
* or from the command line execute:
28
+
The sample uses Java configuration by default. You can run the sample application by either:
29
+
30
+
* Running the "Main" class from within your IDE (Right-click on Main class --> Run As --> Java Application)
31
+
* Or from the command line execute:
14
32
15
33
$ gradlew :enricher:run
16
34
17
-
This example illustrates the usage of the Content Enricher.
35
+
In this mode, the application context is defined using Spring Integration Java configuration classes instead of XML. The configuration classes are located in the `org.springframework.integration.samples.enricher.config` package.
36
+
37
+
## Using XML Configuration
38
+
39
+
To run the sample with XML configuration, activate the `xml-config` profile:
40
+
41
+
* From your IDE, set the system property: `-Dspring.profiles.active=xml-config`
This mode uses the legacy XML-based wiring from `spring-integration-context.xml`.
47
+
48
+
# How It Works
49
+
50
+
This example illustrates the usage of the Content Enricher pattern.
18
51
19
-
Once the application has started, please execute the various Content Enricher examples by
52
+
Once the application has started, please execute the various Content Enricher examples by:
20
53
21
54
* entering 1 + Enter
22
55
* entering 2 + Enter
23
56
* entering 3 + Enter
24
57
25
58
3 different message flows are triggered. For use-cases 1+2 a **User** object containing only the **username** is passed in. For use-case 3 a Map with the **username** key is passed in and enriched with the **User** object using the **user** key:
26
59
27
-
* 1: In the *Enricher*, pass the full **User** object to the **request channel**.
28
-
* 2: In the *Enricher*, pass only the **username** to the **request channel** by using the **request-payload-expression** attribute.
29
-
* 3: In the *Enricher*, pass only the username to the **request channel**, executing the same Service Activator as in **2**.
60
+
***1**: In the *Enricher*, pass the full **User** object to the **request channel**.
61
+
***2**: In the *Enricher*, pass only the **username** to the **request channel** by using the **request-payload-expression** attribute.
62
+
***3**: In the *Enricher*, pass only the username to the **request channel**, executing the same Service Activator as in **2**.
63
+
64
+
## About This Pattern
65
+
66
+
Spring Integration is moving toward Java configuration as the primary style for new development, while XML configuration remains available for users who prefer that style or are migrating older systems. This sample demonstrates how both approaches can coexist in the same project using Spring profiles to select the desired configuration mode at runtime.
67
+
68
+
This pattern (Java first, XML as an alternative) is being applied across other samples in this repository, using `basic/barrier` as a reference model.
30
69
31
70
# Resources
32
71
33
72
For help please take a look at the Spring Integration documentation:
0 commit comments