camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henryk Konsek (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CAMEL-8482) Camel requires restart of Spring applicationcontext to fetch new values for properties managed by Spring Cloud
Date Tue, 24 Mar 2015 17:10:53 GMT

    [ https://issues.apache.org/jira/browse/CAMEL-8482?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14378168#comment-14378168
] 

Henryk Konsek commented on CAMEL-8482:
--------------------------------------

Actually I think that this is a different issue than CAMEL-8460. I need to take a look at
Spring Cloud before I investigate it. Added to my backlog.

> Camel requires restart of Spring applicationcontext to fetch new values for properties
managed by Spring Cloud
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-8482
>                 URL: https://issues.apache.org/jira/browse/CAMEL-8482
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-spring-boot
>    Affects Versions: 2.15.0
>            Reporter: Manuel Rivas
>            Assignee: Henryk Konsek
>         Attachments: config-client.zip
>
>
> When having a camel route builder making use of a property managed by spring  cloud config
server, the beans in the application managed by Spring get the property values refreshed when
invoking the Spring cloud config RefreshEndpoint but the camel routebuilders does not pick
up the new values. Restarting the camel context does not help either. Restart of Spring application
context is required.
> Example that works for Spring managed beans:
> package se.comhem.service;
> import org.springframework.beans.factory.annotation.Value;
> import org.springframework.cloud.context.config.annotation.RefreshScope;
> import org.springframework.stereotype.Component;
> @Component
> @RefreshScope()
> public class CosmosProperties {
>     @Value("${cosmos.someappconf}")
>     private String someAppConf;
>     public String getSomeAppConf(){
>         return someAppConf;
>     }
> }
> When using this bean together with a camel routebuilder it does not work until Spring
Application context is restarted:
> package se.comhem.service;
> import org.apache.camel.model.language.SimpleExpression;
> import org.apache.camel.spring.SpringRouteBuilder;
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.stereotype.Component;
> @Component
> public class ConfigClientRouteBuilder extends SpringRouteBuilder {
>     private final static String URI = "servlet:///testCamel";
>     @Autowired
>     private CosmosProperties cosmosProperties;
>     @Override
>     public void configure() throws Exception {
>         from(URI)
>                 .setBody(new SimpleExpression(cosmosProperties.getSomeAppConf()))
>                 .to("log:se.comhem?level=INFO&showBody=true&multiline=true")
>                 .end();
>     }
> }
> Main application class:
> package se.comhem.service;
> import org.apache.camel.component.servlet.CamelHttpTransportServlet;
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.boot.SpringApplication;
> import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
> import org.springframework.boot.context.embedded.ServletRegistrationBean;
> import org.springframework.context.annotation.Bean;
> import org.springframework.context.annotation.ComponentScan;
> import org.springframework.context.annotation.Configuration;
> import org.springframework.web.bind.annotation.RequestMapping;
> import org.springframework.web.bind.annotation.RestController;
> @Configuration
> @EnableAutoConfiguration
> @RestController
> @ComponentScan
> public class Application {
>     private static final String CAMEL_URL_MAPPING = "/camel/*";
>     private static final String CAMEL_SERVLET_NAME = "CamelServlet";
>     @Autowired
>     private CosmosProperties cosmosProperties;
>     @RequestMapping("/")
>     public String home() {
>         return "Config client running correctly";
>     }
>     public static void main( String[] args ) {
>         SpringApplication.run(Application.class, args);
>     }
>     @RequestMapping("/some-app-conf")
>     public String someAppConf(){
>         return "Some app conf " + this.cosmosProperties.getSomeAppConf();
>     }
>     @Bean
>     public ServletRegistrationBean servletRegistrationBean() {
>         ServletRegistrationBean registration = new ServletRegistrationBean(new CamelHttpTransportServlet(),
CAMEL_URL_MAPPING);
>         registration.setName(CAMEL_SERVLET_NAME);
>         return registration;
>     }
> }
> Bootstrap configuration
> spring:
>   boot:
>     admin:
>       url: http://localhost:8880
>   application:
>     name: config-client
>   config:
>     name: config-client
>   profiles:
>       active: ${environment}
>   cloud:
>       config:
>         uri: http://localhost:8110
>         enabled: true
>         failFast: true
> pom:
> <?xml version="1.0" encoding="UTF-8"?>
> <project xmlns="http://maven.apache.org/POM/4.0.0"
>          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
>     <modelVersion>4.0.0</modelVersion>
>     <groupId>se.comhem.service</groupId>
>     <artifactId>config-client</artifactId>
>     <version>1.0-SNAPSHOT</version>
>     <properties>
>         <org.springframework.version>4.1.5.RELEASE</org.springframework.version>
>         <camel.version>2.15.0</camel.version>
>         <java.version>1.8</java.version>
>     </properties>
>     <dependencyManagement>
>         <dependencies>
>             <dependency>
>                 <groupId>org.springframework.cloud</groupId>
>                 <artifactId>spring-cloud-starter-parent</artifactId>
>                 <version>1.0.0.RELEASE</version>
>                 <type>pom</type>
>                 <scope>import</scope>
>             </dependency>
>         </dependencies>
>     </dependencyManagement>
>     <dependencies>
>         <dependency>
>             <groupId>org.springframework.boot</groupId>
>             <artifactId>spring-boot-starter-web</artifactId>
>             <exclusions>
>                 <exclusion>
>                     <groupId>org.springframework.boot</groupId>
>                     <artifactId>spring-boot-starter-tomcat</artifactId>
>                 </exclusion>
>                 <exclusion>
>                     <groupId>org.slf4j</groupId>
>                     <artifactId>log4j-over-slf4j</artifactId>
>                 </exclusion>
>             </exclusions>
>         </dependency>
>         <dependency>
>             <groupId>org.springframework.boot</groupId>
>             <artifactId>spring-boot-starter-jetty</artifactId>
>         </dependency>
>         <dependency>
>             <groupId>org.springframework.boot</groupId>
>             <artifactId>spring-boot-starter-actuator</artifactId>
>         </dependency>
>         <dependency>
>             <groupId>org.springframework.cloud</groupId>
>             <artifactId>spring-cloud-starter</artifactId>
>         </dependency>
>         <dependency>
>             <groupId>de.codecentric</groupId>
>             <artifactId>spring-boot-starter-admin-client</artifactId>
>             <version>1.1.2</version>
>         </dependency>
>         <dependency>
>             <groupId>se.comhem.common</groupId>
>             <artifactId>decrypt</artifactId>
>             <version>1.0.0</version>
>         </dependency>
>         <!-- Camel -->
>         <dependency>
>             <groupId>org.apache.camel</groupId>
>             <artifactId>camel-core</artifactId>
>             <version>${camel.version}</version>
>             <exclusions>
>                 <exclusion>
>                     <artifactId>slf4j-api</artifactId>
>                     <groupId>org.slf4j</groupId>
>                 </exclusion>
>             </exclusions>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.camel</groupId>
>             <artifactId>camel-spring-boot</artifactId>
>             <version>${camel.version}</version>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.camel</groupId>
>             <artifactId>camel-servlet</artifactId>
>             <version>${camel.version}</version>
>         </dependency>
>     </dependencies>
>     <build>
>         <resources>
>             <resource>
>                 <directory>src/main/resources</directory>
>                 <filtering>true</filtering>
>             </resource>
>         </resources>
>         <plugins>
>             <plugin>
>                 <groupId>org.springframework.boot</groupId>
>                 <artifactId>spring-boot-maven-plugin</artifactId>
>                 <executions>
>                     <execution>
>                         <goals>
>                             <goal>repackage</goal>
>                         </goals>
>                     </execution>
>                 </executions>
>             </plugin>
>             <plugin>
>                 <groupId>org.apache.maven.plugins</groupId>
>                 <artifactId>maven-compiler-plugin</artifactId>
>                 <version>3.2</version><!--$NO-MVN-MAN-VER$-->
>                 <configuration>
>                     <source>${java.version}</source>
>                     <target>${java.version}</target>
>                 </configuration>
>             </plugin>
>             <plugin>
>                 <groupId>org.apache.maven.plugins</groupId>
>                 <artifactId>maven-source-plugin</artifactId>
>                 <executions>
>                     <execution>
>                         <id>attach-sources</id>
>                         <phase>verify</phase>
>                         <goals>
>                             <goal>jar-no-fork</goal>
>                         </goals>
>                     </execution>
>                 </executions>
>             </plugin>
>         </plugins>
>     </build>
> </project>



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message