Let’s say your application can work with 3 different
types of databases
o
H2 (Local Development)
o
Mysql (Development environment)
o
Mysql (Production environment)
o
And you want to utilize only related settings when
you are doing the development/testing/production debugging.
o
You can
actually create three different application.properties files and use the naming
convention which will later used to load the specific profile.
o
So for the given case put below 3 files under
your resources folder
§
application-default.properties
§
application-dev.yaml
§
application-prod.yaml
§
The above files can be found in the given github
project
o
And when you will run the project with “dev”
profile , all your settings will be loaded from application-dev.yml.
o
Notice here convention is used on configuration
and we didn’t need to specify any profiles or which property/yaml file to load
in case if a profile is active.
o
Example project
o
Note : We used SpringBoot defaults here for us
to do a lot of things , we didn’t need to define a spring bean for datasource
configuration , also we used convention and created those property and yaml
files to be loaded in case a specific profile is loaded.
o
Also please note we have only used properties
and yaml combination to show you how to use both in combination , you can use
all properties or all yaml files.
No comments:
Post a Comment