inflearn logo
강의

講義

知識共有

[改訂版2023-11-27] Spring Boot 3.xを利用したRESTful Web Servicesの開発

internalization 구현 시 @RequestHeader의 required 옵션을 false로 설정해도 무조건 400 에러가 발생합니다.

1141

DAEHO LEE

投稿した質問数 4

0

@GetMapping(path = "/hello-world-internationalized")

public String helloWorldInternationalized(@RequestHeader(name = "Accept-Language", required = false) Locale locale) {

System.out.println(locale.getLanguage());

return messageSource.getMessage("greeting.message", null, locale);

}

위처럼 HelloWorldController에 helloWorldInternationalized()를 구현했으나

포스트맨으로 [GET]http://localhost:8080/hello-world-internationalized

을 호출 시 header로 "Accept-Language"를 날리지 않으면 무조건 400 에러가 발생합니다.

"Accept-Language"값을 "en"이나 "fr"로 설정시에는 정상적으로 메세지를 반환합니다.

required를 false로 설정한 후 추가로 해야 할 작업이 있는지 문의드립니다.

spring-boot rest-api

回答 2

0

DAEHO LEE

답변 감사드립니다. 알려주신대로 해보니 curl 명령어 캡쳐화면과 동일하게 잘 되고 있습니다.

다만, 강좌에서 required = false로 설정하여 header로 "Accept-Language"를 날리지 않아도 기본값으로 처리되어 한국어로 나오게 되어야 하는데 계속 400 Bad Request가 뜨네요.

header로 "Accept-Language"를 설정시에는 잘 되고 있습니다.

0

Dowon Lee

안녕하세요, 이도원입니다. 

RequestHeader 관련해서 추가로 설정하실 것은 없을 것 같습니다. 올려주신 메소드를 제 프로젝트에 복사해서 실행시, System.out.println 메소드에서 locale.getLanguage()를 사용하고 있어,

1. Request Header가 없으면, 500 Internal Server Error 

2. Request Header가 존재하면, 정상 처리 됩니다. 

POSTMAN의 cache를 초기해 보시고 실행하시거나, 터미널에서 curl 명령어로 다시 한번 테스트 해 보시기 바랍니다.

감사합니다.

JPA

0

57

1

jpa dependency를 추가하고 SecurityConfig클래스에서 오류가 납니다.

0

68

1

웹 브라우저 400 bad request

0

70

1

@Size는 되는데 @Past는 안 됩니다.

0

61

1

pdf 자료는 없나요?

0

73

2

locale 정보가 null 이면 무조건 messages_ko.properties이 호출 되는 문제

0

87

2

Swagger 강의, Unable to infer base url 이거 뜨시는 분들 도움되시라고

0

118

1

강의에서나온 화면 피피티

0

158

1

HelloWorldBean 관련 에러

0

182

2

Swagger API 3.x 오류..

0

218

1

java: variable message not initialized in the default constructor 에러는 어찌하면 좋을까요?

1

282

1

현재 GIT에 올리신 소스를 실행해봤습니다.

0

189

2

고양이 소리가 귀엽네요 !!

0

137

2

git에서 소스받고 실습중인데

0

117

1

post가 안되요

0

102

1

한국어 같은 경우 언어코드인 messages_ko.properties 로 생성하는게 더 좋지 않나요?

0

167

2

리턴타입으로서 EntityModel<User> 와 ResponseEntity질문

0

103

1

예외처리쪽 관련 질문있습니다.

0

159

2

엔티티가 바로 응답으로 나가도 되나요??

0

220

2

안녕하세여 Cannot invoke "co.kr.joneconsulting.resfulservice.repository.PostRepository.save(Object)" because "this.postRepository" is null

0

135

2

사용자 등록하고 나서 H2 에서 보면 신규 사용자의 password, ssn 이 null 로 되어 있습니다.

0

140

2

ApplictionContext 질문

0

190

2

롬북이 안먹히는것같아요

0

156

1

인텔리제이에서스프링부트 파일 실행하면

0

239

1