dudwl7676
110
2021-04-13 17:46:53 작성 2021-04-13 17:47:52 수정됨
0
71

EmptyInterceptor 에러


안녕하세요 DB에 접근할때 오류가 나서 질문드립니다 ㅜㅡㅜ

제 생각으로는 EmptyInterceptor 클래스를 상속받아 구현한  onPrepareStatement 메소드에서 예외가 잡히는 것 같은데 어떻게 해결을 해야될지 모르겠습니다 ㅜㅜ


인터셉터 구현체 입니다

@Component
public class EventInterceptor extends EmptyInterceptor implements HibernatePropertiesCustomizer {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    private static final long serialVersionUID = 1L;

    @Override
    public String onPrepareStatement(String sql) {

        RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
        String id = (String) attributes.getAttribute(Event.SESSION_NAME, RequestAttributes.SCOPE_SESSION);

        logger.warn("onPrepareStatement:" + id);

        if (id != null) {
            return sql.replaceAll("event_n", Event.TABLE_PREFIX + id + "_n");
        }
        return sql;
    }

    @Override
    public void customize(Map<String, Object> hibernateProperties) {
        logger.warn("customize Called");
        hibernateProperties.put("hibernate.session_factory.interceptor", this);
    }


그리고 해당 클래스에서 @PostConstruct 메소드 실행시 오류가 뜹니다

goodsVersionService와 goodsService에서는 Repository에 접근하여 데이터를 가져오는 로직입니다.

    @PostConstruct
    @Scheduled(cron = "0 0 3 * * ?", zone = "Asia/Seoul")
    public void getGoodsList() {
        version = goodsVersionService.getCurrentVersion();
        validGoodsList = goodsService.getValidGoods();
        allGoods = goodsService.getAllGoods();
    }


오류내용입니다

2021-04-13 08:38:00.010 ERROR 8 --- [   scheduling-1] o.s.s.s.TaskUtils$LoggingErrorHandler    : Unexpected error occurred in scheduled task

org.springframework.dao.InvalidDataAccessApiUsageException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.


0
  • 답변 0

  • 로그인을 하시면 답변을 등록할 수 있습니다.