fix: make sure string responses use utf8

This commit is contained in:
MiniDigger | Martin 2024-11-03 11:00:15 +01:00
parent f04a253f58
commit 8094d80243
2 changed files with 11 additions and 0 deletions

View File

@ -47,6 +47,7 @@ import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor;
import org.springframework.web.client.RestClient;
@ -153,6 +154,13 @@ public class WebConfig extends WebMvcConfigurationSupport {
@Override
public void afterPropertiesSet() {
super.afterPropertiesSet();
for (final HttpMessageConverter<?> messageConverter : this.getMessageConverters()) {
if (messageConverter instanceof StringHttpMessageConverter stringConverter) {
stringConverter.setDefaultCharset(StandardCharsets.UTF_8);
}
}
final List<HandlerMethodArgumentResolver> existingResolvers = new ArrayList<>(Objects.requireNonNull(this.getArgumentResolvers()));
existingResolvers.addAll(0, WebConfig.this.resolvers);
this.setArgumentResolvers(existingResolvers);

View File

@ -3,6 +3,9 @@
###########
server:
port: 8080
servlet:
encoding:
charset: "UTF-8"
spring:
application: