狠狠综合久久av,国产白丝在线观看,精品一区二区国语对白,欧洲在线视频

聯系我們 - 廣告服務 - 聯系電話:
您的當前位置: > 關注 > > 正文

全球熱點評!配置文件中文亂碼怎么解決?訪問多個配置文件的的處理

來源:CSDN 時間:2023-01-06 08:17:28


(相關資料圖)

package com.bojia.fund.proconfig;import org.springframework.beans.factory.annotation.Value;import org.springframework.context.annotation.PropertySource;import org.springframework.stereotype.Component;@Component@PropertySource(value={"classpath:application.properties","classpath:message.properties"},encoding="UTF-8")//設置編碼格式public class MessageProperty {@Value("${msg_nopay}")private String msg_nopay;public String getMsg_nopay() {return msg_nopay;}}

文件目錄結構為src/main/re/application.properties,

src/main/resources/message.properties.

我這里有兩個配置文件,如果要引用MessageProperty 這個類的話在server層或者controller層加上如下代碼:

@Controllerpublic class TestController {@AutowiredMessageProperty property;@RequestMapping(value = "/index.do",produces="text/plain;charset=UTF-8",method = RequestMethod.GET)public String index() {    //你的代碼return null;}}

我這里是controller,server層也是一樣,就可以使用了,注意:

1.要用到@value這個注解的話,不要new,否則取不到值,我這里用的是@Autowired     MessageProperty property;還有application.properties在resources目錄下,如果出現掃描不到xxx.properties等自定義配置文件的話可能是你的

@PropertySource(value={"classpath:application.properties","classpath:message.properties"},encoding="UTF-8")配置錯誤,注意不要寫成

@PropertySource(value={"classpath:resources/application.properties","classpath:resources/message.properties"},encoding="UTF-8"),否認你會啟動報錯的,因為SpringBoot會依次默認從 src/main/resources/等路徑下查找文件,你就不要多此一舉在前面加一個"resources/"了

2.如果出現配置文件中文亂碼就在注解@PropertySource里面加上encoding="UTF-8",可以解決配置文件中文亂碼問題!

3.多個配置文件的話@PropertySource要用value={"classpath:application.properties","classpath:message.properties"}來指定

4.@value得注解在@Component,@Server,@Controller下都可以拿到值

責任編輯:

標簽: 配置文件

精彩放送:

新聞聚焦
Top 主站蜘蛛池模板: 玉林市| 古蔺县| 二手房| 石狮市| 徐汇区| 固原市| 绥滨县| 岱山县| 陇川县| 林周县| 泗水县| 乌拉特前旗| 仙居县| 九江县| 宣城市| 拉孜县| 开封市| 基隆市| 漠河县| 云阳县| 开化县| 吴江市| 临江市| 海宁市| 闸北区| 新巴尔虎左旗| 武乡县| 安图县| 什邡市| 万源市| 和平区| 仙桃市| 右玉县| 葵青区| 平陆县| 株洲市| 开封县| 汨罗市| 梅州市| 宁乡县| 来安县|