Spring MVC读取properties文件时遇到的问题
2017-09-01 11:25
190 查看
java读取properties配置文件方式有很多种,如果需要了解,自行google
1,spring项目读取properties文件,需要在配置文件中加
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config/db.properties</value>
<value>classpath:config/url.properties</value>
<value>classpath:config/parameter.properties</value>
</list>
</property>
</bean>
类似这种的配置,but
Controller和service的代码里,竟然需要两份配置,详情看这里:
http://www.cnblogs.com/shoren/p/spring.html
问题当时是,我在service中已经读取过配置文件信息了,但是在Controller中怎么就获取不到,最后需要配置两份上面的东西
感觉这个问题最终到了,spring配置文件的的问题了,这些配置文件的位置到底对项目有什么影响,以后再查,先记录下。
2、properties读取中文乱码
地址:http://www.cnblogs.com/kevin-yuan/archive/2012/08/25/2655851.html
总结起来就是,properties有自己的默认编码,读出来的时候不一致就乱了。
(当时自己的代码例子:String
cityList
= new
String(ele_contract_city_allow.getBytes("ISO8859-1"),
"UTF-8");
ele_contract_city_allow是在properties中读出的属性)
3、顺带一个别的常识
判断String为空效率较高的方法
if( str==null || str.length <= 0 ){}
不要用 "".equals(str) ,效率不高
1,spring项目读取properties文件,需要在配置文件中加
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config/db.properties</value>
<value>classpath:config/url.properties</value>
<value>classpath:config/parameter.properties</value>
</list>
</property>
</bean>
类似这种的配置,but
Controller和service的代码里,竟然需要两份配置,详情看这里:
http://www.cnblogs.com/shoren/p/spring.html
问题当时是,我在service中已经读取过配置文件信息了,但是在Controller中怎么就获取不到,最后需要配置两份上面的东西
感觉这个问题最终到了,spring配置文件的的问题了,这些配置文件的位置到底对项目有什么影响,以后再查,先记录下。
2、properties读取中文乱码
地址:http://www.cnblogs.com/kevin-yuan/archive/2012/08/25/2655851.html
总结起来就是,properties有自己的默认编码,读出来的时候不一致就乱了。
(当时自己的代码例子:String
cityList
= new
String(ele_contract_city_allow.getBytes("ISO8859-1"),
"UTF-8");
ele_contract_city_allow是在properties中读出的属性)
3、顺带一个别的常识
判断String为空效率较高的方法
if( str==null || str.length <= 0 ){}
不要用 "".equals(str) ,效率不高
相关文章推荐
- 通过Shell脚本读取properties文件中的参数时遇到\r换行符的问题
- spring使用@Value标签读取.properties文件的中文乱码问题的解决
- win7 web开发遇到的问题-由于权限不足而无法读取配置文件,无法访问请求的页面
- tomcat 读取 .properties 文件的问题
- 在读取segy文件时遇到的问题
- 读取Properties文件以及中文乱码问题
- 记录贴:configure.properties等propertie文件的读取问题
- Java 读取Properties文件时应注意的路径问题
- Java读取properties文件中文乱码问题解决
- 解决Java读取properties文件中文乱码的问题
- 遇到一个在脚本中读取文件内容占用文件句柄的小问题
- Java 读取Properties文件时应注意的路径问题
- scala 读取文件遇到encode问题(Mac -> remote Linux)
- C++类中包含string类型数据使用read和write实现文件读取和输出时遇到的问题
- 使用Spring MVC 实现文件上传遇到的问题以及解决方案
- 解决pandas使用read_csv()读取文件遇到的问题
- ifstream fileIn 读取文件遇到的问题
- 解决Java读取properties文件的中文问题的新办法(不使用native2ascii.exe及其他工具)
- Properties文件中文属性读取是乱码问题
- Java读取properties文件中文乱码问题解决