Мне нужно реализовать @EntityListener
@Entity
@Table(name = "profile")
@Data
@EntityListeners(ProfileListener.class)
public class Profile implements Serializable {
...
}
и ProfileListener.class. Я хочу получить доступ к HttpServletRequest для получения некоторых данных для использования внутри @ PostPersist
@PostPersist
public void PostPersist(Object ob) throws IOException {
}
Редактировать Я пытался использовать
1.) RequestContextHolder
@PostPersist
public void PostPersist(Object ob) throws IOException {
HttpServletRequest httpServletRequest = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
}
, и я получил ошибку java.lang.NullPointerException
2.) ApplicationContext
@PostPersist
public void PostPersist(Object ob) throws IOException {
HttpServletRequest httpServletRequest = ApplicationContextProvider.getApplicationContext().getBean(HttpServletRequest .class);
}
и я получил ошибку java.lang.NullPointerException
3.) @Autowired private HttpServletRequest request;
AFAIK ProfileListener.class является классом вне контекста приложения Spring, поэтому яне могу использовать Autowired