Java.SpringBoot.InjectingProperties

example

public class GreetingsServiceImpl implements GreetingsService {

    @Value("${myProperty:defaultValue}") 
    private String property;

    @Override
    public GreetingUI getGreeting() {
        // will read from resources/application.properties or will take default value
        String propValue =  property;
        return new GreetingUI().message("greeting from backend");
    }
}

/resources/application.properties

myProperty = helloThere;

Details

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