279.8.5.3. XML ファイルの使用
XML DSL を使用して Camel ルートを定義することもできますが、Spring または Blueprint を使用しないため、XML ファイルには Camel ルートのみを含めることができます。
web.xml では、以下のように "classpath"、"file"、または "http" の URL から指定できる XML ファイルを参照します。
<context-param> <param-name>routeBuilder-MyRoute</param-name> <param-value>classpath:routes/myRoutes.xml</param-value> </context-param>
<context-param>
<param-name>routeBuilder-MyRoute</param-name>
<param-value>classpath:routes/myRoutes.xml</param-value>
</context-param>
XML ファイルは以下のようになります。
routes/myRoutes.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- the xmlns="http://camel.apache.org/schema/spring" is needed --> <routes xmlns="http://camel.apache.org/schema/spring"> <route id="foo"> <from uri="direct:foo"/> <to uri="mock:foo"/> </route> <route id="bar"> <from uri="direct:bar"/> <to uri="mock:bar"/> </route> </routes>
<?xml version="1.0" encoding="UTF-8"?>
<!-- the xmlns="http://camel.apache.org/schema/spring" is needed -->
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="foo">
<from uri="direct:foo"/>
<to uri="mock:foo"/>
</route>
<route id="bar">
<from uri="direct:bar"/>
<to uri="mock:bar"/>
</route>
</routes>
XML ファイルでは、root タグは <routes> で、名前空間 "http://camel.apache.org/schema/spring" を使用する必要があります。この名前空間には名前に spring がありますが、過去の理由により、Spring は最初であり、XML DSL は時間内に戻るだけなので、過去の理由によるものです。実行時に Spring JAR は必要ありません。Camel 3.0 では、namespace の名前を汎用名に変更できます。