asd
当我们经常用如下的硬解码方式来配置文件: <bean id="SgtPeppers" class="com.CDDemo.SgtPeppers" p:title="sgt" p:song="Twinkle, twinkle, little start"> <property name="title" value="sgt"/> <property name="song" value="Twinkle, twinkle, little start"/> </bean> 但有时我们需要避免硬解码,需要想要这些值在运行时确定,Spring提供了两种在运行时求值的方式: 属性占位符 Spring表达式语言(SpEL) 1.注入外部的值 在Spring中,处理外部值得最简单方式就是申明属性源并通过Spring的Enviroment来检索属性.例如: @Configuration @PropertySource("classpath:app.properties") public class ExpressionTest { @Autowired Environment environment; @Test public BlankDisc disc(){ return new BlankDisc( environment.getProperty("disc.title"),