spring boot整合swagger時,打開swagger-ui中文出現(xiàn)亂碼

問題記錄:


中文出現(xiàn)亂碼.png

本例采用的swagger版本及相關組件

<!-- swagger2 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
            <exclusions>
                <exclusion>
                    <groupId>io.swagger</groupId>
                    <artifactId>swagger-models</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-models</artifactId>
            <version>1.6.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <!-- swagger2 -->

問題出現(xiàn)原因:
加入了Shiro后就出現(xiàn)了亂碼,可能是在加入Shiro的時候編碼選擇錯了,網(wǎng)上介紹的辦法大多是在setting設置以及對tomcat的設置,但是還是不得,在先不探討Shiro倒置的情況下,找到了如下的解決辦法
在config類中,繼承自WebMvcConfigurationSupport類,重寫以下方法:

@Override
public void configureMessageConverters(List> converters) {
    super.configureMessageConverters(converters);
    converters.add(responseBodyConverter());
}
@Bean
public HttpMessageConverter responseBodyConverter() {
    return new StringHttpMessageConverter(Charset.forName("UTF-8"));
}

@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
    configurer.favorPathExtension(false);
}

注意:不要直接在swagger配置類直接繼承WebMvcConfigurationSupport,不然會出現(xiàn)
No mapping for GET /swagger-ui.html的報錯

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容