JPA 엔티티 리스너에 스프링 종속성을 주입해야합니다. 나는 @Configurable과 Spring의 AspectJ 위버를 javaagent로 사용하여 이것을 해결할 수 있다는 것을 알고있다. 그러나 이것은 해킹 해결책처럼 보인다. 내가하려는 일을 성취 할 다른 방법이 있습니까? 당신은JPA 엔티티 리스너에 대한 스프링 종속성 삽입
import org.springframework.context.ApplicationContext;
수입이 솔루션을 시도 할 수 있습니다
@Component
public final class BeanUtil {
private static ApplicationContext context;
private BeanUtil(ApplicationContext context) {
BeanUtil.context = context;
}
public static <T> T getBean(Class<T> clazz) throws BeansException {
Assert.state(context != null, "Spring context in the BeanUtil is not been initialized yet!");
return context.getBean(clazz);
}
}
당신이 정교한 수 있습니까? 그것은 나쁜 상황처럼 들리네 –
[XY 문제] (https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) 때문에 Downvoted – Synch
@NicoVanBelle 나는 User 엔티티가있다. , 저장하기 전에 암호 해쉬를 갖고 싶습니다. 해싱 클래스는 Spring 빈이므로, 엔티티에 주입해야합니다. – Krzaku