Spring Config Client Not able to Fetch Configs from Server - spring

My Spring Cloud config client is not able to resolve the server1 property. It is throwing "Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'server1' in value "${server1}""
#Controller
#RefreshScope
public class OSLController {
#Value("${server1}")
public String oslServer;
}
Here is the bootstrap.properties of the config client:
spring.cloud.config.uri=http://localhost:8888
spring.profiles.active=preprod
spring.application.name=osl
Here are the configurations of the config server:
application.properties
server.port=8888
spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=classpath:/config/osl,classpath:/osl,classpath:/config
Here are the paths when hit by the browser:
http://localhost:8888/osl/preprod
{
"name": "osl",
"profiles": [
"preprod"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "class path resource [config/osl/osl-preprod.properties",
"source": {
"server1": "preprod"
}
},
{
"name": "class path resource [config/osl/osl.properties",
"source": {
"server1": "common"
}
}
]
}
When the config client is started, it prints the following logs:
2021-02-27 19:19:06.576 INFO 27040 --- [ main] in.rahul.ConfigClient2Application : Starting ConfigClient2Application using Java 15.0.1 on DESKTOP-CJ4TSGP with PID 27040 (C:\Rahul\Workspace\ConfigClient-2\target\classes started by Rahul in C:\Rahul\Workspace\ConfigClient-2)
2021-02-27 19:19:06.579 INFO 27040 --- [ main] in.rahul.ConfigClient2Application : No active profile set, falling back to default profiles: default
2021-02-27 19:19:07.282 INFO 27040 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=d5ff5a52-737f-3fd5-8528-04cdeb4cd847
2021-02-27 19:19:07.475 INFO 27040 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
The tutorial that I am following prints the following as well while starting the config client
Fetching config from server at: http://localhost:8888/
The above message is not coming in my config client which is leading me to believe that config client is not able to recognize the config server.
Can someone please guide the problem and how to troubleshoot this? If I am able to read the configs from browser why the client is not able to connect and resolve the server1 property.
I am using windows machine.
Thanks.

Related

Spring Cloud Config Client Located Server: properties not loaded

I am sure this is some kind of boot/cloud version dependency issue but I can't figure out the combination of dependencies and property values.
Config Servers starts and properties are available in browser
localhost:8888/master/ucdp-ingest
localhost:8888/master/ucdp-ingest-dev
$ java --version
openjdk 11.0.14.1 2022-02-08 LTS
OpenJDK Runtime Environment Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS, mixed mode)
Therefore according to 2021-0-3 Availability and the java version we use, went with
Spring Boot: 2.7.6
Spring Cloud: 2021.0.3
Client pom
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.6</version>
<relativePath/>
</parent>
<properties>
<aws-sdk.version>1.12.368</aws-sdk.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<jacoco.version>0.8.8</jacoco.version>
<jasypt-spring-boot.version>3.0.5</jasypt-spring-boot.version>
<java.version>11</java.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<spring-cloud.version>2021.0.3</spring-cloud.version>
<spring-cloud-stream-kinesis-binder.version>2.2.0</spring-cloud-stream-kinesis-binder.version>
<springdoc-openapi-ui.version>1.6.14</springdoc-openapi-ui.version>
<swagger-maven-plugin.version>2.1.6</swagger-maven-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- Spring cloud -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
Note no "spring-cloud-starter-bootstrap" per documentation.
Interestingly "spring.profiles.active" shows deprecated.
However, according to Spring 2.4 docs it should be spring.config.activate.on-profile. This doesn't resolve as system property.
-Dspring.config.activate.on-profile=dev
2022-12-23 15:28:51.358 INFO 36316 --- [ main] c.b.u.ucdp.ingest.UcdpIngestApplication : No active profile set, falling back to 1 default profile: "default"
Client: application.yml
spring:
application:
name: ucdp-ingest
cloud:
config:
name: ${spring.application.name}
uri: http://localhost:8888
username: ----------
password: ---------
request-connect-timeout: 3000
request-read-timeout: 3000
retry:
initial-interval: 1000
max-attempts: 6
label: master
fail-fast: true
config:
import: "configserver:"
server:
port: 8300
servlet:
context-path: /${spring.application.name}
# Actuator
management:
#opt-in use enabled-by-default: false then enable what you want. default = true
enabled-by-default: true
server:
port: ${server.port}
endpoints:
web:
base-path: ${server.servlet.context-path}
exposure:
include: "*"
endpoint:
env:
enabled: true
health:
show-details: always
enabled: true
info:
enabled: true
# shutdown:
# enabled: true
#OpenAPI
springdoc:
api-docs:
path: /docs/api-docs
version: openapi_3_1
swagger-ui:
path: /docs/swagger-ui
paths-to-match: /**
REMOTE application-ucdp-ingest.yml
app:
ucdp:
url: https://ucdpapi.pcr.uu.se/api
connect-timeout-millis: 2000
read-timeout-seconds: 2000
ged:
job:
enabled: true
cron: "20 49 11 * * ?"
#Max page size is 1000
pageSize: 1000
uri: /gedevents/21.1
REMOTE application-ucdp-ingest-dev.yml
contains mongo and aws connection properties. Mongo also failed to connect because properties were not loaded remotely.
LOGS: Note I am passing profile as system property.
+ /c/sfw/java/jdk11.0.14_10/bin/java -Dspring.config.activate.on-profile=dev -Dlogging.config=/c/projects/ucdp-ingest/ucdp-ingest-app/config/logback.xml -jar /c/projects/ucdp-ingest/ucdp-ingest-app/target/ucdp-ingest-app-0.0.1-SNAPSHOT.jar
2022-12-23 15:30:50.081 INFO 20496 --- [ main] c.b.u.ucdp.ingest.UcdpIngestApplication : Starting UcdpIngestApplication v0.0.1-SNAPSHOT using Java 11.0.14.1 on BRANDA-BSTAQ-PC with PID 20496 (C:\projects\ucdp-ingest\ucdp-ingest-app\target\ucdp-ingest-app-0.0.1-SNAPSHOT.jar started by BruceRandall in C:\projects\ucdp-ingest\ucdp-ingest-app)
2022-12-23 15:30:50.086 INFO 20496 --- [ main] c.b.u.ucdp.ingest.UcdpIngestApplication : The following 1 profile is active: "dev"
2022-12-23 15:30:50.136 INFO 20496 --- [ main] o.s.c.c.c.ConfigServerConfigDataLoader : Fetching config from server at : http://localhost:8888
2022-12-23 15:30:50.137 INFO 20496 --- [ main] o.s.c.c.c.ConfigServerConfigDataLoader : Located environment: name=ucdp-ingest, profiles=[dev], label=master, version=7102644c36175df62e3a3952793021cdf730583a, state=null
2022-12-23 15:30:51.495 INFO 20496 --- [ main] ptablePropertiesBeanFactoryPostProcessor : Post-processing PropertySource instances
2022-12-23 15:30:51.496 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Skipping PropertySource configurationProperties [class org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource
2022-12-23 15:30:51.498 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Skipping PropertySource servletConfigInitParams [class org.springframework.core.env.PropertySource$StubPropertySource
2022-12-23 15:30:51.498 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Skipping PropertySource servletContextInitParams [class org.springframework.core.env.PropertySource$StubPropertySource
2022-12-23 15:30:51.499 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource systemProperties [org.springframework.core.env.PropertiesPropertySource] to EncryptableMapPropertySourceWrapper
2022-12-23 15:30:51.499 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource systemEnvironment [org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor$OriginAwareSystemEnvironmentPropertySource] to EncryptableSystemEnvironmentPropertySourceWrapper
2022-12-23 15:30:51.500 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource random [org.springframework.boot.env.RandomValuePropertySource] to EncryptablePropertySourceWrapper
2022-12-23 15:30:51.500 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource cachedrandom [org.springframework.cloud.util.random.CachedRandomPropertySource] to EncryptablePropertySourceWrapper
2022-12-23 15:30:51.500 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource springCloudClientHostInfo [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
2022-12-23 15:30:51.500 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource configClient [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
2022-12-23 15:30:51.500 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource Config resource 'file [config\application.yml]' via location 'optional:file:./config/' [org.springframework.boot.env.OriginTrackedMapPropertySource] to EncryptableMapPropertySourceWrapper
2022-12-23 15:30:51.664 INFO 20496 --- [ main] c.u.j.filter.DefaultLazyPropertyFilter : Property Filter custom Bean not found with name 'encryptablePropertyFilter'. Initializing Default Property Filter
2022-12-23 15:30:51.673 INFO 20496 --- [ main] c.u.j.r.DefaultLazyPropertyResolver : Property Resolver custom Bean not found with name 'encryptablePropertyResolver'. Initializing Default Property Resolver
2022-12-23 15:30:51.675 INFO 20496 --- [ main] c.u.j.d.DefaultLazyPropertyDetector : Property Detector custom Bean not found with name 'encryptablePropertyDetector'. Initializing Default Property Detector
2022-12-23 15:30:52.246 INFO 20496 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8300 (http)
2022-12-23 15:30:52.256 INFO 20496 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-12-23 15:30:52.256 INFO 20496 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.69]
2022-12-23 15:30:52.351 INFO 20496 --- [ main] o.a.c.c.C.[.[localhost].[/ucdp-ingest] : Initializing Spring embedded WebApplicationContext
2022-12-23 15:30:52.351 INFO 20496 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2212 ms
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gedJob' defined in URL [jar:file:/C:/projects/ucdp-ingest/ucdp-ingest-app/target/ucdp-ingest-app-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/bar/udl/ucdp/ingest/service/impl/GedJob.class]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Encountered invalid #Scheduled method 'executeJob':
Could not resolve placeholder 'app.ged.job.cron' in value "${app.ged.job.cron}"
ConfigServerConfigDataLoader : Located environment: name=ucdp-ingest, profiles=[dev], label=master, version=7102644c36175df62e3a3952793021cdf730583a, state=null
Could not resolve placeholder 'app.ged.job.cron' in value "${app.ged.job.cron}"
Unfortunately, ConfigServerConfigDataLoader doesn't give you a complete URL
Configuration Server Endpoint
http://localhost:8888/master/ucdp-ingest
{
"name": "master",
"profiles": [
"ucdp-ingest"
],
"label": null,
"version": "155b907870c49c194dee1f1b6d94be768ce043ec",
"state": null,
"propertySources": [
{
"name": "C:\\\\projects\\\\udl-app-config/file:C:\\Users\\BRUCER~1\\AppData\\Local\\Temp\\config-repo-1334124828626900950\\application-ucdp-ingest.yml",
"source": {
"app.ucdp.url": "https://ucdpapi.pcr.uu.se/api",
"app.ucdp.connect-timeout-millis": 2000,
"app.ucdp.read-timeout-seconds": 2000,
"app.ged.job.enabled": true,
"app.ged.job.cron": "20 49 11 * * ?",
"app.ged.pageSize": 1000,
"app.ged.uri": "/gedevents/21.1",
}
}
]
Reverted back to boot 2.4.3, cloud 2020.0.3 but will be working back up to boot 2.7.6 cloud 2021.0.3.
The main issue was incorrectly interpreting the specification for the naming convention for property files. I noticed when querying the configuration server the name was the branch and the profile was the application name. Hence the reason I could only pull properties with localhost:8888/master/app-name-profile
Once I removed application from my file names in the git repository to ${spring.application.name}-profile I was able to query the server correctly and
the client was able to connect and load properties.
My last issue is I can't pass the profile in as a system property -Dspring.profiles.active=dev resolves to default when the bean access the Config Server.

How to move Zuul gateway configurations to configuration server

I'm starting out with microservices architecture and spring cloud.
I'm trying to get configurations for my Spring Zuul Gateway from the spring configuration server.
I've added below properties in bootstrap.properties file of the gateway service:
spring.application.name=api-gateway
spring.cloud.config.uri=http://localhost:8888
spring.profiles.active=dev
Even though these properties work for all other services, for the gateway they do not work.
The annotations I'm using for the gateway are:
#EnableZuulProxy
#EnableDiscoveryClient
#SpringBootApplication
public class ApiGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ApiGatewayApplication.class, args);
}
}
The annotation for other services is only:
#SpringBootApplication
My configuration server has a connected git repository with a file: api-gateway-dev.properties
logs of gateway:
:: Spring Boot :: (v2.3.0.M4)
2020-04-17 21:42:39.983 INFO 10340 --- [ restartedMain]
c.nyo.apigateway.ApiGatewayApplication : The following profiles are
active: dev 2020-04-17 21:42:41.926 WARN 10340 --- [ restartedMain]
o.s.boot.actuate.endpoint.EndpointId : Endpoint ID
'service-registry' contains invalid characters, please migrate to a
valid format. 2020-04-17 21:42:41.969 WARN 10340 --- [
restartedMain] o.s.boot.actuate.endpoint.EndpointId : Endpoint ID
'hystrix.stream' contains invalid characters, please migrate to a
valid format. 2020-04-17 21:42:42.240 INFO 10340 --- [
restartedMain] o.s.cloud.context.scope.GenericScope : BeanFactory
id=a11a283e-7de6-3470-b177-65c08eab7398 2020-04-17 21:42:43.859 INFO
10340 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer :
Tomcat initialized with port(s): 8765 (http) 2020-04-17 21:42:43.880
INFO 10340 --- [ restartedMain]
o.apache.catalina.core.StandardService : Starting service [Tomcat]
logs of a service that is getting configurations:
:: Spring Boot :: (v2.3.0.M4)
2020-04-17 21:54:01.414 INFO 5180 --- [ restartedMain]
c.c.c.ConfigServicePropertySourceLocator : Fetching config from server
at : http://localhost:8888 2020-04-17 21:54:04.184 INFO 5180 --- [
restartedMain] c.c.c.ConfigServicePropertySourceLocator : Located
environment: name=users-service, profiles=[dev], label=null,
version=244114f5a11aa7d4a0acb5750ddad144f7de1be5, state=null
2020-04-17 21:54:04.186 INFO 5180 --- [ restartedMain]
b.c.PropertySourceBootstrapConfiguration : Located property source:
[BootstrapPropertySource {name='bootstrapProperties-configClient'},
BootstrapPropertySource
{name='bootstrapProperties-https://my-user#bitbucket.org/my-user/configs.git/users-service-dev.properties'},
BootstrapPropertySource
{name='bootstrapProperties-https://my-user#bitbucket.org/my-user/configs.git/users-service.properties'}]
2020-04-17 21:54:04.197 INFO 5180 --- [ restartedMain]
c.n.U.UsersServiceApplication : The following profiles are
active: dev
Is it logical to make gateway configuration dynamic?
Why don't I get the configuration from the configuration server?
Found the problem. I was missing:
implementation 'org.springframework.cloud:spring-cloud-starter-config'
in my build.gradle file dependencies

Spring Cloud Config Server - Properties not being picked up

We are trying to add Spring Cloud Config Server to our project to externalize the configuration.
We have created a Config Server which connects to the Git repo and seems to be working correctly. However when we start a sample client it we get a message fetching config from server. Located environment but then a message to set a property which we have set in the corresponding yaml file in the git repo.
Config Server bootStrap.yml
spring:
application:
name: configuration-service
server:
port: 8888
Config Server application.yml
spring:
profiles:
active: dev
security:
user:
name: root
password: M5awantk
cloud:
config:
server:
git:
clone-on-start: true
uri: https://git.assembla.com/*********
username: ***********
password: ***********
Hitting http://localhost:8080/notification-service/default gives the following which is correct
{
name: "notification-service",
profiles: [
"default"
],
label: null,
version: "21ee5025b232b812e0e64387cd577eeda0351214",
state: null,
propertySources: [
{
name: "https://git.assembla.com/pins-configuration.git/notification-service.yml",
source: {
spring.main.allow-bean-definition-overriding: true,
spring.application.name: "notification-service",
spring.zipkin.baseUrl: "http://localhost:9411/",
spring.jpa.properties.hibernate.cache.use_second_level_cache: true,
spring.jpa.properties.hibernate.cache.use_query_cache: true,
server.port: 8091,
server.compression.enabled: true,
server.compression.min-response-size: 2048,
server.compression.mime-types: "application/json,application/xml,text/html,text/plain",
eureka.instance.hostname: "localhost",
eureka.instance.port: 8761,
eureka.instance.leaseRenewalIntervalInSeconds: 3,
eureka.instance.instanceId:
"${spring.application.name}:${spring.application.instance_id:${random.value}}",
eureka.client.registryFetchIntervalSeconds: 5,
eureka.client.instanceInfoReplicationIntervalSeconds: 5,
eureka.client.initialInstanceInfoReplicationIntervalSeconds: 5,
eureka.client.serviceUrl.defaultZone:
"http://${eureka.instance.hostname}:${eureka.instance.port}/eureka/"
}
}
]
}
Client (named notification-service)
Client bootstrap.yml
spring:
cloud:
config:
uri: http://localhost:8888
username: root
password: M5awantk
name: notification-service
application:
name: notifcation-service
On staring the notification-service it seems to find the config service and the notification-service.yml as expected but then we get an error
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
Although we have the following in notification-service.yml and it shows when we hit http://localhost:8080/notification-service/default
spring.main.allow-bean-definition-overriding: true
Console output when starting notification-service
2020-03-24 18:26:03.046 INFO [notifcation-service,,,] 24238 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2020-03-24 18:26:04.847 INFO [notifcation-service,,,] 24238 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=notification-service, profiles=[default], label=null, version=21ee5025b232b812e0e64387cd577eeda0351214, state=null
2020-03-24 18:26:04.848 INFO [notifcation-service,,,] 24238 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: OriginTrackedCompositePropertySource {name='configService', propertySources=[MapPropertySource {name='configClient'}, OriginTrackedMapPropertySource {name='https://git.assembla.com/pins-configuration.git/notification-service.yml'}]}
2020-03-24 18:26:04.900 INFO [notifcation-service,,,] 24238 --- [ main] c.s.p.n.NotificationServiceApplication : The following profiles are active: dev
2020-03-24 18:26:06.237 INFO [notifcation-service,,,] 24238 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-03-24 18:26:06.464 INFO [notifcation-service,,,] 24238 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 217ms. Found 3 JPA repository interfaces.
2020-03-24 18:26:06.474 INFO [notifcation-service,,,] 24238 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-03-24 18:26:06.615 INFO [notifcation-service,,,] 24238 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 140ms. Found 21 JPA repository interfaces.
2020-03-24 18:26:06.616 WARN [notifcation-service,,,] 24238 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'jpaAuditingHandler' defined in null: Cannot register bean definition [Root bean: class [org.springframework.data.auditing.AuditingHandler]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] for bean 'jpaAuditingHandler': There is already [Root bean: class [org.springframework.data.auditing.AuditingHandler]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] bound.
2020-03-24 18:26:06.626 INFO [notifcation-service,,,] 24238 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-24 18:26:06.630 ERROR [notifcation-service,,,] 24238 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'jpaAuditingHandler' could not be registered. A bean with that name has already been defined and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
Not sure what we might be doing wrong.
EDIT: I have managed to get a very simple application working with just one property set in the corresponding application.yml.
Wondering if it is something to do with properties not being available in time, although from the console output that would not appear to be the case.

spring config server not posting to rabbitmq

I've generated a spring boot config server from spring's initialzr.
I've installed rabbitmq with brew. initialzr generated with boot version 2.1.1.RELEASE and cloud version Greenwich.M3.
the simple rest services are connecting to rabbitmq queues. the config server is connection to a gitlab config repo.
But when I commit and push a change to it, the change is not reflected by the service application. The config server gets logs messages when the push is completed. Can anyone say what might be wrong? No messages ever seem to appear in rabbitmq console. I have been able to refresh the properties via actuator/bus-refresh through rabbitmq though.
config-server log messages on commit of change to config-repo's employee-service.yml file:
2018-12-07 11:53:12.185 INFO 84202 --- [nio-8888-exec-1] o.s.c.c.monitor.PropertyPathEndpoint : Refresh for: employee:service
2018-12-07 11:53:12.228 INFO 84202 --- [nio-8888-exec-1] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$b43cc593] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-12-07 11:53:12.253 INFO 84202 --- [nio-8888-exec-1] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default
2018-12-07 11:53:12.259 INFO 84202 --- [nio-8888-exec-1] o.s.boot.SpringApplication : Started application in 0.072 seconds (JVM running for 3075.606)
2018-12-07 11:53:12.345 INFO 84202 --- [nio-8888-exec-1] o.s.cloud.bus.event.RefreshListener : Received remote refresh request. Keys refreshed []
2018-12-07 11:53:12.345 INFO 84202 --- [nio-8888-exec-1] o.s.c.c.monitor.PropertyPathEndpoint : Refresh for: employee-service
2018-12-07 11:53:12.377 INFO 84202 --- [nio-8888-exec-1] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$b43cc593] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-12-07 11:53:12.398 INFO 84202 --- [nio-8888-exec-1] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default
2018-12-07 11:53:12.402 INFO 84202 --- [nio-8888-exec-1] o.s.boot.SpringApplication : Started application in 0.056 seconds (JVM running for 3075.749)
2018-12-07 11:53:12.489 INFO 84202 --- [nio-8888-exec-1] o.s.cloud.bus.event.RefreshListener : Received remote refresh request. Keys refreshed []
config-server has this application.yml:
---
server:
port: ${PORT:8888}
spring:
cloud:
bus:
enabled: true
config:
server:
git:
uri: ${CONFIG_REPO_URI:git#gitlab.<somedomain>:<somegroup>/config-repo.git}
search-paths:
- feature/initial-repo
main:
banner-mode: "off"
and ConfigServerApplication.java:
#SpringBootApplication
#EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
and these gradle dependencies:
dependencies {
implementation('org.springframework.cloud:spring-cloud-config-server')
implementation('org.springframework.cloud:spring-cloud-starter-stream-rabbit')
implementation('org.springframework.cloud:spring-cloud-config-monitor')
testImplementation('org.springframework.boot:spring-boot-starter-test')
implementation('org.springframework.cloud:spring-cloud-stream-test-support')
}
service has this applciation.yml:
---
server:
port: 8092
management:
security:
enabled: "false"
endpoints:
web:
exposure:
include:
- '*'
spring:
main:
banner-mode: "off"
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
this bootstrap.yml:
---
spring:
application:
name: employee-service
cloud:
config:
uri:
- http://localhost:8888
label: feature(_)initial-repo
these gradle dependencies:
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.cloud:spring-cloud-starter-config')
implementation('org.springframework.cloud:spring-cloud-starter-bus-amqp')
implementation('org.springframework.boot:spring-boot-starter-actuator')
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
this main class:
#SpringBootApplication
public class EmployeeServiceApplication {
public static void main(String[] args) {
SpringApplication.run(EmployeeServiceApplication.class, args);
}
}
and this controller class:
#RefreshScope
#RestController
public class WelcomeController {
#Value("${app.service-name}")
private String serviceName;
#Value("${app.shared.attribute}")
private String sharedAttribute;
#GetMapping("/service")
public String getServiceName() {
return "service name [" + this.serviceName + "]";
}
#GetMapping("/shared")
public String getSharedAttribute() {
return " application.yml [" + this.sharedAttribute + "]";
}
}
Try to create and build your project with Maven instead of Gradle.
I experience the same problem. I have two identical apps with the same RabbitMQ dependencies, one is build with Maven and second with Gradle. The Maven-based app publishes things to RabbitMQ as expected. The very same app, built with Gradle doesn't establish connection to RabbitMQ and is not publishing events.
To further clarify things, I run both apps in Eclipse with Spring Tools.

Spring Reactive MongoDB not saving document

I'm trying to save a basic document but despite connecting to mongodb successfully... It doesn't seem to want to save.
Spring logs
2018-10-03 00:17:25.998 INFO 10713 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2018-10-03 00:17:26.049 INFO 10713 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-10-03 00:17:26.106 INFO 10713 --- [ctor-http-nio-1] r.ipc.netty.tcp.BlockingNettyContext : Started HttpServer on /0:0:0:0:0:0:0:0:8080
2018-10-03 00:17:26.106 INFO 10713 --- [ restartedMain] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 8080
2018-10-03 00:17:26.112 INFO 10713 --- [ restartedMain] c.l.s.ServiceLegalApplicationKt : Started ServiceLegalApplicationKt in 3.459 seconds (JVM running for 4.201)
2018-10-03 00:17:26.644 INFO 10713 --- [ntLoopGroup-2-2] org.mongodb.driver.connection : Opened connection [connectionId{localValue:3, serverValue:4}] to localhost:27017
application.properties
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=legal
spring.data.mongodb.repositories.type=reactive
spring.mongodb.embedded.version=4.0.2
basic interface and class
interface EventRepository: ReactiveMongoRepository<Event, String>
#Document
class Event(id: String, name: String)
trying a simple save function
#Service
class SomeService(val eventRepository: EventRepository)
{
fun save() = eventRepository.save(Event(UUID.randomUUID().toString(), "hey"))
}
Mono<Event> response = repository.save(Event(UUID.randomUUID().toString(), "hey"));
Changes in save method
fun save() = eventRepository.save(Event(UUID.randomUUID().toString(), "hey")).subscribe();
You have to invoke subscribe() method on Mono reference to see the logs or details.
To make you stream terminal with subscribe() operation and to get the Mono result at the same time - split into two separate operations:
Mono<String> myEvent = eventRepository.save(Event(UUID.randomUUID().toString(), "hey"));
myEvent.subscribe();
return myEvent;
You can also call .block() on the returned Reactive mono
Mono<Event> reactiveEvent = repository.save(); reactiveEvent.block()
Also read this

Resources