This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 7484815 Polished docs 7484815 is described below commit 74848159a51176ad64e77d8ce9e03f5cfc1e962b Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sat Mar 10 14:11:05 2018 +0100 Polished docs --- .../src/main/docs/spring-boot.adoc | 241 +++++++++------------ 1 file changed, 107 insertions(+), 134 deletions(-) diff --git a/components/camel-spring-boot/src/main/docs/spring-boot.adoc b/components/camel-spring-boot/src/main/docs/spring-boot.adoc index 4e2dcc6..cd77c13 100644 --- a/components/camel-spring-boot/src/main/docs/spring-boot.adoc +++ b/components/camel-spring-boot/src/main/docs/spring-boot.adoc @@ -1,9 +1,11 @@ [[SpringBoot-SpringBoot]] -Spring Boot -~~~~~~~~~~~ +== Spring Boot *Available as of Camel 2.15* +NOTE: Camel only supports Spring Boot 1.5.x. Support for Spring Boot 2 is planned +for Camel 2.22 which is scheduled for summer 2018. + Spring Boot component provides auto-configuration for Apache Camel. Our opinionated auto-configuration of the Camel context auto-detects Camel routes available in the Spring context and registers the key Camel @@ -14,21 +16,20 @@ Maven users will need to add the following dependency to their `pom.xml` in order to use this component: [source,xml] ------------------------------------------------------------------------------------------------- +---- <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-spring-boot</artifactId> <version>${camel.version}</version> <!-- use the same version as your Camel core version --> </dependency> ------------------------------------------------------------------------------------------------- +---- `camel-spring-boot` jar comes with the `spring.factories` file, so as soon as you add that dependency into your classpath, Spring Boot will automatically auto-configure Camel for you. [[SpringBoot-CamelSpringBootStarter]] -Camel Spring Boot Starter -^^^^^^^^^^^^^^^^^^^^^^^^^ +=== Camel Spring Boot Starter *Available as of Camel 2.17* @@ -42,18 +43,18 @@ application] in the source code also. To use the starter, add the following to your spring boot pom.xml file: [source,xml] ------------------------------------------------------- +---- <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-spring-boot-starter</artifactId> - <version>2.17.0</version> + <version>${camel.version}</version> <!-- use the same version as your Camel core version --> </dependency> ------------------------------------------------------- +---- Then you can just add classes with your Camel routes such as: [source,java] ------------------------------------------------- +---- package com.example; import org.apache.camel.builder.RouteBuilder; @@ -67,7 +68,7 @@ public class MyRoute extends RouteBuilder { from("timer:foo").to("log:bar"); } } ------------------------------------------------- +---- Then these routes will be started automatically. @@ -75,8 +76,7 @@ You can customize the Camel application in the `application.properties` or `application.yml` file. [[SpringBoot-Auto-configuredCamelcontext]] -Auto-configured Camel context -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +=== Auto-configured Camel context The most important piece of functionality provided by the Camel auto-configuration is `CamelContext` instance. @@ -87,7 +87,7 @@ context (under `camelContext` bean name), so you can access it just as any other Spring bean. [source,java] ----------------------------------------------- +---- @Configuration public class MyAppConfig { @@ -100,11 +100,10 @@ public class MyAppConfig { } } ----------------------------------------------- +---- [[SpringBoot-Auto-detectingCamelroutes]] -Auto-detecting Camel routes -^^^^^^^^^^^^^^^^^^^^^^^^^^^ +=== Auto-detecting Camel routes Camel auto-configuration collects all the `RouteBuilder` instances from the Spring context and automatically injects them into the provided @@ -113,7 +112,7 @@ Boot starter is as simple as adding the `@Component` annotated class to your classpath: [source,java] ----------------------------------------------- +---- @Component public class MyRouter extends RouteBuilder { @@ -123,14 +122,12 @@ public class MyRouter extends RouteBuilder { } } ----------------------------------------------- +---- - + -...or creating a new route `RouteBuilder` bean in your `@Configuration` -class: +Or creating a new route `RouteBuilder` bean in your `@Configuration` class: [source,java] --------------------------------------------------- +---- @Configuration public class MyRouterConfiguration { @@ -145,27 +142,26 @@ public class MyRouterConfiguration { }; } - + } --------------------------------------------------- +---- [[SpringBoot-Camelproperties]] -Camel properties -^^^^^^^^^^^^^^^^ +=== Camel properties Spring Boot auto-configuration automatically connects to http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config[Spring Boot external configuration] (like properties placeholders, OS environment variables or system properties) with -the <<properties-component,Camel properties support>>. It basically means +the Camel properties support. It basically means that any property defined in `application.properties` file: -[source,xml] -------------------------- +[source,text] +---- route.from = jms:invoices -------------------------- +---- -...or set via system property... +Or set via system property: [source,xml] ----------------------------------------------------------- @@ -175,7 +171,7 @@ java -Droute.to=jms:processed.invoices -jar mySpringApp.jar ...can be used as placeholders in Camel route: [source,java] ----------------------------------------------- +---- @Component public class MyRouter extends RouteBuilder { @@ -185,23 +181,20 @@ public class MyRouter extends RouteBuilder { } } ----------------------------------------------- +---- [[SpringBoot-CustomCamelcontextconfiguration]] -Custom Camel context configuration -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +=== Custom Camel context configuration If you would like to perform some operations on `CamelContext` bean created by Camel auto-configuration, register `CamelContextConfiguration` instance in your Spring context: [source,java] ---------------------------------------------------------- +---- @Configuration public class MyAppConfig { - ... - @Bean CamelContextConfiguration contextConfiguration() { return new CamelContextConfiguration() { @@ -213,40 +206,37 @@ public class MyAppConfig { } } ---------------------------------------------------------- +---- -Method -C`amelContextConfiguration#``beforeApplicationStart(CamelContext)` will +Method beforeApplicationStart` will be called just before the Spring context is started, so the `CamelContext` instance passed to this callback is fully auto-configured. You can add many instances of -C`amelContextConfiguration` into your Spring context - all of them will +`CamelContextConfiguration` into your Spring context - all of them will be executed. [[SpringBoot-DisablingJMX]] -Disabling JMX -^^^^^^^^^^^^^ +=== Disabling JMX To disable JMX of the auto-configured `CamelContext` use `camel.springboot.jmxEnabled` property (JMX is enabled by default). For example you could add the following property to your `application.properties` file: -[source,xml] ------------------------------------ -camel.springboot.jmxEnabled = false ------------------------------------ +[source,text] +---- +camel.springboot.jmx-enabled = false +---- [[SpringBoot-Auto-configuredconsumerandproducertemplates]] -Auto-configured consumer and producer templates -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +=== Auto-configured consumer and producer templates Camel auto-configuration provides pre-configured `ConsumerTemplate` and `ProducerTemplate` instances. You can simply inject them into your Spring-managed beans: [source,java] ------------------------------------------------------------------------------------------- +---- @Component public class InvoiceProcessor { @@ -255,6 +245,7 @@ public class InvoiceProcessor { @Autowired private ConsumerTemplate consumerTemplate; + public void processNextInvoice() { Invoice invoice = consumerTemplate.receiveBody("jms:invoices", Invoice.class); ... @@ -262,27 +253,26 @@ public class InvoiceProcessor { } } ------------------------------------------------------------------------------------------- +---- By default consumer templates and producer templates come with the endpoint cache sizes set to 1000. You can change those values via the following Spring properties: -[source,xml] ------------------------------------------------- -camel.springboot.consumerTemplateCacheSize = 100 -camel.springboot.producerTemplateCacheSize = 200 ------------------------------------------------- +[source,text] +---- +camel.springboot.consumer-template-cache-size = 100 +camel.springboot.producer-template-cache-size = 200 +---- [[SpringBoot-Auto-configuredTypeConverter]] -Auto-configured TypeConverter -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +=== Auto-configured TypeConverter Camel auto-configuration registers a `TypeConverter` instance named `typeConverter` in the Spring context. [source,java] -------------------------------------------------------------- +---- @Component public class InvoiceProcessor { @@ -295,11 +285,10 @@ public class InvoiceProcessor { } } -------------------------------------------------------------- +---- [[SpringBoot-SpringtypeconversionAPIbridge]] -Spring type conversion API bridge -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +====Spring type conversion API bridge Spring comes with the powerful http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html#core-convert[type @@ -312,7 +301,7 @@ ones. With this approach you can enjoy both Camel and Spring converters accessed via Camel `TypeConverter` API: [source,java] ---------------------------------------------------------------------------- +---- @Component public class InvoiceProcessor { @@ -325,9 +314,7 @@ public class InvoiceProcessor { } } ---------------------------------------------------------------------------- - - +---- Under the hood Camel Spring Boot delegates conversion to the Spring's `ConversionService` instances available in the application context. If @@ -335,22 +322,20 @@ no `ConversionService` instance is available, Camel Spring Boot auto-configuration will create one for you. [[SpringBoot-Disablingtypeconversionsfeatures]] -Disabling type conversions features -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +=== Disabling type conversions features If you don't want Camel Spring Boot to register type-conversions related features (like `TypeConverter` instance or Spring bridge) set the -`camel.springboot.typeConversion` property to `false`. +`camel.springboot.type-conversion` property to `false`. -[source,xml] ---------------------------------------- -camel.springboot.typeConversion = false ---------------------------------------- +[source,text] +---- +camel.springboot.type-conversion = false +---- [[SpringBoot-Blockingmainthread]] -Blocking main thread -^^^^^^^^^^^^^^^^^^^^ +=== Blocking main thread This feature is available starting from Camel *2.15.2*. Camel applications extending FatJarRouter by default block the main thread of @@ -363,18 +348,17 @@ your application using `CamelSpringBootApplicationController#blockMainThread()` method. [source,java] ------------------------------------------------------------------------------------------------------- +---- public static void main(String... args) { ApplicationContext applicationContext = new SpringApplication(MyCamelApplication.class).run(args); CamelSpringBootApplicationController applicationController = applicationContext.getBean(CamelSpringBootApplicationController.class); applicationController.blockMainThread(); } ------------------------------------------------------------------------------------------------------- +---- [[SpringBoot-AddingXMLroutes]] -Adding XML routes -^^^^^^^^^^^^^^^^^ +=== Adding XML routes By default you can put Camel XML routes in the classpath under the directory camel, which camel-spring-boot will auto detect and include. @@ -382,75 +366,64 @@ From *Camel 2.17* onwards you can configure the directory name or turn this off using the configuration option [source,java] ------------------------------------------------------------ +---- // turn off -camel.springboot.xmlRoutes = false +camel.springboot.xml-routes = false // scan in the com/foo/routes classpath -camel.springboot.xmlRoutes = classpath:com/foo/routes/*.xml ------------------------------------------------------------ +camel.springboot.xml-routes = classpath:com/foo/routes/*.xml +---- The XML files should be Camel XML routes (not CamelContext) such as [source,xml] ---------------------------------------------------------- - <routes xmlns="http://camel.apache.org/schema/spring"> - <route id="test"> - <from uri="timer://trigger"/> - <transform> - <simple>ref:myBean</simple> - </transform> - <to uri="log:out"/> - </route> - </routes> ---------------------------------------------------------- +---- +<routes xmlns="http://camel.apache.org/schema/spring"> + <route id="test"> + <from uri="timer://trigger"/> + <transform> + <simple>ref:myBean</simple> + </transform> + <to uri="log:out"/> + </route> +</routes> +---- [[SpringBoot-AddingREST]] -Adding XML Rest-DSL -^^^^^^^^^^^^^^^^^^^ +=== Adding XML Rest-DSL By default you can put Camel Rest-DSL XML routes in the classpath under the directory camel-rest, which camel-spring-boot will auto detect and include. You can configure the directory name or turn this off using the configuration option -[source,java] ------------------------------------------------------------ +[source,text] +---- // turn off -camel.springboot.xmlRests = false +camel.springboot.xml-rests = false // scan in the com/foo/routes classpath -camel.springboot.xmlRests = classpath:com/foo/rests/*.xml ------------------------------------------------------------ +camel.springboot.xml-rests = classpath:com/foo/rests/*.xml +---- The Rest-DSL XML files should be Camel XML rests (not CamelContext) such as [source,xml] ---------------------------------------------------------- - <rests xmlns="http://camel.apache.org/schema/spring"> - <rest> - <post uri="/persons"> - <to uri="direct:postPersons"/> - </post> - <get uri="/persons"> - <to uri="direct:getPersons"/> - </get> - <get uri="/persons/{personId}"> - <to uri="direct:getPersionId"/> - </get> - <put uri="/persons/{personId}"> - <to uri="direct:putPersionId"/> - </put> - <delete uri="/persons/{personId}"> - <to uri="direct:deletePersionId"/> - </delete> - </rest> - </rests> ---------------------------------------------------------- - -[[SpringBoot-SeeAlso]] -See Also -^^^^^^^^ - -* Configuring Camel -* Component -* Endpoint -* Getting Started - +---- +<rests xmlns="http://camel.apache.org/schema/spring"> + <rest> + <post uri="/persons"> + <to uri="direct:postPersons"/> + </post> + <get uri="/persons"> + <to uri="direct:getPersons"/> + </get> + <get uri="/persons/{personId}"> + <to uri="direct:getPersionId"/> + </get> + <put uri="/persons/{personId}"> + <to uri="direct:putPersionId"/> + </put> + <delete uri="/persons/{personId}"> + <to uri="direct:deletePersionId"/> + </delete> + </rest> +</rests> +---- -- To stop receiving notification emails like this one, please contact davscl...@apache.org.