์Šคํ”„๋ง๋ถ€ํŠธ 1 ์„ ์‚ฌ์šฉํ•˜๋˜ ์—”ํ„ฐํ”„๋ผ์ด์ฆˆ ์•ฑ์„ MSA ์ ์šฉ ์ž‘์—…์„ ํ†ตํ•ด ์—ฌ๋Ÿฌ ์•ฑ์œผ๋กœ ๋ถ„๋ฆฌํ•˜๋ฉด์„œ ์Šคํ”„๋ง๋ถ€ํŠธ 2๋กœ ์—…๊ทธ๋ ˆ์ด๋“œ๋ฅผ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค.

์ด ๊ณผ์ •์—์„œ ๋‹ค๋ฅธ ํšŒ์‚ฌ์™€ API ์—ฐ๋™ํ•˜๊ณ  ์žˆ๋˜ ๋ถ€๋ถ„์—์„œ ์ธ์ฝ”๋”ฉ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.

์†Œ์Šค ์ด์ „์„ ์ง„ํ–‰ํ•˜๋ฉด์„œ ๋นผ๋จน์€ ๋ถ€๋ถ„์ด ์žˆ์–ด์„œ์˜€์ฃ .

์ด์Šˆ๊ฐ€ ๋ฐœ์ƒํ•œ ํšŒ์‚ฌ์ธก์—์„œ ์›์ธ์œผ๋กœ ์–˜๊ธฐํ•œ ๊ฒƒ์€ ์‘๋‹ต ํ—ค๋”์˜ Content-Type์— utf-8 ์ธ์ฝ”๋”ฉ ์„ค์ •์ด ๋น ์ ธ์žˆ๋‹ค๋Š” ๊ฒƒ์ด์—ˆ์Šต๋‹ˆ๋‹ค.

 

๊ทธ๋ž˜์„œ ํ™•์ธํ•ด๋ณด๋‹ˆ ์Šคํ”„๋ง๋ถ€ํŠธ 1 ๊ธฐ๋ฐ˜ ์•ฑ์—์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ์„ค์ •์ด ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

	@Bean
	public HttpMessageConverter<String> responseBodyConverter() {
		return new StringHttpMessageConverter(Charset.forName("UTF-8"));
	}

	@Bean
	public Filter characterEncodingFilter() {
		CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
		characterEncodingFilter.setEncoding("UTF-8");
		characterEncodingFilter.setForceEncoding(true);
		return characterEncodingFilter;
	}

๊ทธ๋ฆฌ๊ณ  ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ ์‘๋‹ตํ—ค๋”์˜ Content-Type์— application/json;charset=utf-8 ์ด๋ผ๊ณ  ๋˜์–ด์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ์‹ ๊ทœ ์•ฑ์—์„œ๋Š” charset ์ •๋ณด๊ฐ€ ๋น ์ ธ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

 

๊ทธ๋ž˜์„œ ์œ„ ์„ค์ •์„ ๊ทธ๋Œ€๋กœ ์Šคํ”„๋ง๋ถ€ํŠธ 2 ๊ธฐ๋ฐ˜์˜ ์‹ ๊ทœ๋กœ ๊ฐœ๋ฐœํ•œ ์•ฑ์ชฝ์— ๋„ฃ์œผ๋ ค ํ–ˆ๋”๋‹ˆ ์•ฑ ๊ธฐ๋™ ์‹œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'characterEncodingFilter', defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/HttpEncodingAutoConfiguration.class], could not be registered. A bean with that name has already been defined in com.yanolja.affiliate.out.api.AffiliateOutApiApplication and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

์ด๋ฏธ ๋™์ผํ•œ ์ด๋ฆ„์˜ ๋นˆ์ด ์กด์žฌํ•˜๋‹ˆ ์˜ค๋ฒ„๋ผ์ด๋“œ ํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค์ •์„ ๋ณ€๊ฒฝํ•˜๋ผ๋Š” ์–˜๊ธฐ์˜€์ฃ .

๊ทผ๋ฐ ์ƒ๊ฐํ•ด๋ณด๋‹ˆ ๊ตณ์ด ์ด๋ ‡๊ฒŒ ํ•ด์•ผํ•˜๋‚˜ ๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ค์–ด ์ข€ ์ฐพ์•„๋ณด๋‹ˆ,

์ž๋ฐ” ์†Œ์Šค์— ์ €๋ ‡๊ฒŒ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š๊ณ  ์Šคํ”„๋ง ์„ค์ • ๋งŒ์œผ๋กœ๋„ ํ—ค๋”์˜ ์ธ์ฝ”๋”ฉ ์„ค์ •์€ ๊ฐ€๋Šฅํ–ˆ์Šต๋‹ˆ๋‹ค.

๋ฐ”๋กœ server.servlet.encoding.charset ์„ค์ •์„ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. 

ํ•˜์œ„ ๋ฒ„์ „์—์„œ๋Š” ์ด ์„ค์ •์ด spring.http.encoding.charset ์œผ๋กœ ์‚ฌ์šฉ๋˜์—ˆ์—ˆ์Šต๋‹ˆ๋‹ค.

 

์ž๋ฐ” ์†Œ์Šค์—์„œ characterEncodingFilter ๋นˆ ์ƒ์„ฑ๋กœ์ง์„ ์ œ๊ฑฐํ•˜๊ณ , application.yml ํŒŒ์ผ์— ์•„๋ž˜์™€ ๊ฐ™์ด ์„ค์ •์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

server:
  servlet:
    encoding:
      charset: UTF-8

 

๊ทธ๋ฆฌ๊ณ  ์•ฑ์„ ์žฌ๋ถ€ํŒ… ํ•ด์ฃผ๋ฉด ์‘๋‹ตํ—ค๋”์˜ Content-Type ๊ฐ’์ด application/json;charset=utf-8 ์œผ๋กœ ๋ณ€๊ฒฝ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋งŒ์•ฝ ๊ฐ’์ด ๋ฐ”๋€Œ์ง€ ์•Š๋Š”๋‹ค๋ฉด server.servlet.encoding.force-response ๋˜๋Š” server.servlet.encoding.force ์„ค์ •๊ฐ’์„ true๋กœ ์„ค์ •ํ•ด์„œ ๋‹ค์‹œ ํ•ด๋ณด์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

 

 

์ฐธ๊ณ ๋ฌธ์„œ: docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#server.servlet.encoding.charset