---
schema_version: "1"
id: 6295fe76d1f5058241b99e95d182bbe2341d925d68113eb14c49b1e0749fdcac
title: Spring Module の移行
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/mule-runtime/4.8/migration-module-spring.md
canonical_url: https://docs.mulesoft.com/jp/mule-runtime/4.8/migration-module-spring
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 66ec15b5049cb7cf40ae6d4ced04a6deeebfde340346008fe7bc30f76ebe51e3
description: MuleSoft Documentation Site
release: "4.8"
latest: false
---
# Spring Module の移行

Mule 3 では、Spring DSL を直接使用して、Mule アプリケーションの一部として Spring bean を定義できました。このアプローチでは、ランタイムの内部で使用される Spring バージョンおよびコンポーネントに、Mule アプリケーションを公開する必要があります。これにより 2 つの問題が発生します。

- ユーザーは Mule Runtime で使用できる Spring バージョンおよびモジュールに制限されていた。
- ランタイムでの変更またはアップグレードが、定義するアプリケーションに影響する可能性がある。

Mule 4 でこの問題を修正するために、Spring のサポートを別個のモジュールとしてパッケージすることにしました。したがって、Spring bean をアプリケーション上で直接定義する代わりに、独自のファイルで定義し、Spring Module を使用してそれらを参照する必要があります。

Mule 3 の例:

```xml
<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 の例:

```xml
<mule>
    <spring:config name="springConfig" files="config/connection-factory-beans.xml"/>

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

<table><tbody><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content">XML ファイルの例や設定手順の詳細は、​<a href="https://docs.mulesoft.com/spring-module/latest/" class="xref page">「Spring Module」</a>​を参照してください。</td></tr></tbody></table>

## [](#mule-4-での-spring-module-連動関係の設定)Mule 4 での Spring Module 連動関係の設定

Spring Module には Spring 連動関係は含まれませんので、連動関係を使用する場合は設定が必要です。

Mule Connector 連動関係は相互に、そして Mule アプリケーションの連動関係から分離されているため、設定した Spring 連動関係を Spring Module で使用するためには、設定後に共有ライブラリとして宣言する必要があります。

Spring 連動関係を設定して共有ライブラリとして宣言するには、アプリケーションの ​`pom.xml`​ に以下を追加します。

```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>
```

## [](#spring-module-を-mule-4-プロジェクトに追加します)Spring Module を Mule 4 プロジェクトに追加します。

Spring Module を使用するには、Studio のパレットを使用してアプリケーションに追加するか、​`pom.xml`​ ファイルで次の連動関係を追加します。

```xml
<dependency>
  <groupId>org.mule.modules</groupId>
  <artifactId>mule-spring-module</artifactId>
  <version>1.2.0</version>
  <classifier>mule-plugin</classifier>
</dependency>
```

## [](#関連情報)関連情報

- [Mule 4 の Spring Module](https://docs.mulesoft.com/spring-module/latest/)
- [Mule 4 での共有ライブラリの設定](https://docs.mulesoft.com/jp/mule-runtime/4.8/mmp-concept#configure-shared-libraries)
- [Mule 4 でのクラスローディングの分離](https://docs.mulesoft.com/jp/mule-runtime/4.8/about-classloading-isolation)