개인 필드가있는 엔티티가 있습니다 countryCode
. 국가 코드를 설정하기 위해 엔터티 클래스에 편리한 메서드를 추가하고 싶습니다. CountryCode 개체 또는 문자열을 사용하여 국가 코드를 설정할 수 있습니다.
국가 코드가 문자열로 설정된 경우 CountryCode 저장소가 필요합니다. 그러나 Spring이 저장소 필드를 초기화하도록 할 수 없습니다. 심지어 나는 넣을 경우 @Component
와 @Scope("prototype")
내 법인에 ...
내가 무엇을 놓치고 있습니까?
private CountryCode countryCode;
public void setCountryCode(String code) {
this.countryCode = getByCode(code);
}
@Autowired
@Transient
private CountryCodeRepository countryCodeRepository;
private CountryCode getByCode(String code) {
if (code == null) {
throw new NullPointerException("The country code cannot be null.");
}
// countryCodeRepository is NULL below...
CountryCode finalCC = countryCodeRepository.findByAlpha2OrAlpha3(code);
// ...
}
귀하의 엔티티 클래스는 일부 ORM 프레임 워크에 의해 인스턴스화되므로 봄에 의해 인스턴스화되지 않습니다. 따라서 봄은 필드를 자동으로 자동 배선 할 수 없습니다.
그렇다면 이러한 옵션이 있습니다.
더 많은 정보를 제공해주세요.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다