Spring Cloud Config File System Search Locations-Having Application name specific folders - spring

I have around 10 applications and I am storing all the property files in one location on the file system. So suppose for example- All my property files are inside C:/Config.
Now what i want to do is have an application named folder structure. So lets say I have 3 applications named A,B and C. Then a folder structure like-
C:
-Config
-A
-env1(profile)
-A-env1.yaml
-env2
-A-env2.yml
-B
-env1
-B-env1.yml
-env2
-B-env2.yml
-C
-env1
-C-env1.yml
-env2
-C-env2.yml
Is this possible to achieve? I have gone through the documentation and have tried few things like adding the following in search Locations-
file:///C:/Config/${application}/${profile}
file://C:/Config/${label} (label tag which is there by default)
This doesn't work though.
Any help is much appreciated.
Thank you in advance.

You can load application properties from arbitrary file-system location.
By default Spring reads the following directories (taken from docs):
1)A /config subdirectory of the current directory
2)The current directory
3)A classpath /config package
4)The classpath root
You can also refer to an explicit location using the spring.config.location environment property (comma-separated list of directory locations, or file paths).
Example:
java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties

Related

custom yaml configuration files in a config folder outside the project (Spring)

I have a project with some config files. I need to externalize them to allow the user to edit them. It's a spring boot application and my files are in a yaml format.
It's not application.yaml, it's some custom files with different names.
I use bean annotations. For example, one of my beans looks like this :
#Configuration
#ConfigurationProperties
#PropertySource(value="globalConfiguration.yaml", factory = YamlPropertySourceFactory.class)
public class GlobalConfiguration {
//some fields
//accessors
}
When the file is in src/main/resources, it works well but once built it reads the file inside the jar (which is normal)
What I would like to do is to read in priority the yaml file from a config folder which is near the lib folder like this :
- bin
- config
globalConfiguration.yaml
- lib
myApp.jar
I tried using the parameter --spring.config.location="classpath:./config/" (and /./config and ././config and /config and config...) but nothing work I have this error :
***************************
APPLICATION FAILED TO START
***************************
Description:
Config data location 'classpath:/./config/' does not exist
Action:
Check that the value 'classpath:./config/' is correct, or prefix it with 'optional:'
EDIT :
Now I tried to add my config files to the classpath like this :
set CLASSPATH=%APP_HOME%\config\*;%APP_HOME%\lib\myJar.jar;someDepencies.jar
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %MYAPP_OPTS% -classpath "%CLASSPATH%" my.Main.Class %*
It's the bat generated by gradle when I build the project so I just added %APP_HOME%\config\*; to the classpath variable.
But it didn't change anything.
Finally it had nothing to do with the classpath. the spring.config.location works perfectly well but the directory used is the current one when launching the bat and my app was on a windows shared folder so I wasn't able to do a cd \mysharedfolder.. .
To make it works, there was two option :
To move the app in a local folder. Then move to the folder of the app and so the relative path works from there.
The second option is to set the complete path of the config folder like this :
--spring.config.location="\\\\mysharedfolder\\someSubDirectories\\config\\"

Copy to directory outside of project directory using Gradle 4.0.2

I have a gradle build which generates war file. I want to copy war file to my application servers' dropins directory which is somewhere outside of project directory. I have following copy task to do this.
task copyWarToDropins(type: Copy,dependsOn:[war]) {
from './build/libs/bds-service-token-1.0-SNAPSHOT.war'
into file('/apps/dropins') // want to copy to 'C:/apps/dropins' directory
rename { fileName -> 'bds-service-token.war' }
}
build.dependsOn copyWarToDropin
It evaluates /apps/dropins relative project directory and does copy there. I have tried many ways I can think of but could not make it copy to C:/apps/dropins directory.
Can someone please help?
First, please note that using into file(...) is redundant, as each call to into(...) will be evaluated via Project.file(...) anyhow.
As you can read in the documentation , file(...) handles strings in the following way:
A CharSequence, including String or GString. Interpreted relative to the project directory. A string that starts with file: is treated as a file URL.
So, one way to solve your problem could be using an absolute file URL.
However, if you continue to read the documentation, you will see that Java File objects are supported. So you could simply create such an object:
into new File('C:/your/absolute/path')

Spring Boot on Tomcat set file Paths in properties file

I want to set my relative file path in a properties file so my SaxReader can pick it up when it runs on Tomcat server. I know this should be easy but I've forgotten forgive me :)
I know Spring Boot has application.properties file but I don't see a way to hook in here.
Is there a way to set the relative path in a properties file that will get picked up by Spring Boot and the SaxReader will see it?
As it is I'm hard coding just the filename and putting the file in the resources folder that serves up the templates and static content such as css and js files. The filePath system.out gives: org.dom4j.DocumentException C:sts-bundle\sts-3.7.2.RELEASE\myFileName the toolsuite root location??? weird!!
Please tell me how to specify the relative path in a properties file.
Thanks!!
You can set the file path like any other string property in Spring Boot properties file and access it from inside the path.
E.g. I have the following set in my application.properties file:
download.directory=temp
and it is used as follows in java class:
#Value("${download.directory}")
private String downloadDirectory;
It is used to download the files, now, if I start the application with jar file present in let's say G:/applications folder then the files will be downloaded into G:/applications/temp.

TOMCAT 7 Access properties file outside WEB INF/classes

So i can access properties file if its in WEB-INF/classes.
However if I keep the same file under TOMCAT/conf and updating catalina.properties to point to the path, I get an error like Name not bound.
I have almost tried everything...even tried with absolute path
if your file.properties file is in the WEB-INF/classes folder? Then:?
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("/file.properties");
Only way I could solve it was
1. Create a env folder under tomcat_home and put the config.properties there
2. update catalina.properties and add the tomcat_home\env path in common loader
3. Comment out from spring security XML
Once I commented the above line It ran fine.

set class path in weblogic 11g console

How to set class path in weblogic 11g console for classes present in web-inf/classes/
And my classes are in the below structure which needs to be set as class path to avoid exception which needs these classes to be loaded first.
/com/cdy/ws/a.class files
/com/cdy/ws/b.class files
/com/cdy/ws/c.class files
Please help,
Thanks
If you are looking for WebLogic specific...
Lets say your web application dependent jars defined as:
WS_CLASSPATH=/com/cdy/ws
set in your environment variable.
That means your weblogic server can be loaded with weblogic.jar its relavent jars then, your WS_CLASSPATH can be added in the setDomainEnv.sh/cmc script find the EXT_PRE_CLASSPATH and assign to it.
EXT_PRE_CLASSPATH=$WS_CLASSPATH
There will be opposite side of CLASSPATH after the weblogic specific libraries available with EXT_POST_CLASSPATH in the setDomainEnv script.
The startup or shutdown class must be on the classpath of each server to which it is assigned.
To add a class to a server's classpath, do one of the following:
If you use a script to start a server instance, open the script in a text editor. In the command that sets the classpath, add the pathname of the directory that contains your class root package.
Then restart the server.
For example, you create a startup class named StartBrowser in a package named com.mycompany.startup. You archive the class file in a JAR file named c:\myDomain\src\myJAR.jar.
The start script for your server must add c:\myDomain\src\myJAR.jar to the server's classpath.
If you use the Node Manager to start a server instance, do the following on each server that runs the startup class or shutdown class:
In the left pane of the Console, expand Environment and select Servers.
On the Servers page, click on the server name.
Select Configuration > Remote Start.
In the Classpath field, enter the pathname for the classes that WebLogic Server requires to be on the classpath.
Use an absolute pathname or a pathname that is relative to the Node Manager's home directory.
Separate multiple classes with the type of separator that your operating system or shell requires.
For example, on Windows, use ; (semicolon) and in a BASH shell, use : (colon).
For example, weblogic.jar must be on the classpath. For a complete list, refer to Required Environment and Syntax for weblogic.Server.
In the Classpath field, add the pathname for your class or for a JAR file that contains your class.
For example, you create a startup class named StartBrowser in a package named com.mycompany.startup. You archive the class file in a JAR file named c:\myDomain\src\myJAR.jar. In this case, the Classpath field should contain the following value:
c:\Oracle\Middleware\wlserver_10.3\server\lib\weblogicsp.jar;c:\Oracle\Middleware\wlserver_10.3\server\lib\weblogic.jar;c\myDomain\src\myJAR.jar
step1)Class path can be set using ./setWLSEnv.sh(/wlserver_10.3/server/bin)
step2)Adding a jar file to class path abc.jar to this location(wlserver_10.3/server/lib) and follow step1
If in case you need to set Domain ./setWlEnv.sh(Domain_Home/bin) avil here

Resources