SpringMVC 读取配置文件
2016-12-16 16:21
447 查看
一、不通过注解
1.Spring 配置
2.通过ClassPathResource类 加载 配置文件
1.spring 配置
2.注解获取
1.Spring 配置
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:config.properties</value> </list> </property> </bean>
2.通过ClassPathResource类 加载 配置文件
private static Properties props = new Properties(); static { try { props.load(new ClassPathResource("config.properties").getInputStream()); } catch (FileNotFoundException e) { e.printStackTrace(); System.exit(-1); } catch (IOException e) { System.exit(-1); } }
public static String getKeyValue(String key) { return props.getProperty(key); }二、通过注解(Spring 4支持)
1.spring 配置
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:config.properties</value> </list> </property> </bean>
2.注解获取
@Value("#{propertyConfigurer['jdbc.jdbcUrl']}") private String jdbcUrl;
相关文章推荐
- springmvc 通过注解读取配置文件
- springMvc 之 【javaBean读取属性配置文件中的值】---注解方式
- springmvc如何通过properties读取配置文件
- springMVC中读取配置文件连接数据库
- springMvc 之 【javaBean读取属性配置文件中的值】---非注解方式
- springmvc通过@Value注解读取Properties配置文件的值,junit测试可以取到值,但是在业务中无法读取
- SpringMVC(11):利用数据流InputStream 读取调用 database.properties 配置文件的内容及实例
- springmvc中使用webuploader上传多张图片;maven中读取配置文件中的属性(路径)
- springMvc 如何通过注解@Value 读取配置文件中的内容(.properties)
- SpringMVC通过@Value读取配置文件
- 关于用<fmt:message>标签读取springmvc配置的国际化资源文件显示为???key???的错误原因
- springmvc resources 读取配置静态文件目录
- SpringMVC中如何读取配置文件中的值
- 一个不错读取Configuration文件的类,方便设置配置文件
- 配置文件读取类
- 脚本引擎之----读取INI配置文件
- 自定义配置文件的读取
- Python读取XML配置文件小例子
- 读取ini配置文件的API