通过@Value注解读取.properties配置内容
2017-06-11 10:15
323 查看
方案一:
applicationContext-dao.xml中添加
<!-- 加载配置文件 -->
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:properties/*.properties</value>
</list>
</property>
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="properties" ref="configProperties" />
</bean>
Service、Controller层调用代码:
@Value("#{configProperties['jdbc.url']}")
private String url;
方案二:
applicationContext-dao.xml、springmvc.xml中添加
<!-- 加载配置文件 -->
<context:property-placeholder location="classpath:properties/*.properties" />
Service、Controller层调用代码:
@Value("${jdbc.url}")
private String url;
applicationContext-dao.xml中添加
<!-- 加载配置文件 -->
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:properties/*.properties</value>
</list>
</property>
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="properties" ref="configProperties" />
</bean>
Service、Controller层调用代码:
@Value("#{configProperties['jdbc.url']}")
private String url;
方案二:
applicationContext-dao.xml、springmvc.xml中添加
<!-- 加载配置文件 -->
<context:property-placeholder location="classpath:properties/*.properties" />
Service、Controller层调用代码:
@Value("${jdbc.url}")
private String url;
相关文章推荐
- Spring MVC 通过@Value注解读取.properties配置内容
- Spring MVC 通过@Value注解读取.properties配置内容
- 通过@Value注解读取.properties配置内容
- Spring MVC 通过@Value注解读取.properties配置内容
- 通过@Value注解读取.properties配置内容
- 通过@Value注解读取.properties配置内容
- 通过@Value注解读取.properties配置内容
- 通过@Value注解读取.properties配置内容 (续)
- 通过@Value注解读取.properties配置内容
- 通过@Value注解读取.properties配置内容
- Spring MVC 通过@Value注解读取.properties配置内容
- 通过@Value注解读取.properties配置内容
- springMvc 如何通过注解@Value 读取配置文件中的内容(.properties)
- SpringMVC通过@Value注解读取.properties配置
- Spring MVC 通过@Value注解读取.properties配置
- AntisHsu studying 通过读取.properties配置文件中的键值来实现动态添加注解内容例如@Controller @RequestMapping(value = "${adminPa
- SpringMVC通过@Value注解读取.properties配置
- Spring MVC 通过@Value注解读取.properties配置
- Spring MVC 通过@Value注解读取.properties配置
- springmvc通过@Value注解读取Properties配置文件的值,junit测试可以取到值,但是在业务中无法读取