5.3. 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-starterやcamel-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.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 Blueprint file from the classpath that contains the Camel XML DSL @ImportResource({"classpath:blueprint/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 やメモリー使用量などのリソースを制限するためにすべてのクイックスタートで使用されます。