Как? - Apache Camel с конфигурацией Spring Boot и XML - PullRequest
0 голосов
/ 27 апреля 2018

У меня есть приложение, в котором я использую Spring boot MVC и Camel. ниже приведен код, который я запускаю.

@ComponentScan({"com.xyz.routes","com.xyz.web","com.xyz.security"})
@SpringBootApplication
//@ImportResource("classpath:META-INF/spring/camelContext.xml")
public class Application {

    public static void main(String[] args) { 
        ApplicationContext applicationContext  = SpringApplication.run(Application.class, args);
    }

Если я использую аннотацию @ImportResource выше (в настоящее время комментируется), маршруты верблюдов не запускаются.

Например, ниже без аннотации.

INFO | 27 Apr 2018 15:26:31,149 | [main] org.apache.camel.spring.SpringCamelContext - Total 1 routes, of which 1 are started. |  |  | (DefaultCamelContext.java:2834)
INFO | 27 Apr 2018 15:26:31,150 | [main] org.apache.camel.spring.SpringCamelContext - Apache Camel 2.17.0 (CamelContext: camel-1) started in 0.255 seconds |  |  | (DefaultCamelContext.java:2835)

И ниже две строки журнала после того, как я включил аннотацию.

INFO | 27 Apr 2018 15:30:56,755 | [main] org.apache.camel.spring.SpringCamelContext - Total 0 routes, of which 0 are started. |  |  | (DefaultCamelContext.java:2834)
INFO | 27 Apr 2018 15:30:56,755 | [main] org.apache.camel.spring.SpringCamelContext - Apache Camel 2.17.0 (CamelContext: mtmSender) started in 0.089 seconds |  |  | (DefaultCamelContext.java:2835)

Есть идеи, почему это не работает, когда я включаю аннотацию? Примечание. Общее количество маршрутов равно нулю.

Обратите внимание, что мне нужен XML-конфиг, потому что я планирую определить компоненты и свойства там позже.

Ниже приведен camelContext.xml

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
         ">

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
        <property name="locations">
            <list>
                <value>${application-default.properties}</value>
                <value>${application.properties}</value>
            </list>
        </property>
        <property name="ignoreUnresolvablePlaceholders" value="true"/>
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_NEVER" />
    </bean>
    <bean id="sampleBean" class="com.xyz.model.SampleBean" />

    <camelContext xmlns="http://camel.apache.org/schema/spring"  id="mtmSender">
        <properties>
            <property key="CamelLogDebugStreams" value="true"/>
        </properties>
    </camelContext>

</beans>

1 Ответ

0 голосов
/ 30 апреля 2018

После обсуждения с OP мы обнаружили, что проблема заключалась в смешении зависимостей Apache Camel с зависимостями Spring Boot 2.0.x.

Из-за некоторых критических изменений API в Spring Boot 2.0.x Apache Camel пока не поддерживает Spring Boot 2.0.

Это также упоминается в Замечания к выпуску Apache Camel 2.21.0

Этот выпуск поддерживает только Spring Boot 1.5.x. Поддержка Spring Boot 2.0.x появится в версии Camel 2.22, которая запланирована на начало лета 2018 года.

На данный момент решение заключается в использовании Spring Boot 1.5.x с Apache Camel.

POM с фактическими совместимыми зависимостями:

<dependencyManagement>
  <dependencies>
    <!-- Spring Boot BOM -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-dependencies</artifactId>
      <version>1.5.12.RELEASE</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
    <!-- Camel BOM -->
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-spring-boot-dependencies</artifactId>
      <version>2.21.0</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>

  <!-- Spring Boot -->
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-undertow</artifactId>
  </dependency>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
  </dependency>

  <!-- Camel -->
  <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-spring-boot-starter</artifactId>
  </dependency>
  <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-stream-starter</artifactId>
  </dependency>

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

<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <version>1.5.12.RELEASE</version>
      <executions>
        <execution>
          <goals>
            <goal>repackage</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...