6.2. Camel Spring Boot アプリケーションの構造

Camel Spring Boot アプリケーションのディレクトリー構造は以下のようになります。

  ├── LICENSE.md
  ├── pom.xml
  ├── README.md
  ├── configuration
  │   └── settings.xml
  └── src
      ├── main
      │   ├── fabric8
      │   │   └── deployment.yml
      │   ├── java
      │   │   └── org
      │   │       └── example
      │   │           └── fis
      │   │               ├── Application.java
      │   │               └── MyTransformer.java
      │   └── resources
      │       ├── application.properties
      │       ├── logback.xml
      │       └── spring
      │           └── camel-context.xml
      └── test
          └── java
              └── org
                  └── example
                      └── fis

このうち、アプリケーションの開発に重要なファイルは次のとおりです。

pom.xml
追加の依存関係が含まれます。Spring Boot と互換性のある Camel コンポーネントは、camel-jdbc-startercamel-infinispan-starter などのスターターバージョンを利用できます。pom.xml にスターターが含まれると、スターターは自動的に設定され、起動時に Camel コンテンツと登録されます。application.properties ファイルを使用すると、コンポーネントのプロパティーを設定できます。
application.properties

設定の外部化を可能にし、異なる環境で同じアプリケーションコードを使用して作業できるようになります。詳細は Externalized Configuration を参照してください。

たとえば、この Camel アプリケーションでアプリケーションの名前や IP アドレスなどの特定のプロパティーを設定できます。

application.properties

#spring.main.sources=org.example.fos

logging.config=classpath:logback.xml

# the options from org.apache.camel.spring.boot.CamelConfigurationProperties can be configured here
camel.springboot.name=MyCamel

# lets listen on all ports to ensure we can be invoked from the pod IP
server.address=0.0.0.0
management.address=0.0.0.0

# lets use a different management port in case you need to listen to HTTP requests on 8080
management.server.port=8081

# disable all management endpoints except health
endpoints.enabled = false
endpoints.health.enabled = true

Application.java

これはアプリケーションを実行するために重要なファイルです。ユーザーとして camel-context.xml ファイルをインポートし、Spring DSL を使用してルートを設定します。

Application.java file@SpringBootApplication アノテーションを指定します。このアノテーションは、デフォルトの属性を持つ @Configuration@EnableAutoConfiguration、および @ComponentScan と同等です。

Application.java

@SpringBootApplication
// load regular Spring XML file from the classpath that contains the Camel XML DSL
@ImportResource({"classpath:spring/camel-context.xml"})

Spring Boot アプリケーションを実行するには main メソッドが必要です。

Application.java

public class Application {
    /**
     * A main method to start this application.
     */
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

camel-context.xml

src/main/resources/spring/camel-context.xml は、Camel ルートが含まれる、アプリケーションの開発に重要なファイルです。

注記

Spring Boot アプリケーションの開発に関する詳細は、Developing your first Spring Boot Application を参照してください。

src/main/fabric8/deployment.yml

fabric8-maven-plugin によって生成されるデフォルトの OpenShift 設定ファイルにマージされる追加設定を提供します。

注記

このファイルは Spring Boot アプリケーションの一部として使用されませんが、CPU やメモリー使用量などのリソースを制限するためにすべてのクイックスタートで使用されます。