Spring.Reading from properties file

Any beanFactoryPostProcessor should be declared in @Configuration file with static, because configuration is being initialized in very begining.

Nothing needed, props a read from application.properties / application.yml file, but if you want to custmomize the file you can add annotation


Also we can use PropertySourcesPlaceholderConfigurer

By default we can read from resources/application.properties file, but we also can configure another one like this

create file myapplication.properties

mymessage=hello from app properties

configure spring

public class Config {
    public PropertySourcesPlaceholderConfigurer configurer() {
        return new PropertySourcesPlaceholderConfigurer();

call mymessage from someService

public class SomeService {
    private void init(String msg) {

and here we are

Also @ApplicationProperties can be used

This entry was posted in Без рубрики. Bookmark the permalink.