Spring Boot/Spring Cloud解决中文乱码
2017-12-25 17:31
465 查看
乱码的描述(废话):
中文都成了乱码。
我在网上找了很多解决方案,但是基本上都没解决我的问题,直到翻了一下午的帖子找到了一个解决我项目乱码的一个解决方案。一般乱码问题基本上都是运行环境或者项目配置的问题(除了新手在编程的时候项目编码不规范)。
以下是解决方案:
1:项目配置问题,在接收请求后相应时乱码问题,说明在构建相应时的字符集有问题,maven项目我这边没遇到过(不一定其他猿类没有遇到过),解决方案:
@Configuration
public class CustomMVCConfiguration extends WebMvcConfigurerAdapter {
@Bean
public HttpMessageConverter<String> responseBodyConverter() {
StringHttpMessageConverter converter = new StringHttpMessageConverter(
Charset.forName("UTF-8"));
return converter;
}
@Override
public void configureMessageConverters(
List<HttpMessageConverter<?>> converters) {
super.configureMessageConverters(converters);
converters.add(responseBodyConverter());
}
@Override
public void configureContentNegotiation(
ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
}
}
2:maven运行环境问题,我的项目就是运行环境上的问题,主要原因是使用了spring boot的maven插件,以spring:run运行的项目,需要在插件中添加运行的编码配置:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
</configuration>
</plugin>
记录点滴、成为巨人。
中文都成了乱码。
我在网上找了很多解决方案,但是基本上都没解决我的问题,直到翻了一下午的帖子找到了一个解决我项目乱码的一个解决方案。一般乱码问题基本上都是运行环境或者项目配置的问题(除了新手在编程的时候项目编码不规范)。
以下是解决方案:
1:项目配置问题,在接收请求后相应时乱码问题,说明在构建相应时的字符集有问题,maven项目我这边没遇到过(不一定其他猿类没有遇到过),解决方案:
@Configuration
public class CustomMVCConfiguration extends WebMvcConfigurerAdapter {
@Bean
public HttpMessageConverter<String> responseBodyConverter() {
StringHttpMessageConverter converter = new StringHttpMessageConverter(
Charset.forName("UTF-8"));
return converter;
}
@Override
public void configureMessageConverters(
List<HttpMessageConverter<?>> converters) {
super.configureMessageConverters(converters);
converters.add(responseBodyConverter());
}
@Override
public void configureContentNegotiation(
ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
}
}
2:maven运行环境问题,我的项目就是运行环境上的问题,主要原因是使用了spring boot的maven插件,以spring:run运行的项目,需要在插件中添加运行的编码配置:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
</configuration>
</plugin>
记录点滴、成为巨人。
相关文章推荐
- Springboot 之 解决IDEA读取properties配置文件的中文乱码问题
- SpringBoot JPA MySQL 遇到中文乱码的解决办法
- spring boot新手教程之使用FastJson解析JSON数据以及解决返回中文乱码问题
- 解决SpringBoot整合Activiti5.20.0流程图中文乱码
- Spring Boot 中文乱码解决
- Springboot 之 解决IDEA读取properties配置文件的中文乱码问题
- Springboot 之 解决IDEA读取properties配置文件的中文乱码问题
- Springboot解决IDEA读取properties配置文件的中文乱码
- spring boot jpa mysql 解决中文乱码
- SpringBoot mail中文附件乱码的解决方法
- Springboot使用FastJson后,接口返回中文乱码的问题解决。
- SpringCloud 上传文件,经过Zuul,中文文件名乱码解决办法
- 关于Spring boot中读取属性配置文件出现中文乱码的问题的解决
- Spring Boot 中文乱码解决
- SpringBoot 用fastjson替换到jackjson并解决中文乱码的问题
- 解决Springboot使用FastJson 返回中文乱码的问题
- SpringCloud上传文件,经过Zuul,中文文件名乱码解决办法
- 解决SpringBoot框架下利用jdbcTemplate插入mysql数据库中文乱码问题
- spring boot 解决后台返回 json 到前台中文乱码之后出现返回json数据报错 500
- Springboot 之 解决IDEA读取properties配置文件的中文乱码问题