How to set an env variable's value as null - spring

Sorry if it's a repeat question. I couldn't find the answer anywhere.
My java application expects a password through an environment variable.
My staging environment doesn't have any password setup. How can I send a null value to the java application through env variable?
export pass=
If I put the above ^ in my ~/.bash_rc file, it isn't working.
EDIT :
I'm using spring & hibernate and taking the value in the XML. Something like the below:
<bean id="myclass" class="mu.package.Myclass">
<constructor-arg index="0" value="${pass}"/>
</bean>
If I replace ${pass} with ${pass:#{null}} to handle null checks with spel, it always takes the null value because the value is not present as a property but as an env variable. Is it possible for ${pass:#{null}} to check both properties & env variable before assigning null value?

Make sure your configuration has defined a PropertyPlaceHolder element in the XML:
<context:property-placeholder />
Then you simply need to make sure that by setting up the system environment variable that it is named exactly the same as your XML configuration expects for it to be translated.

Related

How to set enviroment variable Heroku

I need to set enviroment variable GOOGLE_APPLICATION_CREDENTIALS at .json format like service-account-file.json but i cant.
I tried this https://elements.heroku.com/buildpacks/buyersight/heroku-google-application-credentials-buildpack and this https://github.com/gerywahyunugraha/heroku-google-application-credentials-buildpack but it is not working.Heroku => java.io.IOException: Error reading credential file from environment variable GOOGLE_APPLICATION_CREDENTIALS, value 'google-credentials.json': File does not exist.
There is no such ways to set environment variable from json file you can use the environment variable like process.env.VARIABLENAME and define that variable name in config
Here i attach the screenshots from where you can define the variable

How to pass a parameter as an environment variable

How do you pass a parameter as an environment variable?
Step 1: Open up user bash file 'vim ~/.bash_profile', write the environment variable and save the file
export TWLIO_NUMBER=+303....
Step 2: In the application porperties file, store the variable
twlio_number=${TWLIO_NUMBER}
Step 3: Import Value in order to use it
import org.springframework.beans.factory.annotation.Value;
#Value("${twlio_number}")
private String TWILIO_NUMBER;
Also, if I hardcode the value in the application properties file, the code works.
Pass those as Java-Opts. It will work.
How to pass JVM arguments in SpringBOOT
https://www.baeldung.com/spring-boot-command-line-arguments
So I have a system variable in my spring project.
String dataSourceUrl = System.getenv(DEFAULT_CONNECTION);
I am looking for something quick to set the variable in command line.
I found this command work in mac
export DEFAULT_CONNECTION=value (value wrap in single quote to prevent the values being replaced)
You can check by env | grep DEFAULT_CONNECTION
run as usual mvn spring-boot:run

how to set application property variable with system eviroment

I need to set applcation properties variable with system variable Ex.
my system variable enviroment on widows is USER_NAME = admin
I want that set spring.datasource.username with USER_NAME
I tryed to do this mode:
in application.properties file
spring.datasource.username={USER_NAME}
but dind't set.
anybody knows how to do?
In your application properties the values should be with lower case and separated by point:
spring.datasource.username=${user.name}
Your environment variable should be as you've mentioned:
USER_NAME=admin

Windows batch script to replace a string

I have a txt file that looks like this:
file: config.txt
property name="java.nio.preferSelect" value="true"
property name="pico.rcp.platform.host" value="172.22.3.11"
property name="pico.rcp.platform.port" value="6790"
I want a windows batch script that will search for "pico.rcp.platform.host" string and change the IP value in that line regardless its value to the passed value in the command line. Like the following:
changeServerTo.bat "172.22.3.1" config.txt
the above script should make the file looks like this:
file: config.txt
property name="java.nio.preferSelect" value="true"
property name="pico.rcp.platform.host" value="172.22.3.1"
property name="pico.rcp.platform.port" value="6790"
and
changeServerTo.bat "172.22.100.221" config.txt
should make the file looks like this:
file: config.txt
property name="java.nio.preferSelect" value="true"
property name="pico.rcp.platform.host" value="172.22.100.221"
property name="pico.rcp.platform.port" value="6790"
and so on.
Your help is much appreciated.
Thanks in advance.
This script just rewrites the entire file and uses the parameter in the output
echo property name="java.nio.preferSelect" value="true" >config.txt
echo property name="pico.rcp.platform.host" value=%1 >>config.txt
echo property name="pico.rcp.platform.port" value="6790" >>config.txt

How to set the property value as DirectorySearch result in wix?

I am trying to set the property value to DirectorySearch result. It is working fine for absolute path like Path='C:\Program Files\SampleDir'.But it is failing if I use path like Path='[INSTALLDIR]'.
What I observed in case of path=[INSTALLDIR] it is searching for the file in C drive itself.But here [INSTALLDIR] original value is 'C:\Program Files\SampleDir'.If I change the Depth=2 then it is working fine. Whatever the property that I mention in Path attribute it is searching in C drive only.But it is working fine with absolute value of Path like Path='C:\Program Files\SampleDir'.
The code that I am using is
<Property Id='BACKUPFILESEXIST' Secure='yes' Value='ABC'>
<DirectorySearch Id='DirSearch' Path='[INSTALLDIR]' Depth='0' AssignToProperty='yes'>
<FileSearch Id='FileSearch' Name='EncodeDateAction.dll'/>
</DirectorySearch>
</Property>

Resources