Showing posts with label Externalise. Show all posts
Showing posts with label Externalise. Show all posts

Sunday, March 28, 2021

Externalisation of Reloadable Properties Spring Application

org.springframework.context.support.ReloadableResourceBundleMessageSource 
.setBasename(String Full_Filepath_of_Properties_Files_Without_Prefix)

SetBaseName/SetBaseNames- Sets Filepath without extension
You can add Multiple Filepaths as well

getMessage(String key, PlaceHolder Args, Locale)
--------------------------------------------------------------
Load resource from the application root folder
"file:data.txt"

Load resource from classpath
classpath:data.txt"

Load resource from the filesystem
file:///c:/temp/filesystemdata.txt"

Load resource from URL
https://testsite.com/data.txt"

-----------------------------------------------------

https://dzone.com/articles/working-with-resources-in-spring

https://en.wikipedia.org/wiki/File_URI_scheme


A file URI takes the form of

file://host/path

Unix[edit]

Here are two Unix examples pointing to the same /etc/fstab file:

file://localhost/etc/fstab
file:///etc/fstab

Windows[edit]

Here are some examples which may be accepted by some applications on Windows systems, referring to the same, local file c:\WINDOWS\clock.avi

file://localhost/c$/WINDOWS/clock.avi
file:///c:/WINDOWS/clock.avi

where host is the fully qualified domain name of the system on which the path is accessible, and path is a hierarchical directory path of the form directory/directory/.../name. If host is omitted, it is taken to be "localhost", the machine from which the URL is being interpreted. Note that when omitting host, the slash is not omitted (while "file:///foo.txt" is valid, "file://foo.txt" is not, although some interpreters manage to handle the latter).

RFC 3986 includes additional information about the treatment of ".." and "." segments in URIs.

-----------------------------------------------------

@Bean @Scope(BeanDefinition.SCOPE_SINGLETON)

public ReloadableResourceBundleMessageSourceWrapper reloadableResourceBundleMessageSource(String externalFilePath) { ReloadableResourceBundleMessageSource reloadableResourceBundleMessageSource = new ReloadableResourceBundleMessageSource reloadableResourceBundleMsgSource.setBasename(externalFilePath);//Full Filepath of Properties/XML , file: or classpath: or relativePath reloadableResourceBundleMsgSource.setCacheSeconds(60);//After 60 Seconds, It tries to validate Cache again - Tries to read file again return reloadableResourceBundleMsgSource; }

--------------------------------------------------------------------

org.springframework.context.support.ReloadableResourceBundleMessageSource

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/support/ReloadableResourceBundleMessageSource.html

public final String getMessage(String code, 
                               @Nullable Object[] args,
                               Locale locale)
                        throws NoSuchMessageException


Specified by: getMessage(...) in MessageSource

Parameters:code the message code to look up, e.g. 'calculator.noRateSet'.

MessageSource users are encouraged to base message names on qualified classor package names, avoiding potential conflicts and ensuring maximum clarity.

args an array of arguments that will be filled in for params withinthe message (params look like "{0}", "{1,date}", "{2,time}" within a message),or null if nonelocale the locale in which to do the lookupReturns:the resolved message (never null)

Throws:NoSuchMessageException - if no corresponding message was found

--------------------------------------------------------------------

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/support/AbstractResourceBasedMessageSource.html

void setBasename(String basename)

Set a single basename, following the basic ResourceBundle convention of not specifying file extension or language codes.

void setBasename(String basename);

Set an array of basenames, each following the basic ResourceBundle convention of not specifying file extension or language codes.


About message resource keep note:
A plain path will be relative to the current application context.
A "classpath:" URL will be treated as classpath resource.
A "file:" URL will load from an absolute file system path.
Any other URL, such as "http:", is possible too.

--------------------------------------------------------------------

//Set the number of milliseconds to cache loaded properties files.
void	setCacheMillis(long cacheMillis)

//Set the number of seconds to cache loaded properties files.
void	setCacheSeconds(int cacheSeconds)


Azure - Pipeline - Add Approver for Stage

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops&tabs=check-pass