用 @Value("${xxxx}")注解从配置文件读取值的用法
2017-09-11 20:08
495 查看
1. 用法:
从配置properties文件中读取init.password 的值。
[java]
view plain
copy
print?
@Value("${init.password}")
private String initPwd;
2. 在spring的配置文件中加载配置文件dbconfig.properties :
[html]
view plain
copy
print?
<!-- 加载配置文件 -->
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="fileEncoding" value="UTF-8"/>
<property name="locations">
<list>
<value>classpath:dbconfig.properties</value>
</list>
</property>
</bean>
或者这样加载:
[html]
view plain
copy
print?
<context:property-placeholder location="classpath:dbconfig.properties" />
或者这样加载:
[html]
view plain
copy
print?
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="location">
<value>dbconfig.properties</value>
</property>
</bean>
3. dbconfig.properties 文件:
[b][html]
view plain
copy
print?
#MD5
password.algorithmName=md5
password.hashIterations=2
#initpwd
init.password=admin
从配置properties文件中读取init.password 的值。
[java]
view plain
copy
print?
@Value("${init.password}")
private String initPwd;
2. 在spring的配置文件中加载配置文件dbconfig.properties :
[html]
view plain
copy
print?
<!-- 加载配置文件 -->
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="fileEncoding" value="UTF-8"/>
<property name="locations">
<list>
<value>classpath:dbconfig.properties</value>
</list>
</property>
</bean>
或者这样加载:
[html]
view plain
copy
print?
<context:property-placeholder location="classpath:dbconfig.properties" />
或者这样加载:
[html]
view plain
copy
print?
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="location">
<value>dbconfig.properties</value>
</property>
</bean>
3. dbconfig.properties 文件:
[b][html]
view plain
copy
print?
#MD5
password.algorithmName=md5
password.hashIterations=2
#initpwd
init.password=admin
相关文章推荐
- 用 @Value("${xxxx}")注解从配置文件读取值的用法
- AntisHsu studying 通过读取.properties配置文件中的键值来实现动态添加注解内容例如@Controller @RequestMapping(value = "${adminPa
- <meta attribute="???">xxxx</meta>的用法 - hibernate配置文件生成java类
- springMvc 如何通过注解@Value 读取配置文件中的内容(.properties)
- Spring之@Value 注解获取properties值(Spring 3的@value简化配置文件的读取)
- 利用Spring的@Value注解读取配置文件
- spring提供读取配置文件中的属性注解@Value
- 使用Spring 3的@value简化配置文件的读取 (转)
- 在springmvc配置文件里面写默认的注解映射的支持的时候:<mvc:annotation-driven />The prefix "mvc" for element "mvc:annotation
- springmvc 通过注解读取配置文件
- Spring注解@Value及属性加载配置文件
- [dotNET]如何利用ConfigurationSettings.AppSettings.GetValues读取配置文件中多个同Key的value
- Spring-boot junit类读取config配置文件的注解
- Jar内外配置文件的读取public class JarReader { public static void main(String[] args) { String jarPath = "C
- java后台读取配置文件中key与value -----demo
- java后台读取配置文件中key与value -----demo2
- java中Class.getResource用法(用于配置文件的读取)
- [dotNET]如何利用ConfigurationSettings.AppSettings.GetValues读取配置文件中多个同Key的value
- @Value(value="${***.***}")配置文件赋值给static静态变量
- mysql启动读取数据库配置文件爆:对实体 "characterEncoding" 的引用必须以 ';' 分隔符结尾