Why prepending file location with file: in application.properties? - spring

I've seen some application.yaml files where a file path is prepended with file: like this:
ssl:
key-store: file:/etc/ssl/keystore.p12
What does a file: here stand for? I've searched Spring docs, but found only examples with file: (like here: https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-files), but not the actual meaning behind this keyword.
Why not just using an absolute path like /etc/ssl/keystore.p12 and pass it to FileInputStream

Related

Understanding the spring profile

I have basic idea how spring profile works. But here in this file this - i am not able to get it. And current Application.yml file mentioning the three profile which one will get active and when that i need to know as well. Below is the Application.yml file content.
spring:
application:
name:
profiles:
active:
-default
-local
-swaggerinfo
Note: i have three config files present in my resources. Also if i want to look another config file
then spring use the naming convention like Application-<Name>.extension . so - is already get added for the new config file then why we explicitly need
to put another one in our application.yml file under spring.profile.active.
Below are the names of the three config files present under the resources folder.
application.yml
application-local.yml
bootstrap-default.yml
But here in this file this - i am not able to get it. spring use the
naming convention like Application-.extension . so - is already
get added for the new config file then why we explicitly need to put
another one in our application.yml file under spring.profile.active
spring:
application:
name:
profiles:
active:
-default
-local
-swaggerinfo
The declaration of profiles are incorrect. You must either put space or should not use (-) at all.
spring:
profiles:
active:
- default
- local
- swaggerinfo
The Spring also supports the following way of declarations.
spring:
profiles:
active: default,local,swaggerinfo
or
spring:
profiles:
active:
default
local
swaggerinfo
Here default refers to application.properties file not bootstrap-default.properties. Also, You don't need to specify the default profile. Spring automatically use application.properties as default one. So, in your case it's appropriate to go with local and swaggerinfo.
current Aplication.yml file mentioning the three profile which one
will get active and when that i need to know as well.
Let's talk about the following declaration.
spring:
profiles:
active:
- local
- swaggerinfo
Both local and swaggerinfo profiles will be active for props loading. So,which means that all the three files (application.yml by default) will be consumed by spring.
Let's talk about the order.
The order in the above case would be
application -> application-local -> application-swaggerinfo
Note:
Assume that you've mentioned the same prop in all the three files then in that case the precedence will be given as per the order highlighted above i.e prop mentioned in the application-swaggerinfo will override the ones available in the other twos.

Spring Cloud Config Server serving nested plain text files

I have a Config Server up and running, with the relevant application.yml setting of
spring:
application:
name: config
...
searchPaths:
- '{application}'
- '{application}/{profile}'
I would like to access a file that is not application.properties, something like myfile.txt. If I have the git layout
/myapp/nested/folder/myfile.txt
I want to be able to access that file. According to the Spring Config Server docs, I should be able to do this via /{name}/{profile}/{label}/{path}, but I can't get any paths to work.
TL;DR: How do I retrieve nested config files from a git repo via Config Server?
TL;DR: The documentation is wrong. The endpoint /{name}/{profile}/{label}/{path} should be written as /{application}/{profile}/{label}/{path}. You just need to make sure that one of your searchPaths/{path} can resolve your file.
First off, {label} is, as always, the git branch name (probably "master").
Second, {path} can can be an absolute path to the file. It uses /, i.e., myapp/nested/folder/myfile.txt, not (_) as is required in {application} or {label}.
Third, the search paths in the question are set to '{application}' and '{application}/{profile}', along with the default search path of /, the git repo's root directory. These define the places Config Server will search for a plain text file as:
/{expanded application}/{path}
/{expanded application}/{profile}/{path}
/{path}
Note that only {application} can be expanded into multiple folders with (_) and that only {path} can include multiple folders with /. For instance, with these searchPaths and a file located at /myapp/nested/folder/myfile.txt, the following requests are valid:
/asdf/asdf/master/myapp/nested/folder/myfile.txt
/myapp/asdf/master/nested/folder/myfile.txt
/myapp/nested/master/folder/myfile.txt
/myapp(_)nested(_)folder/asdf/master/myfile.txt
/myapp(_)nested/folder/master/myfile.txt
where asdf can be any arbitrary string.

how to Appoint yml file path

I have use springboot to creat a project.
when I make yml file at src/main/resources/config or src/main/resources , I cant set :
spring:
profiles:
include:
- 'scheduling'
- 'yml'
in application.yml to appoint file file path,
and use #Value("${importance_info.message.notice}") to get the appointed value from
src/main/resources/config/application-scheduling.yml
but if I create yml not in the src/main/resources/config or src/main/resources, I can't get appointted value from it.
when I use #PropertySource(value = {"classpath:config/sub/sub-scheduling.yml"}), still can't get appointted.
Please tell me , how to make config or code to get appointed value from yml file in that file.

Spring command line JSON config containing array

I am using Grails 3 Elasticsearch plugin with Springs external JSON configuration by setting spring.application.json as system property.
The properties are available in the application but I can't find a way to initialize an array properly.
What I am trying to accomplish is to override the default values of the hosts property specified in my application.yml:
environments:
development:
elasticSearch:
client:
hosts:
- {host: "myhost.com", port: 9300}
- {host: "anotherhost.com", port: 9300}
I am setting the property from the command line as follows:
-Dspring.application.json={"environments":{"development":{"elasticSearch":{"client":{"hosts":[{"host":"override1.com", "port":9000},{"host":"override2.com", "port":9100}]}}}}}
I would expect environments.development.elasticSearch.client.hosts to contain an array like it does when initialized from the application.yml, but in fact environments.development.elasticSearch.client containes host[0] and host[1], where each contains the host and the port. The host array from the yml file is still there.
How can I achieve the same behavior using the command line as with the application.yml file?
I believe you can do this the same way that you would if it was set in a .properties file, using a list:
-Denvironments.developmet.elasticSearch.client.hosts={"host":"override1.com", "port":9000},{"host":"override2.com", "port":9100}
and I believe you can also do it as an environment variable...
set ENVIRONMENTS_DEVELOPMENT_ELASTICSEARCH_CLIENT_HOSTS='{"host":"override1.com", "port":9000},{"host":"override2.com", "port":9100}'
There may need to be some quotes around parts of these depending on the shell you are in, the OS, etc.

Symfony3: Splitting routing.yml in multiple files

I have a routing.yml file where I define the routes of my bundle. My routing file is growing bigger.
Is there a way to split the routing.yml file in multiple files in Symfony3 ?
I saw this question but it is for Symfony2. The path aren't the same.
In Symfony2, we did like this :
app_catalogs:
resource: "#AppBundle/Resources/config/routing/routing_catalog.yml"
prefix: /catalogs
I tried this but it doesn't work (my file is in the same level than routing.yml) :
app_catalogs:
resource: "app/config/routing_catalog.yml"
prefix: /catalogs
(When not importing from a bundle), you should use paths relative to the current directory of the configuration file, so for example:
app_catalogs:
resource: routing_catalog.yml
prefix: /catalogs

Resources