Spring Boot + Camel + JPA not working in Fabric8

235 views
Skip to first unread message

Benjamin Fayle

unread,
Oct 4, 2014, 7:52:52 AM10/4/14
to fab...@googlegroups.com
Has anyone managed to get Spring Boot + Camel + JPA working in Fabric8?

I made a simple app based on the Fabric8 Spring Boot Camel example but added JPA support.

If I comment out the annotations @EnableJpaRepositories and @EntityScan then Fabric8 no longer sees this as a Camel route.

I can't find anything in Fabric8 or Hawtio that explains what is going on. 

package io.fabric8.quickstarts.camel;

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.orm.jpa.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@Configuration
//@EnableJpaRepositories
//@EntityScan
public class CamelConfiguration {

    @Bean
    RouteBuilder routeBuilder() {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("timer://foo?fixedRate=true&period=5000").
                        setBody().constant("<hello>world!</hello>").
                        log(">>> ${body}");
            }
        };
    }

    // Collaborators fixtures
    @Autowired
    CamelContext camelContext;

}

I'm using this for the pom.xml:

<?xml version="1.0" encoding="UTF-8"?>


  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>io.fabric8.quickstarts</groupId>
    <artifactId>fabric8-quickstarts-springboot-parent</artifactId>
    <version>1.2.0.Beta4</version>
  </parent>

  <artifactId>springboot-camel</artifactId>

  <name>Fabric8 :: Quickstarts :: Spring-Boot :: Camel</name>
  <description>Shows how to use Camel with Spring Boot in the Java Container</description>

  <properties>
    <!-- Explicitly declaring the source encoding eliminates the following
               message: -->
    <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
        resources, i.e. build is platform dependent! -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <version.compiler.plugin>2.3.1</version.compiler.plugin>
    <version.maven-bundle-plugin>2.3.7</version.maven-bundle-plugin>

    <!-- maven-compiler-plugin -->
    <maven.compiler.target>1.7</maven.compiler.target>
    <maven.compiler.source>1.7</maven.compiler.source>

    <!-- the version of the BOM, defining all the dependency versions -->
    <fabric8.bom.version>1.2.0.Beta4</fabric8.bom.version>
    <fabric.version>1.2.0.Beta4</fabric.version>

    <spring-version>4.0.6.RELEASE</spring-version>
    <spring-boot-version>1.1.5.RELEASE</spring-boot-version>

    <!-- fabric8 deploy profile configuration -->
    <fabric8.profile>quickstarts-spring.boot-camel</fabric8.profile>
    <fabric8.parentProfiles>containers-java.spring.boot</fabric8.parentProfiles>
  </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.fabric8</groupId>
                <artifactId>process-spring-boot-bom</artifactId>
                <version>${fabric.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

  <dependencies>
    <!-- BOMs -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>${spring-boot-version}</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>

    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>process-spring-boot-container</artifactId>
    </dependency>
    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>process-spring-boot-starter-camel</artifactId>
    </dependency>
    <dependency>
        <groupId>io.fabric8</groupId>
        <artifactId>process-spring-boot-registry</artifactId>
    </dependency>

    <!-- Spring -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
    </dependency>

    <!-- Camel -->
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-spring</artifactId>
    </dependency>
    
    <!-- Database driver -->
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <!-- Compiler plugin enforces Java 1.7 compatibility and activates annotation processors -->
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>${maven.compiler.source}</source>
          <target>${maven.compiler.target}</target>
        </configuration>
      </plugin>

      <plugin>
          <!--
            this plugin will use the fabric.* properties to configure its behaviour
            see the Properties section here: http://fabric8.io/gitbook/mavenPlugin.html
          -->
          <groupId>io.fabric8</groupId>
          <artifactId>fabric8-maven-plugin</artifactId>
          <version>${fabric.version}</version>
      </plugin>
    </plugins>
  </build>

</project>

Henryk Konsek

unread,
Oct 4, 2014, 8:33:06 AM10/4/14
to Benjamin Fayle, fab...@googlegroups.com

Hi

I will take a look at your example after the weekend. Stay tuned :-)

Cheers.

--
You received this message because you are subscribed to the Google Groups "fabric8" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fabric8+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Henryk Konsek

unread,
Oct 6, 2014, 9:51:44 AM10/6/14
to Benjamin Fayle, fab...@googlegroups.com
Hi Benjamin,

>> Has anyone managed to get Spring Boot + Camel + JPA working in Fabric8?

Can you attach your Maven project here? I'm not sure if I get the
issue you have here. Can you make the project to fail on 'mvn clean
install'?

Cheers.

--
Henryk Konsek
http://henryk-konsek.blogspot.com

Benjamin Fayle

unread,
Oct 6, 2014, 10:35:10 AM10/6/14
to Henryk Konsek, fab...@googlegroups.com
The project doesn't  fail on that. It's when you deploy it to Fabric8 using mvn fabic8:deploy. It deploys successfully but If you look at the container created in hawtio it recognizes the Camel route with the lines commented. Comment them out and it no longer recognizes the Camel route. 
--

Benjamin Fayle 

CTO

tagga 
Connect. Profile. Engage c: 604-224-9393 
t: @tagga



Reply all
Reply to author
Forward
0 new messages