Constructor Binding

leverest96·2023년 4월 7일
0

Trouble Shooting

목록 보기
16/20
post-thumbnail

문제 인지

spring security를 구현하기 위해 기존 프로젝트를 참고하던 중 property에서 @ConstructorBinding에 빨간줄이 생겼다. 마우스를 올려보니 '@ConstructorBinding' not applicable to type이라는 오류 메세지가 있었다.

해결 방법

spring boot 3.0 이상 버전부터는 클래스의 생성자가 여러 개일 경우를 제외하면 더이상 @ConstructorBinding 어노테이션을 사용할 필요가 없다고 한다.

@ConstructingBinding No Longer Needed at the Type Level

@ConstructorBinding is no longer needed at the type level on @ConfigurationProperties classes and should be removed. When a class or record has multiple constructors, it may still be used on a constructor to indicate which one should be used for property binding.

Improved @ConstructorBinding Detection

When using constructor bound @ConfigurationProperties the @ConstructorBinding annotation is no longer required if the class has a single parameterized constructor. If you have more than one constructor, you’ll still need to use @ConstructorBinding to tell Spring Boot which one to use.

For most users, this updated logic will allow for simpler @ConfigurationProperties classes. If, however, you have a @ConfigurationProperties and you want to inject beans into the constructor rather than binding it, you’ll now need to add an @Autowired annotation.

https://www.zodaland.com/tip/64

profile
응애 난 애기 개발자

0개의 댓글