問題記錄:

中文出現(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的報錯