Contact Free trial Login

Migrating the Spring Module

Mule 3 allowed to define Spring beans as part of the Mule application using the Spring DSL directly. This approach 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 file and reference them through the Spring module.

Mule 3 example:
<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:
<mule>
    <spring:config name="springConfig" files="config/connection-factory-beans.xml"/>

    <flow>
        ...
    </flow>
</mule>
See Spring Module to find an example XML file and also further configuration instructions.

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:

 <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>
                         </sharedLibrary>
                         <sharedLibrary>
                             <groupId>org.springframework</groupId>
                             <artifactId>spring-beans</artifactId>
                         </sharedLibrary>
                         <sharedLibrary>
                             <groupId>org.springframework</groupId>
                             <artifactId>spring-context</artifactId>
                         </sharedLibrary>
                         <sharedLibrary>
                             <groupId>org.springframework</groupId>
                            <artifactId>spring-aop</artifactId>
                         </sharedLibrary>
                         <sharedLibrary>
                             <groupId>org.springframework.security</groupId>
                             <artifactId>spring-security-core</artifactId>
                         </sharedLibrary>
                         <sharedLibrary>
                             <groupId>org.springframework.security</groupId>
                             <artifactId>spring-security-config</artifactId>
                         </sharedLibrary>
                     </sharedLibraries>
                 </configuration>
             </plugin>
         </plugins>
     </build>

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

<dependency>
  <groupId>org.mule.modules</groupId>
  <artifactId>mule-spring-module</artifactId>
  <version>1.1.0</version> <!-- or newer -->
  <classifier>mule-plugin</classifier>
</dependency>

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub