Migrating the Spring Module | MuleSoft Documentation
# 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 own 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.   
---  
## Configure Spring Module Dependencies in Mule 4
The Spring Module does not include any Spring dependency, you need to configure the dependencies you want to use.
Because Mule connector dependencies are isolated from each other and from the Mule application dependencies, after configuring Spring dependencies you also have to declare them as shared libraries to make these dependencies available for the Spring Module.
To configure Spring dependencies and also declare them as shared libraries, add the following to your application’s `pom.xml`:
```
<!-- These Properties define the plugin versions to use -->
<properties>
 <springVersion>4.3.17.RELEASE</springVersion>
 <springSecurityVersion>4.2.6.RELEASE</springSecurityVersion>
 <mule.maven.plugin.version>3.4.0</mule.maven.plugin.version>
</properties>
<build>
 <plugins>
 <!-- Only used to declare the shared libraries-->
  <plugin>
   <groupId>org.mule.tools.maven</groupId>
   <artifactId>mule-maven-plugin</artifactId>
   <version>${mule.maven.plugin.version}</version>
   <configuration>
    <!-- Configure the Spring dependencies as Shared Libraries -->
    <sharedLibraries>
     <sharedLibrary>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-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-core</artifactId>
     </sharedLibrary>
     <sharedLibrary>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-config</artifactId>
     </sharedLibrary>
    </sharedLibraries>
   </configuration>
  </plugin>
 </plugins>
</build>
<!-- These are the Spring dependencies to configure -->
<dependencies>
 <dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-core</artifactId>
  <version>${springSecurityVersion}</version>
 </dependency>
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-beans</artifactId>
  <version>${springVersion}</version>
 </dependency>
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context</artifactId>
  <version>${springVersion}</version>
 </dependency>
 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
  <version>${springVersion}</version>
 </dependency>
 <dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-config</artifactId>
  <version>${springSecurityVersion}</version>
 </dependency>
</dependencies>
```

## Add the Spring Module to your Mule 4 Project
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.2.0</version>
 <classifier>mule-plugin</classifier>
</dependency>
```

## See Also
  * Spring Module in Mule 4
  * Configure Shared Libraries in Mule 4
  * Class-loading Isolation in Mule 4