spring boot configuration property values and acquire @ConfigurationProperties compare notes @Value

Feature Comparison:

 
  @ConfigurationProperties  @Value 
Mapping Assignment Batch injection configuration file attributes A designated
Loosely bound (loose syntax) ① stand by not support
SpEL② not support stand by
③ data check JSR303 stand by not support
④ complex type package stand by stand by

 

 

 

 

 

 
 
 
 
 
 

Explanation

① refers to the property value in the configuration file whether hump, underscore "_" cable "-" are supported, as written, in javaBean the property value can be obtained if the value of firstName

- person.firstName: Use a standard way 
- person.first -name: capital with - 
- person.first_name: uppercase with _ 
- PERSON_FIRST_NAME: Recommended system properties to use such an approach

 

②  value = " literal: {value}, from the environment variables: $ {key}, the configuration file to obtain the value: # {} SpEL
  column (" Development javaEE subversive "code):

  

@Value("I Love You!") 
private String normal;
@Value("#{systemProperties['os.name']}") 
private String osName;
@Value("#{ T(java.lang.Math).random() * 100.0 }") 
private double randomNumber;
@Value("#{demoService.another}") 
private String fromAnother;
@Value("classpath:com/wisely/highlight_spring4/ch2/el/test.txt") 
private Resource testFile;
@Value("http://www.baidu.com") 
private Resource testUrl;
@Value("${book.name}") 
private String bookName;

 

③ Reference: https://blog.csdn.net/qq_28867949/article/details/78922520

④ assignment of object, map, array and other objects. As ( Note that the wording of the configuration file, object properties ):

private Date birth;
private Map<String,Object> maps;
private List<Object> lists;
private Dog dog;

 

Guess you like

Origin www.cnblogs.com/jonrain0625/p/11330417.html