I’ve succeed to externalize my spring-boot configuration file (application.properties) in a config folder when I run my spring-boot application as a unix service with the help of the official spring documentation https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
I have also some i18n messages.properties files in my src/main/resources that I would like to externalize in the same config folder but I failed to do it. I’ve tried a lot of things, like playing with spring.messages.basename but unfortunately, it doesn’t work.
I’m using the latest version of spring-boot, and use auto configure mode with the default i18n properties name messages.
What am I missing??? thanks for your help.
Just a few notes:
classpath:message - will always lookup embeded message_xxx files
classpath:/message and classpath:message are equivalent
file:message - will lookup jar's external current directory e.g. ./message_en.properties <- this is what you want
file:/message - you have to put your message files to root "/" to make it work
use notation file:config/message if you need to put in config folder together with your
./config/application.properties
I think you need a leading slash.
Try: spring.messages.basename=classpath:/config/messages
I think, resource bundle is default to classpath. So there's no need to append it. just go straight to your folder location from classpath.
Try this: **assuming your config is inside static folder
spring.messages.basename=static/config/messages
Related
My project structure looks like as attached file. Even though I have profile specific properties, I would like to run my app with external properties file i.e., outside of jar file.
I tried with following command:
java -jar test_service.jar --spring.config.location=file:///C:/external_props/test.properties
But its taking application-default.properties file.
from log file:
No active profile set, falling back to default profiles: default
Why it is not taking external properties file ?
When you pass --spring.config.location command line argument SpringBoot won't consider application-*.properties files in src/main/resources directory. The filename you mentioned for --spring.config.location is taken as base filename, in your case test. So, it will only load test.properties file from that path you provided as default profile.
If you want to enable certain profile, say prod, you need to create file C:/external_props/application-prod.properties and enable prod profile using --spring.profiles.active=prod.
Spring will automatically look for some property file in a specific location.
From where you execute the jar file, Spring will look in that directory for a property file called application.properties
An other way is to put a config directory in the directory you execute the jar from and put the application properties in there.
There is one more option and that is the -Dspring.profiles.active={profiles} parameter.
Spring will then look in the directory or config directory to application-{profile}.properties
Reference:
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
Also i think you use the
--spring.config.location=file:///C:/external_props/test.properties
is not used correctly for a windows based file path.
Windows uses the \ instead of the /.
I just installed jetty 9.4.6. I dropped one of the war files from the demo area into $JETTY_BASE/webapps. The war file got expanded into /tmp/jetty-10.1.100.103-8080-test.war-_test-any-4774924669679182185.dir
I then tried a curl on it like this: :8080/test/index.html. I get a 503 error. I verified that index.html exists.
So does jetty serve the compressed war file or does it serve from the tmp folder? Any doc links would be greatly appreciated.
Yes, it creates a temp directory, though you can also define and persist your own if you'd like.
By default, Jetty will create this directory inside the directory
named by the java.io.tmpdir System property. You can instruct Jetty to
use a different parent directory by setting the context attribute
org.eclipse.jetty.webapp.basetempdir to the name of the desired parent
directory. The directory named by this attribute must exist and be
writeable.
You can find more in the official documentation here.
I have a Spring Boot project that I'm running as an executable jar started as an init.d service on Linux.
I understand I can create a .conf file with the same name as the jar file to specify JVM parameters. However, I would ideally like to "hard code" some parameters so there is no risk of the .conf file being missing. This is a real risk as each deployment will have a different jar name because of the version number.
Also I know I can set the environment variable JAVA_OPTS, but I'm not sure how to do this if I'm launching the Spring Boot as a init.d service using a symlink to the jar file.
Lastly I know I can replace the init.d script completely using the embeddedLaunchScript parameter, but I fell this overkill for what I want to accomplish and would want updates to the script in further releases.
Is there a way to specify JVM parameters in the Maven plugin or some other programmatic method?
Alternatively is there a way to hard code a static CONF file name? Looking at the embeddedLaunchScriptProperties it looks like confFolder can the folder, but not the name of the .conf file.
As of Spring boot 2.0, you can set the inlinedConfScript property of the build plugin. You can now reference a file that includes the appending or overwriting the JAVA_OPTS variable before the application starts. More details can be found in the Spring Documentation.
I have a Maven Netbeans Application I want to modify its configuration. What do I need to do to change startup parameters from the conf file like: default_options?
I have to manually do it but would like to make it part of the build process.
You will have to create a netbeans.conf file in your nbm-application project and point the nbm-maven-plugin to it's location - please see http://mojo.codehaus.org/nbm-maven/nbm-maven-plugin/cluster-app-mojo.html#etcConfFile
Create your own ProjectName.conf, for example from default ProjectName.conf file.
Next place it in nbproject folder.
And add to project.conf line like this:
app.conf=nbproject/ProjectName.conf
Support for Custom Configuration Files in NetBeans
I have an application which uses Equinox as an osgi framework for a while now. Until now I used the system property osgi.install.area to specify where my bundles are like so
${osgi.install.area}/
plugins/
org.eclipse.osgi_3.7.0.v20110613.jar
... my app bundles
Equinox then automatically uses ${osgi.install.area}/configuration as the configuration area.
Everything works fine.
Now I need to move the configuration area out of ${osgi.install.area} because that may be read-only and I thought it was as simple as setting ${osgi.configuration.area} to a suitable path but when I do this the application no longer starts and I have the following stack trace in the logs:
java.lang.IllegalStateException: Unable to acquire application service. Ensure that the org.eclipse.core.runtime bundle is resolved and started (see config.ini).
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:74)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at org.eclipse.core.runtime.adaptor.EclipseStarter.main(EclipseStarter.java:150)
...
The path is used because at that location the log file is created and a directory "org.eclipse.osgi".
Paths to bundles are referenced in my config.ini like so:
osgi.bundles=de.mycomp.app-0.6.0.20121116-1834.jar#start, ...
The error message does not really give a hint where to look. It must be something rather simple but I am rather clueless at the moment.
Thanks in advance,
Robert
I tested changing the configuration area an existing osgi app and it worked, with the following argument below in the .ini file in the root of the install. Are you sure you are setting the config param correctly like this:
-Dosgi.configuration.area=c:\mytest
After doing that and running the app again, it created the folder and a new configuration.
Here is a copy of my .ini file that works, also it's important that osgi params come after and vm args.
-loglevel=trace
-vmargs
-Dosgi.configuration.area=c:\mytest
-Dorg.osgi.service.http.port=8094
-Declipse.ignoreApp=true
-Dosgi.noShutdown=true
-Dequinox.ds.print=true