Chapter 4. Develop an Application for the Spring Boot Image

download PDF

4.1. Overview

This chapter explains how to develop applications for the Spring Boot image.

4.2. Create a Spring Boot Project using Maven Archetype

To create a Spring Boot project, follow these steps:

  1. Go to the appropriate directory on your system.
  2. In a shell prompt, enter the following the mvn command to create a Spring Boot project

    mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate \
      -DarchetypeCatalog= \
      -DarchetypeGroupId=org.jboss.fuse.fis.archetypes \
      -DarchetypeArtifactId=spring-boot-camel-xml-archetype \

    The archetype plug-in switches to interactive mode to prompt you for the remaining fields

    Define value for property 'groupId': : org.example.fis
    Define value for property 'artifactId': : fuse72-spring-boot
    Define value for property 'version':  1.0-SNAPSHOT: :
    Define value for property 'package':  org.example.fis: :
    [INFO] Using property: spring-boot-version = 1.5.16.RELEASE
    Confirm properties configuration:
    groupId: org.example.fis
    artifactId: fuse72-spring-boot
    version: 1.0-SNAPSHOT
    package: org.example.fis
    spring-boot-version: 1.5.16.RELEASE
     Y: :

    When prompted, enter org.example.fis for the groupId value and fuse72-spring-boot for the artifactId value. Accept the defaults for the remaining fields.

Then, follow the instructions in the quickstart on how to build and deploy the example.


For the full list of available Spring Boot archetypes, see Section 4.4, “Spring Boot Archetype Catalog”.

4.3. Structure of the Camel Spring Boot Application

The directory structure of a Camel Spring Boot application is as follows:

  ├── pom.xml
  ├── configuration
  │   └── settings.xml
  └── src
      ├── main
      │   ├── fabric8
      │   │   └── deployment.yml
      │   ├── java
      │   │   └── org
      │   │       └── example
      │   │           └── fis
      │   │               ├──
      │   │               └──
      │   └── resources
      │       ├──
      │       ├── logback.xml
      │       └── spring
      │           └── camel-context.xml
      └── test
          └── java
              └── org
                  └── example
                      └── fis

Where the following files are important for developing an application:

Includes additional dependencies. Camel components that are compatible with Spring Boot are available in the starter version, for example camel-jdbc-starter or camel-infinispan-starter. Once the starters are included in the pom.xml they are automatically configured and registered with the Camel content at boot time. Users can configure the properties of the components using the file.

Allows you to externalize your configuration and work with the same application code in different environments. For details, see Externalized Configuration

For example, in this Camel application you can configure certain properties such as name of the application or the IP addresses, and so on.



# the options from org.apache.camel.spring.boot.CamelConfigurationProperties can be configured here

# lets listen on all ports to ensure we can be invoked from the pod IP

# lets use a different management port in case you need to listen to HTTP requests on 8080

# disable all management endpoints except health
endpoints.enabled = false = true

It is an important file to run your application. As a user you will import here a file camel-context.xml to configure routes using the Spring DSL.

The file specifies the @SpringBootApplication annotation, which is equivalent to @Configuration, @EnableAutoConfiguration and @ComponentScan with their default attributes.

// load regular Blueprint file from the classpath that contains the Camel XML DSL

It must have a main method to run the Spring Boot application.

public class Application {
     * A main method to start this application.
    public static void main(String[] args) {, args);


The src/main/resources/spring/camel-context.xml is an important file for developing application as it contains the Camel routes.


You can find more information on developing Spring-Boot applications at Developing your first Spring Boot Application


Provides additional configuration that is merged with the default OpenShift configuration file generated by the fabric8-maven-plugin.


This file is not used part of Spring Boot application but it is used in all quickstarts to limit the resources such as CPU and memory usage.

4.4. Spring Boot Archetype Catalog

The Spring Boot Archetype catalog includes the following examples.

Table 4.1. Spring Boot Maven Archetypes


Demonstrates how to use Apache Camel with Spring Boot based on a fabric8 Java base image.


Demonstrates how to connect a Spring-Boot application to an ActiveMQ broker and use JMS messaging between two Camel routes using Kubernetes or OpenShift.


Demonstrates how to configure a Spring-Boot application using Kubernetes ConfigMaps and Secrets.


Demonstrates how to use Apache Camel to integrate a Spring-Boot application running on Kubernetes or OpenShift with a remote Kie Server.


Demonstrates how to connect a Spring-Boot application to a JBoss Data Grid or Infinispan server using the Hot Rod protocol.


Demonstrates how to use SQL via JDBC along with Camel’s REST DSL to expose a RESTful API.


Demonstrates how to connect Apache Camel to a remote JBoss Data Virtualization (or Teiid) Server using the JDBC protocol.


Spring Boot, Camel and XA Transactions. This example demonstrates how to run a Camel Service on Spring-Boot that supports XA transactions on two external transactional resources: a JMS resource (A-MQ) and a database (PostgreSQL). This quickstart requires the PostgreSQL database and the A-MQ broker have been deployed and running first, one simple way to run them is to use the templates provided in the Openshift service catalog


Demonstrates how to configure Camel routes in Spring Boot via a Blueprint configuration file.


Demonstrates how to use Apache CXF with Spring Boot based on a fabric8 Java base image. The quickstart uses Spring Boot to configure an application that includes a CXF JAXRS endpoint with Swagger enabled.


Demonstrates how to use Apache CXF with Spring Bootbased on a fabric8 Java base image. The quickstart uses Spring Boot to configure an application that includes a CXF JAXWS endpoint.


A Technology Preview quickstart is also available. The Spring Boot Camel XA Transactions quickstart demonstrates how to use Spring Boot to run a Camel service that supports XA transactions. This quickstart shows the use of two external transactional resources: a JMS (AMQ) broker and a database (PostgreSQL). You can find this quickstart here:

Technology Preview features are not supported with Red Hat production service level agreements (SLAs), might not be functionally complete, and Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process. For more information, see Red Hat Technology Preview features support scope.

4.5. Camel Starter Modules

4.5.1. Overview

Starters are Apache Camel modules intended to be used in Spring Boot applications. There is a camel-xxx-starter module for each Camel component (with a few exceptions listed below).

Starters meet the following requirements:

  • Allow auto-configuration of the component using native Spring Boot configuration system which is compatible with IDE tooling.
  • Allow auto-configuration of data formats and languages.
  • Manage transitive logging dependencies to integrate with Spring Boot logging system.
  • Include additional dependencies and align transitive dependencies to minimize the effort of creating a working Spring Boot application.

Each starter has its own integration test in tests/camel-itest-spring-boot, that verifies the compatibility with the current release of Spring Boot.

4.5.2. Using Camel Starter Modules

Apache Camel provides a starter module that allows you to develop Spring Boot applications using starters.

To use the Spring Boot starter:

  1. Add the following to your Spring Boot pom.xml file:

  2. Add classes with your Camel routes such as:

    package com.example;
    import org.apache.camel.builder.RouteBuilder;
    import org.springframework.stereotype.Component;
    public class MyRoute extends RouteBuilder {
        public void configure() throws Exception {

These routes will be started automatically.


To keep the main thread blocked so that Camel stays up, either include the spring-boot-starter-web dependency, or add camel.springboot.main-run-controller=true to your or application.yml file.

You can customize the Camel application in the or application.yml file with camel.springboot.* properties.

4.6. Unsupported Starter Modules

The following components do not have a starter because of compatibility issues:

  • camel-blueprint (intended for OSGi only)
  • camel-cdi (intended for CDI only)
  • camel-core-osgi (intended for OSGi only)
  • camel-ejb (intended for JEE only)
  • camel-eventadmin (intended for OSGi only)
  • camel-ibatis (camel-mybatis-starter is included)
  • camel-jclouds
  • camel-mina (camel-mina2-starter is included)
  • camel-paxlogging (intended for OSGi only)
  • camel-quartz (camel-quartz2-starter is included)
  • camel-spark-rest
  • camel-swagger (camel-swagger-java-starter is included)

4.7. BOM file for Spring Boot

The purpose of a Maven Bill of Materials (BOM) file is to provide a curated set of Maven dependency versions that work well together, saving you from having to define versions individually for every Maven artifact.

The Fuse BOM for Spring Boot offers the following advantages:

  • Defines versions for Maven dependencies, so that you do not need to specify the version when you add a dependency to your POM.
  • Defines a set of curated dependencies that are fully tested and supported for a specific version of Fuse.
  • Simplifies upgrades of Fuse.

Only the set of dependencies defined by a Fuse BOM are supported by Red Hat.

To incorporate a BOM file into your Maven project, specify a dependencyManagement element in your project’s pom.xml file (or, possibly, in a parent POM file), as shown in the following example:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project ...>

    <!-- configure the versions you want to use here -->


After specifying the BOM using the dependency management mechanism, it becomes possible to add Maven dependencies to your POM without specifying the version of the artifact. For example, to add a dependency for the camel-hystrix component, you would add the following XML fragment to the dependencies element in your POM:


Note how the Camel artifact ID is specified with the -starter suffix — that is, you specify the Camel Hystrix component as camel-hystrix-starter, not as camel-hystrix. The Camel starter components are packaged in a way that is optimized for the Spring Boot environment.

4.8. Spring Boot Maven plugin

The Spring Boot Maven plugin is provided by Spring Boot and it is a developer utility for building and running a Spring Boot project:

  • Building — create an executable Jar package for your Spring Boot application by entering the command mvn package in the project directory. The output of the build is placed in the target/ subdirectory of your Maven project.
  • Running — for convenience, you can run the newly-built application with the command, mvn spring-boot:start.

To incorporate the Spring Boot Maven plugin into your project POM file, add the plugin configuration to the project/build/plugins section of your pom.xml file, as shown in the following example:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project ...>

    <!-- configure the versions you want to use here -->

Red Hat logoGithubRedditYoutubeTwitter


Try, buy, & sell


About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.