Программисты JAVA общаются здесь
Anonymous
Получение java.lang.IllegalStateException: запрос, связанный с потоком, не найден
Сообщение
Anonymous » 19 фев 2026, 07:07
При попытке использовать аннотацию @Async я получаю сообщение об ошибке ниже.
Код: Выделить всё
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
@Override
@Transactional
public void triggerEmailCommunication(List eventCode, Integer authorizationId, Integer claimId,
boolean callMethod) {
Map emailBody = new HashMap();
try {
if (callMethod) {
LOGGER.info("Communication async flow triggerEmailCommunication method starts.");
emailBody = emailBodyObject(authorizationId, claimId, eventCode);
}
private Map emailBodyObject(Integer authorizationId, Integer claimId, List eventCode)
throws CareBusinessServiceException {
LOGGER.info("EmailBodyObject method starts.");
Map emailBody = new HashMap();
EmailClaimDetailsVO emailClaimDetails = new EmailClaimDetailsVO();
ClaimAuthorizationVO claimAuthVO = new ClaimAuthorizationVO();
Claim claim = new Claim();
Authorization authorization = new Authorization();
List rejectReasonList = new ArrayList();
Provider provider = new Provider();
String providerName = null;
String claimIntimationNbr = null;
String authorizationNbr = null;
SimpleDateFormat formatter = new SimpleDateFormat(AmhiConstants.DATE_FORMAT_DD_MM_YYYY);
try {
Integer claimIntimationId = null;
if (null != claimId) {
claim = enableBusinessService.retrieveClaimDetails(claimId);
} catch(Exception e) {
}
}
Слой DAO
Код: Выделить всё
@Override
public Claim retrieveClaimIdRecord(Integer claimId) {
CriteriaBuilder builder = manager.getCriteriaBuilder();
CriteriaQuery criteriaQuery = builder.createQuery(Claim.class);
Root root = criteriaQuery.from(Claim.class);
ArrayList
conditions = new ArrayList();
conditions.add(builder.equal(root.get(Claim_.claimId), claimId));
criteriaQuery.select(root).where(conditions.toArray(new Predicate[] {}));
javax.persistence.Query query = manager.createQuery(criteriaQuery);
List claims = query.getResultList();
if(CollectionUtils.isNotEmpty(claims)){
return claims.get(0);
}
return new Claim();
}
Значение извлекается из БД. Но я получаю вышеуказанное исключение, как уже упоминалось.
Подробнее здесь:
https://stackoverflow.com/questions/521 ... uest-found
1771474040
Anonymous
При попытке использовать аннотацию @Async я получаю сообщение об ошибке ниже. [code]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. [/code] Код: [code]@Async @Override @Transactional public void triggerEmailCommunication(List eventCode, Integer authorizationId, Integer claimId, boolean callMethod) { Map emailBody = new HashMap(); try { if (callMethod) { LOGGER.info("Communication async flow triggerEmailCommunication method starts."); emailBody = emailBodyObject(authorizationId, claimId, eventCode); } private Map emailBodyObject(Integer authorizationId, Integer claimId, List eventCode) throws CareBusinessServiceException { LOGGER.info("EmailBodyObject method starts."); Map emailBody = new HashMap(); EmailClaimDetailsVO emailClaimDetails = new EmailClaimDetailsVO(); ClaimAuthorizationVO claimAuthVO = new ClaimAuthorizationVO(); Claim claim = new Claim(); Authorization authorization = new Authorization(); List rejectReasonList = new ArrayList(); Provider provider = new Provider(); String providerName = null; String claimIntimationNbr = null; String authorizationNbr = null; SimpleDateFormat formatter = new SimpleDateFormat(AmhiConstants.DATE_FORMAT_DD_MM_YYYY); try { Integer claimIntimationId = null; if (null != claimId) { claim = enableBusinessService.retrieveClaimDetails(claimId); } catch(Exception e) { } } [/code] Слой DAO [code]@Override public Claim retrieveClaimIdRecord(Integer claimId) { CriteriaBuilder builder = manager.getCriteriaBuilder(); CriteriaQuery criteriaQuery = builder.createQuery(Claim.class); Root root = criteriaQuery.from(Claim.class); ArrayList conditions = new ArrayList(); conditions.add(builder.equal(root.get(Claim_.claimId), claimId)); criteriaQuery.select(root).where(conditions.toArray(new Predicate[] {})); javax.persistence.Query query = manager.createQuery(criteriaQuery); List claims = query.getResultList(); if(CollectionUtils.isNotEmpty(claims)){ return claims.get(0); } return new Claim(); } [/code] Значение извлекается из БД. Но я получаю вышеуказанное исключение, как уже упоминалось. Подробнее здесь: [url]https://stackoverflow.com/questions/52189445/getting-java-lang-illegalstateexception-no-thread-bound-request-found[/url]