Currently I'm working in Spring boot micro services project. Consider I have 3 micro services named as A, B, C. Now My project have application.yml file separately for each micro service. Now I want to add one more microservice D, for manage all service property files.
view my config-service structure
eureka.yml(inside config-service) file is:
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0
endpoints:
sensitive: false
In eureka-service bootstrap.properties is:
spring:
application:
name: eureka
cloud:
config:
uri: http://localhost:8888
Config service application properties :
spring:
application:
name: config
cloud:
config:
server:
native:
search-locations: classpath:/config/DEVELOP
profiles:
active: native
server:
port: 8888
my config application file is:
#SpringBootApplication
#EnableConfigServer
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
I did the following steps:
start the config-service
start the eureka-service
unfortunately, eureka server getting error.
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
the problem is while running eureka server, its not looking the config file which is inside the config service...
help me to resolve this. or instead of micro service, how can I go with folder?
Thanks # g00glen00b
I am changed config service bootstrap yml as follows :
spring:
application:
name: config
cloud:
config:
server:
native:
searchLocations: classpath:/config/DEVELOP/
profiles:
active: native
server:
port: 8888
Its working fine.
Related
I am doing a POC on Config Server wherein I will connect to BitBucket repo and if any checkin happen in that repo, my Config Service will pick those changes. In the below code if I am providing bitbucket credentials (hardcoding username and password), its able to connect to BitBucket and everything is working fine. But if I try to provide SSH key, its throwing below error:
application.yml
server.port: 8888
spring:
application.name: config-server
cloud.config.server.git.uri: ${url}
cloud:
config:
server:
git:
cloneOnStart: true
username: username
password: password
default-label: master
management:
endpoints:
web:
exposure:
include: refresh
eureka:
client:
serviceUrl:
defaultZone: http://localhost:7001/eureka/
registryFetchIntervalSeconds: 1
instance:
leaseRenewalIntervalInSeconds: 1
Like I said the above configuration is working fine. When I replaced with the below configuration.
server.port: 8888
spring:
application.name: config-server
cloud.config.server.git.uri: ${URL}
cloud:
config:
server:
git:
#cloneOnStart: true
ignore-local-ssh-settings: true
hostKey: ${hostKEY}
hostKeyAlgorithm: ssh-rsa
private-key: ${SSH PRIVATE KEY}
management:
endpoints:
web:
exposure:
include: refresh
eureka:
client:
serviceUrl:
defaultZone: http://localhost:7001/eureka/
registryFetchIntervalSeconds: 1
instance:
leaseRenewalIntervalInSeconds: 1
I am getting below error::
2023-02-10T12:26:39.276+05:30 INFO 24628 --- [ main] c.e.c.ConfigServerApplication : Started ConfigServerApplication in 2.949 seconds (process running for 3.646)
2023-02-10T12:26:41.041+05:30 WARN 24628 --- [2)-10.73.53.175] .c.s.e.MultipleJGitEnvironmentRepository : Error occured cloning to base directory.
org.eclipse.jgit.api.errors.TransportException: https://bitbucketdc-cluster07.jpmchase.net/scm/ccbrft/ccbrap-config.git: Authentication is required but no CredentialsProvider has been registered
I created SSH Key using command :: ssh-keygen -m PEM -t rsa -b 4096 -C "cigfid_dev#example.com
Any help is appreciated.
I have a config server in github have a structure like this:
-ms_one
|_application.yml
|_application-dev.yml
-ms_two
|_application.yml
|_application-dev.yml
Repo url: My Github Repo
In the project I also follow the same structure:
-configServer
-ms_one
-ms_two
In the application.yml of configServer I have
spring:
application:
name: CONFIGSERVER
profiles:
active: dev
cloud:
config:
server:
git:
uri: <github repo url>
clone-on-start: true
default-label: main
search-paths: {application}
eureka:
client:
fetch-registry: true
register-with-eureka: true
logging:
level:
web: error
In the ms-one service I have in application.yml
spring:
profiles:
active: dev
application:
name: ms-one
config:
import: configserver:http://localhost:8003
Now, I want the config server to fetch the configuration from the folder with the same name as application name and apply the configuration. The problem is the correct configuration is not being fetched. Please help me doing this
I got the idea of setting spring.cloud.config.server.git.search-paths:{application} from the thread How to point spring-cloud-config server to a git folder inside a git repo
I have a Spring Boot Application and I would like to Load configurations from Vault based on the Profile I am running. At present i have 2 profiles (dev, prod). My Dev Profile uses a H2 database where as the Prod Profile uses a Posgres DB. Running the dev Profile loads the correct config from Vault but running with the Prod Profile seems to be skipping it somehow and not looking in Vault.
bootstrap.yaml
spring:
application:
name: my-app
profiles:
active:
cloud:
vault:
host: localhost
port: 8200
scheme: http
uri: http://localhost:8200
connection-timeout: 5000
read-timeout: 15000
authentication: TOKEN
token: 00000000-0000-0000-0000-000000000000
kv:
enabled: true
backend: secret
default-context: my-app/dev
fail-fast: false
bootstrap-prod.yaml
spring:
application:
name: gateway
profiles:
active: prod
cloud:
vault:
host: localhost
port: 8200
scheme: http
uri: http://localhost:8200
connection-timeout: 5000
read-timeout: 15000
authentication: TOKEN
token: 00000000-0000-0000-0000-000000000000
kv:
enabled: true
backend: secret
default-context: my-app/dev
fail-fast: false
For example running the command gradle will load configuration from vault. But running gradle -Pprod fails to load the correct configuration from Vault.
try this syntax to activate your profile when using gradle:
./gradlew clean bootRun --args='--spring.profiles.active=prod'
I have these KVs sources store on Consul:
config/books/<key>
config/common/<key>
And in my spring boot app application.yml, I have config it as following:
spring:
application:
name: sampleapp
cloud:
consul:
host: localhost
port: 8500
config:
enabled: true
prefix: config
defaultContext: books
I know that this configuration that I made has pointed the app to read from config/books .
But I can't figure out how can I retrieve the Consul KV config from both config/common and config/books.
It's not really flexible there, but it can be done if you rename your project and use defaultContext as well. Based on the documentation Spring Cloud Consul Config takes next paths:
config/testApp,dev/
config/testApp/
config/application,dev/
config/application/
where testApp - name of your app, application - default context
So with the following configuration it will work
spring:
application:
name: books
cloud:
consul:
host: localhost
port: 8500
config:
enabled: true
prefix: config
defaultContext: common
Logs after running this configuration:
Located property source: CompositePropertySource {name='consul', propertySources=[ConsulPropertySource {name='config/books/'}, ConsulPropertySource {name='config/common/'}]}
I am working on a Spring Boot Registration Server(Eureka Server).
Currently it is working with below configuration.
Project Name: registration-service
Inside main method: System.setProperty("spring.config.name", "registration-service");
"yml file":
file name: registration-service
content:
eureka:
instance:
hostname: eureka-server
server:
enableSelfPreservation: false
client:
register-with-eureka: false
fetch-registry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
server:
port: 2323 # HTTP (Tomcat) port
spring:
application:
name: eureka-server
With above configuration,application start running on 2323.
But if i change spring.config.name,it does not work,start giving connection refused exception.
why it is happening? even though this spring.config.name is no where used in yml file. Should it be necessarily same as project name? or it is specific to #EnableEurekaServer enabled spring boot application.
And in yml we have to write
spring:
application:
name: eureka-server
though in other spring boot application we give name of current project(here it should be registration-service).why we have to write here eureka-server? I know,I am missing something(or a lot of things).please help me in understanding the missing part.
Spring boot by default looks for file application.yml. If u have different profiles in your application it can also look for application-{profilename}.yml. This is the default convention followed.
spring.config.name property is used to override this default behaviour. When u override this property with register-service then spring boot looks for a file register-service.yml and loads config from that.
So your eureka server url which is given in the register-service.yml file may not be available in the default application.yml file. Hence when u change the value Spring boot may not be avle to find the Eureka server url.
Keep the names unchanged, as much as possible. If u have config file as register-service.yml then keep the spring.config.name=register-service. If you change this value then u need to create the new file with config.name value and then add eureka configuration to that again.