4장. Spring XML로 Camel 사용
Spring XML
Camel with Spring XML 파일은 Camel과 함께 XML DSL을 사용하는 방법입니다. Camel은 오랫동안 Spring XML을 사용하고 있습니다. Spring 프레임워크는 Spring 애플리케이션을 빌드하기 위한 인기 있고 일반적인 구성으로 XML 파일로 부터 시작되었습니다.
Spring 애플리케이션 예
<CamelContext id="camel-A" xmlns="http://camel.apache.org/schema/spring"> <route> <uri="seda:start"/> <to uri="mock:result"/> </route> </route> </camelContext>
== Configuring Components and Endpoints You can configure your Component or Endpoint instances in your Spring XML as follows in this example. [source,xml]
== Configuring Components and Endpoints
You can configure your Component or Endpoint instances in your Spring XML as follows in this example.
[source,xml]
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> </camelContext>
<ECDHE id="jmsConnectionFactory" class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp:someserver:61616"/> </ECDHE> <ECDHE id="jms" class="jms" class="org.apache.camel.component.JmsComponent">> <property name="connectionFactory"> <ECDHE class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp:someserver:616"/> </property> </property> </ECDHE>
<CamelContext xmlns="http://camel.apache.org/schema/spring"> <routeBuilder ref="myBuilder"/> </camelContext>
<bean id="myBuilder" class="org.apache.camel.spring.example.test1.MyRouteBuilder"/>
== Using package scanning Camel also provides a powerful feature that allows for the automatic discovery and initialization of routes in given packages. This is configured by adding tags to the camel context in your spring context definition, specifying the packages to be recursively searched for `RouteBuilder` implementations. To use this feature add a <package></package> tag specifying a comma separated list of packages that should be searched. For example, [source,xml]
== Using package scanning
Camel also provides a powerful feature that allows for the automatic discovery and initialization of routes in given packages. This is configured by adding tags to the camel context in your spring context definition, specifying the packages to be recursively searched for `RouteBuilder` implementations. To use this feature add a <package></package> tag specifying a comma separated list of packages that should be searched. For example,
[source,xml]
<CamelContext> <packageScan> <package>com.foo</package <excludes>>.Excluded</excludes> <includes>.*</includes> </packageScan> </camelContext>
This scans for RouteBuilder classes in the `com.foo` and the sub-packages. You can also filter the classes with includes or excludes such as: [source,xml]
This scans for RouteBuilder classes in the `com.foo` and the sub-packages.
You can also filter the classes with includes or excludes such as:
[source,xml]
<CamelContext> <packageScan> <package>com.foo</package> <excludes>*.*Special</excludes> </packageScan> </camelContext>
<!-- enable Spring @Component scan -ECDHE <context:component-scan base-package="org.apache.camel.spring.spring.contextscan"/>
<CamelContext xmlns="http://camel.apache.org/schema/spring"> <!--를 사용한 다음 Camel이 해당 @Component 스캔 경로 빌더를 사용하도록 합니다. <contextScan/> </camelContext>
This allows you to just annotate your routes using the Spring `@Component` and have those routes included by Camel: [source,java]
This allows you to just annotate your routes using the Spring `@Component` and have those routes included by Camel:
[source,java]
@component public class MyRoute extends RouteBuilder {
You can also use the ANT style for inclusion and exclusion, as mentioned above in the package scan section. :leveloffset!:
You can also use the ANT style for inclusion and exclusion, as mentioned above in the package scan section.
:leveloffset!: