I have an application. It has multiple external (yaml) configuration files (ex; mongo.yml, redis.yml, etc). I would like Spring Boot to load these, so that they are accessible as expected inside the code base (aka, mongo.host, redis.port, etc).
This (directory) pattern is non-negotiable, as every other service in our architecture can handle it (and is currently using it).
How can I do this?
Notes:
The documentation leads me to believe that this:
java -jar app.jar \
--spring.config.location=config/ \
--spring.config.name=mongo,services
should do what I want: I'm specifying to look in the config/ directory for the mongo and services files (presumably, checking for both mongo.properties and mongo.yml?). However, this is not working; the values are still what appear to be the defaults. Also, it isn't what I want; each file has to be specified, instead of just the directory.
Is there a way to do this? Is there a way to get close?
Thanks!
Related
I want to embeded posgresql. i try to print help. there's no options to read config. but the weird. postgres read config from -D options, the file is postgresql.conf that create from initdb.exe. whichis data directory. but the config can set data dir location. so for me is weird management. why not like usual application. just have command to read config file. the real problem is postgres log give error dont know where the lib folder. from postgresql structure folder lib 1 up from bin.
posgresql
postgresql\lib
postgreseql\bin
what i want is lib folder inside bin.
project
project\bin
project\bin\lib
i try to set config that relate to library name, nothing help
dynamic_library_path 'c:\project\bin\lib'
local_preload_libraries
shared_preload_libraries
command that i use to start postgres server
pg_ctl start -s -W -D data -l log/system.log
I am not sure in which programming language or IDE you want to use PostgresSQL. Usually it is easiest to simply include the proper Nuget packages. And it is getting even more easier if you chose to use the EntityFramework to access your data.
When I start my spring boot app as a systemd service I receive this error:
start-stop-daemon: warning: this system is not able to track process names longer than 15 characters, please use --exec instead of --name.
Spring boot seems to build the process name from the jar name and the directory the jar is contained in. Is there any way to fix this aside from renaming the jar, and the directory it's contained in, to be shorter than 15 characters?
If I try to edit spring boots startup script to use --exec instead of --name then I get another error:
'start-stop-daemon: unable to stat /opt/program/programname_optprogramname (No such file or directory)
It appears that this issue is fixed in Spring boot 2.0.2. So if you run into this issue upgrading might fix it (not to imply that upgrading is always a simple effort)
We are using spring-boot with the embedded launcher-script in service mode, to have daemonized/init.d behavior.
We however do not have an /etc/init.d symlink to the spring-boot jar as that would require using sudo. we avoid sudo to pass a profile-environmental like -Dspring.profiles.active=$APP_PROFILE in the JAVA_OPTS
(this won't work when started via sudo but defined in /home/appuser/.bashrc (?) )
We have this directory-layout with some indirections. basically app.jar => current/app.jar => build-xx/app.jar
appuser#host:~/apps/services$ ls
app.jar -> /home/appuser/apps/services/current/services-1.0-SNAPSHOT.jar
current -> /home/appuser/apps/services/services-1298
services-1298
When starting the application with app.jar start the launch-script generates an additional pid-subdirectory in the pid-folder based on the "identity" of the program. For us this can look like this:
/home/appuser/apps/services/run/services-1.0-SNAPSHOT_homeappuserappsservicesservices-1298/services.pid
Unlike when used with an symlinked /etc/init.d which gets special treatment and the pid-subdir services-1.0-SNAPSHOT_homeappuserappsservicesservices-1298 is omitted/stays stable.
This dynamic pid-subdir makes it very hard for us to check the daemon's status or start/stop during deployment because you have to always get the sequence right and nobody is stopping you from starting a process twice (the old instance and now a new instance with a new identity-subdir).
So, does anyone know why this pid-subdir-identity stuff must exist and what would be our best way to deal with it?
Do we have a bad setup?
Any advice appreciated.
You can control the identity by using the APP_NAME environment variable.
I'd recommend configuring your service's environment variables using a .conf file next to the jar file. For example, if your app is called app.jar, you conf file should be named app.conf and be placed in the same directory as the jar. You can then configure APP_NAME and JAVA_OPTS etc for your application. This should allow you to use init.d if you so wish.
Is there some simple placeholder I can use in the application.properties, something like:
logging.file=myApplication-${timestamp}.log
without any additional xml files or anything like that?
No, you can't configure it without an additional logging configuration file specific to the logging framework itself (log4j, logback, ...). This is what the documentation mentions:
To configure the more fine-grained settings of a logging system you need to use the native configuration format supported by the LoggingSystem in question.
This answer explains how you could configure this for Logback.
If you are on unix based machine you can do so in shell script.
--logging.file=application-"$(date '+%Y-%m-%d:%H:::%M')".log
or
#!/bin/sh:
append_date = "$(date '+%Y-%m-%d:%H:::%M')"
java -jar spring-application.jar --logging.file=application-$append_date .log
I am using spring cloud config server to host a centralized location for all the property files configurations to be used in the project.
I tried using the config files from a local file system using below and it works fine:
spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=file://${HOME}/Documents/test-config/cloud-config-properties/
I also used the git repo using: spring.cloud.config.server.git.uri=ssh://xxxxxx.com:7999/test/cloud-config-properties.git
I would like to try using a combination of this in my project.
Example - for dev/test profile - i would like to use from local filesystem and for the production - I would like to use Git repository.
I enabled both the git uri and native profiles in my application.properties in config server application. But the properties are always picked up from the local file system. Is this possible?
Not supported out of the box, however there is a workaround for this. You can define the basedir for the configuration server, which is where it saves the files it fetches from the remote server, by setting the property (in the config server):
spring.cloud.config.server.git.basedir=<your_dir>
If you are working with docker, you can map this directory to the host filesystem.
Now whatever file you put in there will be picked up by configuration-server if it matches any of the application/profile in the request. For example you could put a file there called application-dynamic.properties, and have all your clients use dynamic as the last profile, for example
spring.profiles.active=systesting,dynamic
This way everything you will put in application-dynamic.properties will override whatever is defined in your config repo.
One thing to notice though is that you need to add the file only after configuartion server starts, because it deletes this folder during startup.
Needles to say, it's not a good practice doing this in production (for example a restart will cause the file to be deleted), but for test/dev this is the best option.