I have a Spring Boot app that can not be run with a .yml config file.Below is the command that I run:
java -jar /opt/myAppFolder/myApp.war
I have a config folder withing the same location that I run my war file. And in that config,I have a application.yml file that application needs to retrieve some config:
security:
user:
password: password
logging:
level:
org.springframework.security: DEBUG
release:
sourceDir: /$ANY_DIR
targetDir: /$ANY_DIR
users:
- name: $ANY_NAME
pwd : $ANY_NAME
- name: $ANY_NAME
pwd : $ANY_NAME
mail:
host: $ANY_NAME
recipients: $ANY_NAME
subject: $ANY_NAME
body: $ANY_NAME
server:
port: 9000
spring:
profiles:
active: prod
Problem: Once I run the app on command line,the process just hangs.No output,no logging. I have tried to enable debug via command line. No avail.
If I put a file with properties extension,it works.However I want to use .yml since it is more convenient for me to have list of dynamic properties.And why nothing is displayed anway?
Any help appreciated.
Spring Boot Version:1.5.7
OS Version:Ubuntu 3.13.0-24-generic
Finally resolved it.
So here is the story:
I have contacted Spring Boot Team and they have recommended me to upgrade to version 1.5.8.RELEASE.
Once I did that,I had a different issue;application was not hanging anymore,but shutting down without logging anything.
And eventually it turned out to be an error in my logback-spring.xml file. It was malformatted.And in its "prod" profile,I did not have any console appender.Hence no output visible. So I have fixed my file and it started working.
More on my communication with Spring Boot Team:
https://github.com/spring-projects/spring-boot/issues/10711
Related
I have an spring boot application .jar, based on spring batch,and it is not a web application, and I'm using a ksh script to Launch it on my server side.
for some performance observation, we decide to install Spring Boot Admin for this app, using a "sba.war" that is already deployed in another web application on another server, I tried to drop the sba.war beside my applicationBatch.war after updating the application.yml file and import the SBA dependency on my build.gradle file :
spring:
datasource:
# BDD DEV
url: jdbc:oracle:thin:#xxxx:9999:AAAAA
username: xxxxxx
password: xxxxxx
# SBA DEV
boot:
admin:
client:
enabled: true
instance:
service-base-url: https://xxxxx.com
url: https://xxxxx.com/sba
username: username
password: password
so the problem is, that my application is not deployed on a tomcat server, it is runned by the ksh script on it's embeded server.
So can I anyhow use the embeded server of SBA to run it ?
Im using kubenetes and I have a pod contain ignite db I added to the pod another container - sscaling/jmx-prometheus-exporter:latest
I read in git I should run this
To run as a javaagent download the jar and run:
java -javaagent:./jmx_prometheus_javaagent-0.14.0.jar=8080:config.yaml -jar yourJar.jar
but I didnt understand, should I also download the file for the kubenrtes container as well?
can someone assist how can I continue from here
I have the following default configuration:
---
hostPort: localhost:5555
username:
password:
rules:
- pattern: ".*"
I have an environment with different services. They all are deployed and managed by Docker images and Kubernetes. I also use spring-boot-admin in order to monitor them all and spring-cloud-kubernetes to discover all the services automatically.
This my properties file.
application.yml (In the SBA project)
server:
port: ${admin-server.port:8086}
tomcat:
remote-ip-header: x-forwarded-for
protocol-header: x-forwarded-proto
spring:
application:
name: admin-server
security:
user:
name: ${spring-security.admin.username:****}
password: ${spring-security.admin.password:****}
boot:
admin:
discovery:
ignored-services: admin-server
notify:
mail:
enabled: ${admin-mail.enabled:true}
to: ${admin-mail.recipients:******}
from: ${admin-mail.from:******}
template: classpath:/template/status-changed.html
ignore-changes: OFFLINE:UP, DOWN:UP
slack:
webhook-url: ${admin-slack.webhook:*******}
ignore-changes: OFFLINE:UP, DOWN:UP
enabled: true
mail:
test-connection: false
host: smtpjc.*****
port: 25
properties:
mail:
smtp:
connectiontimeout: 5000
timeout: 3000
writetimeout: 5000
debug: ${admin-mail.debug:true}
It works perfectly whenever I restart the SBA project, it discovers every service.
My problem comes when I restart a single project, it is shown as OFFLINE in the SBA and it does not change its status.
What am I missing?
I have found the issue and fixed it like this:
spring.cloud.kubernetes.reload.enabled: true
I should have added this line to the config file.
I've found out, that I had to use the fabric8 kubernetes-client.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-fabric8-all</artifactId>
</dependency>
I'm using these current versions:
<spring-cloud.version>2020.0.2</spring-cloud.version>
<spring-cloud-kubernetes.version>2.0.2</spring-cloud-kubernetes.version>
<spring-boot-admin.version>2.4.1</spring-boot-admin.version>
Otherwise I follow the instructions of https://piotrminkowski.com/2020/02/18/spring-boot-admin-on-kubernetes/
I am trying set Spring Cloud Config Server, but the service config server, it the running on port 8888 which is correct, and another service should run on port 18060, but for reason when I startup, it allocate port 8080 for me and the return a warning "Could not locate PropertySource: label not found", what should I do? Thank you !!!
Add #EnableConfigServer at configuration class level or main class of spring boot application and restart the service .it will work .
In my case it was because I had to set the default branch of my github URI (the branch of the repository set for spring.cloud.config.server.git.uri) in the config server by setting the following to the application.properties
spring.cloud.config.server.git.default-label=main
I ran into similar issue, when I run my server locally I see in the logs only on the stratup
o.s.c.c.c.ConfigServicePropertySourceLocator - Could not locate PropertySource: label not found
It turned out this is a problem with the health check for the config server, when health check is triggered to config server an empty environment is used so the application name is empty hence the spring cloud client will try to access {config-server}/application since application is the default application name, see issue for more info on this.
To solve the issue I just disabled the health check for config server
health.config.enabled=false
Try this one. I had the same issue and solved.
First enable debug mode in your app.(In your property file: logging.level.=DEBUG . This is only to make sure the issue is same as mine Or you may have any clue of where it can go wrong.)
Then start the application and see the logs. The log shows the configured server URI and what the URL to get all property resources.
Compare both URL s - the one in the log and your Configuration server URI.
Issue is that mistakenly the URL defined the property file can have empty space at the end. (This can happen when you copy past from somewhere ) Example:
the value for spring.cloud.config.uri=http:localhost:< port >< additional empty space >
If this is the case, the client's log shows localhost:/20%20%/ < app name > / < profile >
Simply remove the post empty space. Then it should work !
In your bootstrap.yml file
Add these lines
spring:
cloud:
config:
enabled: true
uri: http://localhost:8888 ##this is the link to the server config
label: main ##this is what you are missing (name of the git repo branch)
application:
name: currency-spring-cloud-config-client
profiles:
active: testing
server:
port: 8600
spring:
cloud:
config:
enabled: true
uri:
- http://localhost:9196 ### your port for cloud config server
label: main ### your git repo branch name
In my case my server was fetching cofnigs from github repository, and I forgot that I made it private :)
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.