spring使用@Value标签读取*.properties文件的中文乱码问题的解决


spring使.properties,spring.properties,使asci,.,


1.spring.xml,.properties使"utf8"

<context:property-placeholder location="classpath:conf/*.properties" file-encoding="UTF-8"/>

 

2.使:

@Component
@PropertySource(value = "classpath:conf/copyWriteUI.properties",encoding = "utf-8")
@Getter
public class CopyWriteUI {
    @Value("${a}")
    private String a;
    @Value("${b}")
    private String b;
    }

  

3.,unicode 
4. IntelliJIDEA!!!idea,! 
idea 会自动帮我们进行如上的第三步的

附录 spring <context:property-placeholder/> 的属性说明

<context:property-placeholder   
        location="属性文件,多个之间逗号分隔"  
        file-encoding="文件编码"  
        ignore-resource-not-found="是否忽略找不到的属性文件"  
        ignore-unresolvable="是否忽略解析不到的属性,如果不忽略,找不到将抛出异常"  
        properties-ref="本地Properties配置"  
        local-override="是否本地覆盖模式,即如果true,那么properties-ref的属性将覆盖location加载的属性,否则相反"  
        system-properties-mode="系统属性模式,默认ENVIRONMENT(表示先找ENVIRONMENT,再找properties-ref/location的),NEVER:表示永远不用ENVIRONMENT的,OVERRIDE类似于ENVIRONMENT"  
        order="顺序"  
        /> 

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM