Spring Boot project not resolving placeholder variable when restarting with #reboot - spring-boot

I have this placeholder variable in the application-DEV.properties file:
vm.hostname=${hostname}
Apparently this is not being resolved when the app was auto-restarted after VM reboot via #reboot command. I got this well known error:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder "${hostname}"
But when I ran the app as a user on the VM, everything was OK. So I'm guessing at #reboot time, value of ${hostname} was not defined at the VM-level for the Spring Boot app to pick it up?

This jvm arg is required: -Dhostname=$HOSTNAME
Everything is working ok after adding this. Arg is required for #reboot as well as any crontab as well.

Related

Error configuring wildfly as a windows service

I am using wildfly 10.1 in standalone mode and need to use it as a service.
I copied the service files to the bin folder and then installed the service from the command prompt.
This works well, except that it is impossible to stop the service without killing the process using taskkill.
As a fix, I tried replacing
set DESCRIPTION="WildFly Application Server"
with
set DESCRIPTION=WildFly Application Server
in the service.bat file as mentioned here. But this is causing the service not to start. The system log says:
The Wildfly service terminated with the following service-specific
error: Incorrect function.
How can I fix this issue and get the service starting and stoppping normally?
Add System variable JAVA_HOME to System variable and try to start the service. It worked for me.

spring boot can't load environment variables

I use spring boot 1.3.3.RELEASE at my ubuntu 15.10 and try to configure my app via env properties like this (guided by https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html):
> export SPRING_REDIS_HOST=somehost
> echo $SPRING_REDIS_HOST
somehost
My application.properties contains:
spring.redis.host=localhost
The problem is that I never get somehost in my app.
Any ideas? Did I miss something?
Thanks, George
The reason is that I set env in another terminal window so java process doesn't see it. Everything works fine now.
You must set the correct systemPropertiesMode
http://docs.spring.io/spring/docs/4.2.5.RELEASE/javadoc-api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html#setSystemPropertiesMode-int-
the default value is fallback.
"If not being able to resolve a placeholder with the specified properties, a system property will be tried."

How to pass environment variable to Tomcat running as Windows service

I have an application installed in Tomcat that is invoked by the wrapper which sets an environment variable
set FOO=c:\foo
and invokes the startup.bat, and I have a requirement to run Tomcat as windows service.
So far, I tried to set the system environment variable, which did not help.
I tried following the windows service HOWTO appending ++Environment in the registry, so that
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tomcat7\Parameters\ImagePath
looks like this
C:\Apache\Tomcat-7.0.64\bin\Tomcat7.exe //RS//Tomcat7 ++Environment=FOO=c:\foo
That did not help either.
Any suggestions, please
You were almost there. Replace the equal sign with a space in your tomcat7 command, and that should work.
I've just written this up on another question: Setting User Environment Variables for tomcat on Windows
I had to change --JvmOptions of the service.bat file then remove the service and re-install again.
--JvmOptions "-Dspring.profiles.active=pp;-Dcatalina.home=%CATALINA_HOME%;...."
I have a InstallService.bat file. In the file I am first creating the service without specifying the Environment variable and then I am updating the service with the Environment variable specified.This is how the bat file looks like.
tomcat8 //IS//CompassTomcat8_8080 --DisplayName="Compass Apache Tomcat 8:8080" --Install=%CATALINA_HOME%\bin\tomcat8.exe --Startup=auto
tomcat8 //US//CompassTomcat8_8080 --DisplayName="Compass Apache Tomcat 8:8080" --Install=%CATALINA_HOME%\bin\tomcat8.exe --Startup=auto --Environment=Key1=Value1;Key2=Value2
It has started working now.

Error running Spring Batch Admin on Tomcat 6/7

I am getting this error when running a Spring Batch Admin template project created via STS 3.2 on vanilla Tomcat 6/7 on RedHat Linux:
Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [batch-L.properties] cannot be opened because it does not exist
I have no idea where that file is coming from. I tried searching for the file but to no success. Also, I need to add, that when running the same *war file on my local machine, everything works fine.
I will be grateful for any help.
Spring Batch Admin uses a system variable ENVIRONMENT to determine what properties file to load. By default, (if the variable isn't set), it will look for an HSQLDB version named batch-hsqldb.properties. In your case, it looks like the ENVIRONMENT variable is being set to the letter L.

Configuring Redis on Windows

I'm using the MsOpenTech version of Redis on a Windows 2008 server. I've installed via the RedisWatcher Service as described here, and this is working fine - the server is responding and data going in and out nicely, running multiple instances etc - so great.
I have one problem though - i'm attempting to use a redis.conf file to set some default configuration; the .conf file being stored in the same directory as redis-server.exe, namely c:\redis\bin
The config changes themselves are straighforward, i'm simply setting timeout to 20 seconds, thus:
timeout 20
but when I run the watcher service, connect to the server via the command line and do config get timeout, it returns 0
I've tried to restart the watcher service after making the updates to config. I've tried passing in the timeout value directly in the watcher.conf file for the service, like
cmdparms --timeout 20
and this doesn't work. I've attempted the same on a second instance, same results.
Interestingly, if I start a second instance of the redis server within the watcher, thus:
{
workingdir c:\redis\inst2
runmode hidden
saveout 1
cmdparms --port 6380
}
this works, respecting the --port argument and kicking off a second instance at port 6380. Although as mentioned above, passing a --timeout parameter or a config file parameter to this instance is not working either.
Setting configuration via the command line works fine, ie, when connected to redis:
config set timeout 20
This sets the timeout as expected, but obviously doesn't persist the setting beyond that session. This being version 2.6 of redis, I don't have access to the config rewrite command, so can't get around it that way.
Any ideas welcome.
In the end the answer was simple. Restarting the RedisWatcher service does not restart the redis-server.exe process.
Manually stopping this process and restarting via the watcher made the config changes be picked up.

Resources