Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Deprecated JavaConfigContextLoader. See CAMEL-6917.

...

Note that this library is totally optional; you could just wire Camel together yourself with Java Config.

...

Configuration

The most common case of using JavaConfig with Camel would be to create configuration with defined list of routes to be used by router.

...

Code Block
java
java
@Configuration
@ComponentScan("com.example.routes")
public class MyRouteConfiguration extends CamelConfiguration {
}

Other examples

Testing

Since Camel 2.11.0 you can use the CamelSpringJUnit4ClassRunner with CamelSpringDelegatingTestContextLoader. This is the recommended way to test Java Config and Camel integrationThe following example using Java Config is actually a Spring Testing based unit test.

Wiki Markup
{snippet:lang=java|id=example|url=camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patternstest/FilterTestCamelSpringDelegatingTestContextLoaderTest.java}

The @ContextConfiguration annotation tells the Spring Testing framework to load the ContextConfig class as the configuration to use. This class derives from SingleRouteCamelConfiguration which is a helper Spring Java Config class which will configure the CamelContext for us and then register the RouteBuilder we create.

If you wish to create a collection of RouteBuilder instances then derive from the CamelConfiguration helper class and implement the routes() method. Keep in mind that (starting from the Camel 2.13.0) if you don't override routes() method, then CamelConfiguration will use all RouteBuilder instances available in the Spring context.

Since The following example using Java Config demonstrates how to test Java Config integration with Camel 2.11.0 you can use the CamelSpringJUnit4ClassRunner with CamelSpringDelegatingTestContextLoader like example using Java Config with CamelSpringJUnit4ClassRunner10 and lower. Keep in mind that JavaConfigContextLoader is deprecated and could be removed in the future versions of Camel on the behalf of the CamelSpringDelegatingTestContextLoader.

Wiki Markup
{snippet:lang=java|id=example|url=camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/

...

patterns/

...

FilterTest.java}

The @ContextConfiguration annotation tells the Spring Testing framework to load the ContextConfig class as the configuration to use. This class derives from SingleRouteCamelConfiguration which is a helper Spring Java Config class which will configure the CamelContext for us and then register the RouteBuilder we create.