Spring モジュールの移行

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

  • ユーザーは Mule Runtime で使用できる Spring バージョンおよびモジュールに制限されていた。

  • ランタイムでの変更またはアップグレードが、定義するアプリケーションに影響する可能性がある。

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

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

    <flow>
        ...
    </flow>
</mule>
XML ファイルの例や設定手順の詳細は、​「Spring モジュール」​を参照してください。

Mule 4 での Spring モジュール連動関係の設定

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

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

Spring 連動関係を設定して共有ライブラリとして宣言するには、アプリケーションの ​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>

Spring モジュールを Mule 4 プロジェクトに追加します。

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

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