개발자 도전기
[Spring] @Value 어노테이션으로 주입한 값이 null일 때 본문
🚨 ERROR
Caused by: java.lang.NullPointerException: Parameter specified as non-null is null
@Value 어노테이션으로 주입한 값이 null인 오류가 발생했다.
💣 CAUSE
public SmsUtil() {
this.messageService = NurigoApp.INSTANCE.initialize(apiKey, apiSecret, "https://api.coolsms.co.kr");
}
생성자를 통해 field에 값을 주입해주었는데 의존성 주입 전에 생성자가 호출되는 문제 때문에 null 값이 들어가게 되었다
💡 SOLVE
@PostConstruct를 사용하였습니다
@PostConstruct를 사용하면 의존성 주입이 이루어진 후 초기화가 수행되게 됩니다
@PostConstruct
public void init() {
this.messageService = NurigoApp.INSTANCE.initialize(apiKey, apiSecret, "https://api.coolsms.co.kr");
}
'개발공부 > Spring' 카테고리의 다른 글
[Spring] Negative matches: Did not match: (0) | 2024.06.12 |
---|---|
[Spring] a bean of type 'org.apache.catalina.filters.CorsFilter' that could not be found. (0) | 2024.06.11 |
[Spring] 컨트롤러로 요청 시 302 Found 응답 뜰 때 (0) | 2024.06.04 |
[Spring] Encoded password does not look like BCrypt (0) | 2024.05.24 |
[Spring] Ajax로 이메일 중복 확인하기 (0) | 2024.05.02 |