@Value通过SpEL注入properties值

两种方式将键值对封装到java.util.properties中;

1.直接配置

<util:properties id="props">  
   <prop key="yong">test</prop>

   <!--利用占位符-->

   <prop key="yong">${test}</prop>  
</util:properties>


@Value("#{props.yong}")

private String yong

或者

public String test(@Value("#{props['yong']}") String yong){}


2.通过.properties文件注入

如paf.properties中有键值对

yong=test


<util:properties id="settings" location="classpath:paf.properties" />


@Value("#{props['paf.yong']}")  

你可能感兴趣的:(properties,value)