Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Extended documentation with common use cases.

...

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

...

Common cases

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
public class MyRouteConfiguration extends CamelConfiguration {

    @Autowire
    private MyRouteBuilder myRouteBuilder;

    @Autowire
    private MyAnotherRouteBuilder myAnotherRouteBuilder;

    @Override
    public List<RouteBuilder> routes() {
        return Arrays.asList(myRouteBuilder, myAnotherRouteBuilder);
    } 

}

Starting from Camel 2.13.0 you can skip the routes() definition, and fall back to the RouteBuilder instances located in the Spring context.

Code Block
java
java

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

Other examples

The following example using Java Config is actually a Spring Testing based unit test.

...