Spring Boot / Spring Cloud solve the Chinese garbled

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/zhanghaishan/article/details/78895005

Garbled description (nonsense):

Chinese have become garbled.


I find a lot of solutions, but basically did not solve my problem, I turned up one afternoon to find a solution to my post project garbled a solution. General operating environment are basically garbage problem or issue project configuration (except when the project coding novice in programming non-standard).


Here are solutions:

1: Project configuration issues, when appropriate, after receiving the request garbled, indicating that construction of the corresponding character set in question, maven projects here I have not met (not necessarily the other apes have not met), the solution:

@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 runtime environment issues, my project is the problem on the operating environment, mainly due to the use of a maven plugin spring boot to spring: the project run to run, you need to add code to run in the plug-in configuration:

<plugin>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-maven-plugin</artifactId>
	<configuration>
		<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
	</configuration>
</plugin>


Record bit, become a giant.

Guess you like

Origin blog.csdn.net/zhanghaishan/article/details/78895005