Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

Migrating the Spring Module

Mule 3 allowed to define Spring beans as part of the Mule application using the Spring DSL directly. This approache requires Mule applications to be exposed to the Spring versions and components that the runtime uses internally. This causes two problems:

  • Users were limited to the Spring version and modules available in the Mule runtime.

  • Any changes or upgrades in the runtime can potentially affect applications defining

To fix this problem in Mule 4 we decided to package our Spring support as a separate module. So, instead of defining your Spring beans directly on your application, you now have to define them in their own file and reference them through the Spring module.

Mule 3 example

         
      
1
2
3
4
5
6
7
8
9
10
11
<mule>
    <spring:beans>
        <spring:bean name="xaConnectionFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory">
            <spring:property name="brokerURL" value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false" />
        </spring:bean>
    </spring:beans>

    <flow>
        ...
    </flow>
</mule>
Mule 4 example

         
      
1
2
3
4
5
6
7
<mule>
    <spring:config name="springConfig" files="config/connection-factory-beans.xml"/>

    <flow>
        ...
    </flow>
</mule>

The Spring module doesn’t ship with any particular Spring dependency. You can provide whatever ones you need by adding the following to your application’s pom.xml:


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 <properties>
    <springVersion>4.1.9.RELEASE</springVersion>
    <springSecurityVersion>4.0.4.RELEASE</springSecurityVersion>
</properties>

    <build>
         <plugins>
             <!-- Only used to declare the shared libraries-->
             <plugin>
                 <groupId>org.mule.tools.maven</groupId>
                 <artifactId>mule-maven-plugin</artifactId>
                 <version>1.0.0</version>
                 <configuration>
                     <sharedLibraries>
                         <sharedLibrary>
                             <groupId>org.springframework</groupId>
                             <artifactId>spring-core</artifactId>
                             <version>${springVersion}</version>
                         </sharedLibrary>
                         <sharedLibrary>
                             <groupId>org.springframework</groupId>
                             <artifactId>spring-beans</artifactId>
                             <version>${springVersion}</version>
                         </sharedLibrary>
                         <sharedLibrary>
                             <groupId>org.springframework</groupId>
                             <artifactId>spring-context</artifactId>
                             <version>${springVersion}</version>
                         </sharedLibrary>
                         <sharedLibrary>
                             <groupId>org.springframework</groupId>
                            <artifactId>spring-aop</artifactId>
                            <version>${springVersion}</version>
                         </sharedLibrary>
                         <sharedLibrary>
                             <groupId>org.springframework.security</groupId>
                             <artifactId>spring-security-core</artifactId>
                             <version>${springSecurityVersion}</version>
                         </sharedLibrary>
                         <sharedLibrary>
                             <groupId>org.springframework.security</groupId>
                             <artifactId>spring-security-config</artifactId>
                             <version>${springSecurityVersion}</version>
                         </sharedLibrary>
                     </sharedLibraries>
                 </configuration>
             </plugin>
         </plugins>
     </build>

To use the Spring module, simply add it to your application using the Studio palette or add the following dependency in your pom.xml file:


         
      
1
2
3
4
5
6
<dependency>
  <groupId>org.mule.modules</groupId>
  <artifactId>mule-spring-module</artifactId>
  <version>1.1.0</version> <!-- or newer -->
  <classifier>mule-plugin</classifier>
</dependency>

In this topic: