-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using config client OUTSIDE a Spring Boot application... #299
Comments
How would your app consume the properties if it isn't a Spring application? If there is no link to the Spring |
It is a Spring application. Well more specifically we are a plugin to ActiveMQ which is a Spring app but not a Spring Boot one and would like settings pertaining to our configuration to come from the config server. I have been able to get @value annotations to work from System properties and a local properties file but would like them if there is an available config server to come from it and fallback otherwise. Do you have some instructions or at least an idea that would push me in the right direction? I am writing a class that does this the hard way revolving around It would be 1000% more preferable to do this the normal way. Any assistance would be appreciated. |
Well the "normal" way is to use Spring Cloud Config as part of a Spring Boot app. You really should consider doing that at some point. If you want to try and cobble it together yourself you need a |
One of the things I tried before I started this thread was this:
However I wasn't sure how exactly to configure this. Does the above seem right? It didn't work but there is so many new technologies being stitched together I don't know where things are going wrong. Should this be used in conjunction with or as a replacement for PropertySourcesPlaceholderConfigurer? |
In conjunction with. And declaring it as a bean in the main application context isn't going to work - you need to apply it before the context starts. How you do that is highly dependent on how the context is created. |
Thanks. I attempted to try to convert ActiveMQ to a Spring Boot and it seems too much work. I have written a custom wrapper that gets/parses the Config server settings. |
a chinese guy had see this and made a solution. |
@Mike520 I tried following the steps... There are a couple of problems:
Autowire problemsIt loads the properties... I'm having a hard time:
Did you get that to work? LOADING SPRING WEB with SPRING CORE 4.2.5In addition to what the user described in https://wenku.baidu.com/view/493cf9eba300a6c30d229f49.html, I had to do the following in a regular Spring Web application: https://github.com/marcellodesales/spring-mvc-helloworld-spring-cloud-config-client
@Configuration
@EnableConfigurationProperties({GithubProperties.class})
public class PropertiesConfigurer {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
LogsJava HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
Running Jetty 6.1.26
2017-04-13 13:30:13.849:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
ParentLoaderPriority enabled
Context path:/HelloWorld
ProjectClassLoader: entry=/home/mdesales/dev/github/intuit/servicesplatform-tools/spring-cloud-config-reference-springframework-app/target/classes
ProjectClassLoader: entry=/home/mdesales/.m2/repository/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/junit/junit/4.11/junit-4.11.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/springframework/spring-core/4.2.9.RELEASE/spring-core-4.2.9.RELEASE.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/springframework/cloud/spring-cloud-config-client/1.2.0.RELEASE/spring-cloud-config-client-1.2.0.RELEASE.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.4.1.RELEASE/spring-boot-autoconfigure-1.4.1.RELEASE.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/springframework/boot/spring-boot/1.4.1.RELEASE/spring-boot-1.4.1.RELEASE.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/springframework/spring-context/4.2.9.RELEASE/spring-context-4.2.9.RELEASE.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/springframework/spring-aop/4.2.9.RELEASE/spring-aop-4.2.9.RELEASE.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/springframework/spring-beans/4.2.9.RELEASE/spring-beans-4.2.9.RELEASE.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/springframework/spring-expression/4.2.9.RELEASE/spring-expression-4.2.9.RELEASE.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/springframework/cloud/spring-cloud-commons/1.1.3.RELEASE/spring-cloud-commons-1.1.3.RELEASE.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/springframework/security/spring-security-crypto/4.0.4.RELEASE/spring-security-crypto-4.0.4.RELEASE.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/springframework/cloud/spring-cloud-context/1.1.3.RELEASE/spring-cloud-context-1.1.3.RELEASE.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/springframework/spring-web/4.2.9.RELEASE/spring-web-4.2.9.RELEASE.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.8.3/jackson-annotations-2.8.3.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.8.3/jackson-databind-2.8.3.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.8.3/jackson-core-2.8.3.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.5/jcl-over-slf4j-1.7.5.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/ch/qos/logback/logback-classic/1.0.13/logback-classic-1.0.13.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/ch/qos/logback/logback-core/1.0.13/logback-core-1.0.13.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/springframework/spring-webmvc/4.2.9.RELEASE/spring-webmvc-4.2.9.RELEASE.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/jstl/jstl/1.2/jstl-1.2.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/springframework/boot/spring-boot-configuration-processor/1.4.5.RELEASE/spring-boot-configuration-processor-1.4.5.RELEASE.jar
ProjectClassLoader: entry=/home/mdesales/.m2/repository/org/json/json/20140107/json-20140107.jar
2017-04-13 13:30:13.903:INFO::jetty-6.1.26
13:30:14,300 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
13:30:14,300 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
13:30:14,300 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/home/mdesales/dev/github/intuit/servicesplatform-tools/spring-cloud-config-reference-springframework-app/target/classes/logback.xml]
13:30:14,379 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
13:30:14,381 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
13:30:14,389 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
13:30:14,469 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - This appender no longer admits a layout as a sub-component, set an encoder instead.
13:30:14,469 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - To ensure compatibility, wrapping your layout in LayoutWrappingEncoder.
13:30:14,469 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - See also http://logback.qos.ch/codes.html#layoutInsteadOfEncoder for details
13:30:14,470 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.zenika.controller] to DEBUG
13:30:14,470 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [com.zenika.controller] to false
13:30:14,470 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[com.zenika.controller]
13:30:14,470 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.cloud.config.client] to DEBUG
13:30:14,470 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [org.springframework.cloud.config.client] to false
13:30:14,470 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[org.springframework.cloud.config.client]
13:30:14,471 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to ERROR
13:30:14,471 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
13:30:14,471 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
13:30:14,472 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@612679d6 - Registering current configuration as safe fallback point
2017-04-13 13:30:14.474:INFO:/HelloWorld:Initializing Spring root WebApplicationContext
##################### loaded my comfigurable context
2017-04-13 13:30:14 [main] DEBUG c.z.c.config.CloudEnvironment - Adding [servletConfigInitParams] PropertySource with lowest search precedence
2017-04-13 13:30:14 [main] DEBUG c.z.c.config.CloudEnvironment - Adding [servletContextInitParams] PropertySource with lowest search precedence
2017-04-13 13:30:14 [main] DEBUG c.z.c.config.CloudEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
2017-04-13 13:30:14 [main] DEBUG c.z.c.config.CloudEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
##################### will load the client configuration
ConfigClientProperties [enabled=true, profile=qal, name=publisher, label=master, username=null, password=null, uri=http://localhost:8888, authorization=null, discovery.enabled=false, failFast=false, token=null]
2017-04-13 13:30:14 [main] INFO o.s.c.c.c.ConfigServicePropertySourceLocator - Fetching config from server at: http://localhost:8888
2017-04-13 13:30:15 [main] INFO o.s.c.c.c.ConfigServicePropertySourceLocator - Located environment: name=publisher, profiles=[qal], label=develop, version=null, state=null
2017-04-13 13:30:15 [main] DEBUG c.z.c.config.CloudEnvironment - Adding [configService] PropertySource with lowest search precedence
2017-04-13 13:30:15 [main] DEBUG c.z.c.config.CloudEnvironment - Initialized CloudEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,systemProperties,systemEnvironment,configService]
2017-04-13 13:30:15 [main] DEBUG c.z.c.config.CloudEnvironment - Replacing [servletContextInitParams] PropertySource with [servletContextInitParams]
2017-04-13 13:30:15 [main] INFO c.z.c.c.SpringCloudConfigContext - Refreshing Root WebApplicationContext: startup date [Thu Apr 13 13:30:15 PDT 2017]; root of context hierarchy
2017-04-13 13:30:15 [main] DEBUG c.z.c.c.SpringCloudConfigContext - Bean factory for Root WebApplicationContext: org.springframework.beans.factory.support.DefaultListableBeanFactory@16612a51: defining beans [propertiesConfigurer,baseController,myPropeties,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,org.springframework.web.servlet.view.InternalResourceViewResolver#0]; root of factory hierarchy
2017-04-13 13:30:15 [main] DEBUG c.z.c.c.SpringCloudConfigContext - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@d62fe5b]
2017-04-13 13:30:15 [main] DEBUG c.z.c.c.SpringCloudConfigContext - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@7a1234bf]
Github Properties are f4d24eed3909ad8766e29fd2500e80cb33d153a8 with /app/spring-cloud-config-publisher/git_basedir
My Properties are: f4d24eed3909ad8766e29fd2500e80cb33d153a8 with /app/spring-cloud-config-publisher/git_basedir
2017-04-13 13:30:15 [main] DEBUG c.z.c.c.SpringCloudConfigContext - Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@5629510]
2017-04-13 13:30:15.715:INFO:/HelloWorld:Initializing Spring FrameworkServlet 'mvc-dispatcher'
Github Properties are f4d24eed3909ad8766e29fd2500e80cb33d153a8 with /app/spring-cloud-config-publisher/git_basedir
My Properties are: f4d24eed3909ad8766e29fd2500e80cb33d153a8 with /app/spring-cloud-config-publisher/git_basedir
2017-04-13 13:30:15.886:INFO::Started SelectChannelConnector@0.0.0.0:8080 |
Well, I saw this issue a while ago and actually have the exact same motivation, to use @RefreshScope and Spring Boot Configuration Server for core Spring, I finally have a working implementation and wrote blog about it. If anybody needs it here is the link to the blog. |
I have clone the project and built it on maven. But it giving me the error: Could not resolve placeholder 'github.token' in string value "${github.token}" |
Hello @mehmetsalgar, |
Is it possible to use the client without it starting from a Spring Boot context?
I would like remote configuration available to me however my code exists within the context of a ActiveMQ plugin and another within a Vert.x server. I do not control the start classes in either.
My code doesn't have to be automatically refreshed. A simple on start loading of properties is sufficient. If the setting change I would be willing to restart the app to get the new properties.
Is this possible?
The text was updated successfully, but these errors were encountered: