HyeLog
JavaMailSender 빈(Bean) 등록 에러 본문
🚨에러 코드
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.example.demo.utils.MailService required a bean of type 'org.springframework.mail.javamail.JavaMailSender' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.mail.javamail.JavaMailSender' in your configuration.
👩💻공부한 내용
📍final 멤버 변수란?
클래스의 멤버 변수 앞에 final 키워드를 붙이면(Ex. private final nickname), 해당 변수에 값 할당을 딱 1번만 할 수 있다. final 멤버 변수에 값을 할당하는 방법은, 필드 선언시 하는 것과, 생성자를 통해서 할당하는 것 2가지가 있다. 만약 멤버 변수를 final로 선언하고, 선언부나 생성자에서 초기화하지 않으면, 컴파일 에러가 발생한다.
이렇게 값이 할당된 멤버 변수의 값은 다시 다른 값으로 변경할 수 없다. 객체가 생성되고 난 이후에는, 상수처럼 작용해야하는 멤버 변수 앞에 final 키워드를 붙여주게 된다.
(참고: https://hbase.tistory.com/151 )
📍의존성 주입이란?
어떤 클래스 A가 다른 클래스 객체 B를 사용할 때 A는 B에 의존성이 있다고 한다.
Spring Boot에는 몇가지 의존성 주입 방법이 있다. 좋은 글들이 많으니 참고하자.
(참고: https://mangkyu.tistory.com/125, https://jgrammer.tistory.com/entry/springboot-%EC%9D%98%EC%A1%B4%EC%84%B1-%EC%A3%BC%EC%9E%85-%EB%B0%A9%EC%8B%9D-%EA%B2%B0%EC%A0%95 )
🌈 에러 해결 방법 🌈
내가 JavaMailSender를 @Bean으로 등록하지 않아서 생기는 에러였다. MailConfig 클래스를 새로 만들어서 빈 등록을 해주니 해결되었다.
(참고: https://tecoble.techcourse.co.kr/post/2020-09-29-spring-properties-binding/
https://velog.io/@coffiter/SpringBoot-%EB%A9%94%EC%9D%BC-%EB%B0%9C%EC%86%A1JavaMailSender )
'웹 개발 > 에러 해결' 카테고리의 다른 글
[JPA, MySQL] Repository.save() 안되는 이유, 다른 테이블의 FK 인 컬럼 변경 에러 해결 방법 (Feat. AUTO_INCREMENT) (1) | 2023.07.08 |
---|