У меня есть метод, который вызывает только процедуру в MySQL.Это мой код:
import javax.persistence.EntityManager;
import javax.persistence.ParameterMode;
import javax.persistence.PersistenceContext;
import javax.persistence.StoredProcedureQuery;
import javax.transaction.Transactional;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
@Service
public class ClientService {
@PersistenceContext
protected EntityManager entityManager;
@Async
public void callFunction(Integer clientId) {
StoredProcedureQuery query = entityManager.createStoredProcedureQuery("myProcedureSql");
query.registerStoredProcedureParameter("clientId", Integer.class, ParameterMode.IN);
query.setParameter("clientId", clientId);
query.execute();
}
}
Мне нужно, чтобы он работал асинхронно, но когда я добавляю тег @Async в метод, он не может выдать следующую ошибку:
196536 [SimpleAsyncTaskExecutor-2] ERROR org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler - Unexpected error occurred invoking async method 'public void ar.com.lemondata.turnero.backend.service.PruebaService.procesarCSV()'.
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/DispatcherPortlet: 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/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
ЕслиЯ удаляю @Async, код работает отлично