0% found this document useful (0 votes)
3 views16 pages

4.4.1 (TASK) Injecting Custom App Properties

Injecting_Custom_app_properties
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views16 pages

4.4.1 (TASK) Injecting Custom App Properties

Injecting_Custom_app_properties
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Injecting Custom Application Properties

By:MadSe
Application and Benefits of
Injecting Properties

By:MadSe
• Externalizing Configuration

• Custom properties allow you to externalize configuration,


making it easy to change values without modifying the
code.
• This is especially useful in different environments
(development, testing, production).

• Environment-Specific Settings

• You can define different property files for different


environments (e.g., "application-dev.properties",
"application-prod.properties").

• Spring Boot can then load the appropriate properties


based on the active profile.

By:MadSe
• Database Configuration

• Custom properties can be used to configure database


connection details, such as URL, username, and password.

• API Endpoints

• You can store external API endpoints as properties,


making it easy to change them without code changes.

By:MadSe
• Feature Toggles

• Feature toggles can be managed using custom properties


to enable or disable features dynamically.

• Centralized Configuration Management

• All configurations are centralized in properties files,


making them easier to manage and update.

By:MadSe
TASK  Injecting Custom
Application Properties

By:MadSe
• Objective :

• Injecting properties and values

• Steps :

1) Make a copy of our “commandline” or “mycoolapp”


application folder to create another app to keep the
applications organized.
2) Injecting properties in our “application.properties” file
3) Injecting properties into Spring Boot “controller” using
“@Value” so that we can expose endpoints to access
them

By:MadSe
Making a Copy out of Previous App

By:MadSe
• As given above, access the “commandline” project properties.
• Get the application folder path.
• Open the path in Windows File Explorer and create a copy
• Rename it to “custom_properties”
• Open the project in Net Beans again.
• NOTE : Only the folder name is changed. The name of the
project will remain the same.

By:MadSe
Injecting Properties in
“application.properties”

By:MadSe
• #11 - #12  Inserting our custom properties in “application.properties” file

By:MadSe
Injecting Properties in
Spring Boot Controller and Exposing
Endpoint

By:MadSe
• #5  Importing “@Value” annotation from the Spring Framework
• #13 - #18  Storing custom property values in variable names by annotating
them with”@Value”

By:MadSe
• #5  Importing “@Value” annotation from the Spring Framework
• #13 - #18  Storing custom property values in variable names by annotating them
with”@Value”
• #20 - #24  Exposing endpoint “/teaminfo” that will fetch the custom properties
info  NEXT, running the app
By:MadSe
• Make sure to open the main application java file as given above  Right-click 
Run File  Check out the output next

By:MadSe
• Above, accessing the endpoint successfully to display the custom properties.

By:MadSe

You might also like