[SPRING] @Async 및 @Transactional : 작동하지 않음
SPRING@Async 및 @Transactional : 작동하지 않음
코드를 참조하십시오.
@Async와 @Transactional에서 같은 결과를 얻길 기대했지만 그렇지 않습니다. 설명 해주시거나 내가 뭘 잘못 했니?
편집 : 방금 코드 + 로그를 게시하도록 편집했습니다.
흐름 방향 : AppDataLoaderController는 AppDataLoaderService를 호출합니다. DataMigrationService는 JpaDataMigrationDao를 호출합니다.
package concepts.web.rest.resource.spring.impl;
@Controller
@RequestMapping("/appdataloader")
public class AppDataLoaderController {
@RequestMapping("/loadMarkupPct")
@ResponseStatus(HttpStatus.ACCEPTED)
public void loadMarkUpPCT() {
try {
this.appDataLoaderService.loadMarkUpPCT();
} catch (ServiceException e) {
e.printStackTrace();
}
}
package concepts.service.impl;
@Service("appDataLoaderService")
public class AppDataLoaderServiceImpl implements AppDataLoaderService {
@Async
@Override
public void loadMarkUpPCT() throws ServiceException {
logger.debug("@Async loadMarkUpPCT");
dataMigrationService.loadMarkUpPCT();
}
package concepts.service.impl;
@Service
@Scope("prototype")
public class DataMigrationServiceImpl implements DataMigrationService {
@Override
public void loadMarkUpPCT() throws ServiceException {
// TODO Auto-generated method stub
Assert.notNull(markUpPCTDataLoader);
List<MarkUpPCT> markUpPCTs=markUpPCTDataLoader.getMarkupCoef();
for (MarkUpPCT markUpPCT: markUpPCTs)
dataMigrationDao.storeMarkUpPCT(markUpPCT);
}
package concepts.persistence.impl.jpa;
@Repository
public class JpaDataMigrationDao extends DataMigrationDaoAdapter{
@PersistenceContext
private EntityManager entityManager;
@Transactional
@Override
public void storeMarkUpPCT(MarkUpPCT markUpPCT) {
entityManager.persist(markUpPCT);
}
일부 로그
14 Nov 2013 18:47:05,531 36813 [http-bio-18080-exec-3] DEBUG OpenEntityManagerInViewFilter - Opening JPA EntityManager in OpenEntityManagerInViewFilter
14 Nov 2013 18:47:05,578 36860 [http-bio-18080-exec-3] DEBUG DispatcherServlet - DispatcherServlet with name 'mvc' processing POST request for [/POCQI/appdataloader/loadMarkupPct]
[http-bio-18080-exec-3] DEBUG RequestMappingHandlerMapping - Looking up handler method for path /appdataloader/loadMarkupPct
[http-bio-18080-exec-3] DEBUG RequestMappingHandlerMapping - Returning handler method [public void concepts.web.rest.resource.spring.impl.AppDataLoaderController.loadMarkUpPCT()]
[SimpleAsyncTaskExecutor-1] DEBUG DataMigrationServiceImpl - @Async loadMarkUpPCT
[http-bio-18080-exec-3] DEBUG DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'mvc': assuming HandlerAdapter completed request handling
[SimpleAsyncTaskExecutor-1] DEBUG MarkUpPCTDataLoader - {80=1.6, 90=1.8, 100=2.0, 105=2.05, 110=2.1, 115=2.15, 117=2.17, 120=2.2, 125=2.25, 150=2.5}
[http-bio-18080-exec-3] DEBUG DispatcherServlet - Successfully completed request
[http-bio-18080-exec-3] DEBUG OpenEntityManagerInViewFilter - Closing JPA EntityManager in OpenEntityManagerInViewFilter
[http-bio-18080-exec-3] DEBUG EntityManagerFactoryUtils - Closing JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Opening JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Registering transaction synchronization for JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Closing JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Opening JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Registering transaction synchronization for JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Closing JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Opening JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Registering transaction synchronization for JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Closing JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Opening JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Registering transaction synchronization for JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Closing JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Opening JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Registering transaction synchronization for JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Closing JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Opening JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Registering transaction synchronization for JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Closing JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Opening JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Registering transaction synchronization for JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Closing JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Opening JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Registering transaction synchronization for JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Closing JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Opening JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Registering transaction synchronization for JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Closing JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Opening JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Registering transaction synchronization for JPA EntityManager
[SimpleAsyncTaskExecutor-1] DEBUG EntityManagerFactoryUtils - Closing JPA EntityManager
해결법
-
==============================
1.@Transactional을 사용하여 loadMarkUpPCT () 메소드에 주석을 달고 그 결과가 작동하는지 알려주십시오.
@Transactional을 사용하여 loadMarkUpPCT () 메소드에 주석을 달고 그 결과가 작동하는지 알려주십시오.
-
==============================
2.나는 단지 같은 문제에 부딪쳤다. @EnableAsync 주석을 추가하는 것을 잊어 버렸습니다.
나는 단지 같은 문제에 부딪쳤다. @EnableAsync 주석을 추가하는 것을 잊어 버렸습니다.
from https://stackoverflow.com/questions/19935809/async-and-transactional-not-working by cc-by-sa and MIT license
'SPRING' 카테고리의 다른 글
[SPRING] 테스트 목적으로 스프링 부트에서 db connection을 모의 (mock) 할 수 있습니까? (0) | 2019.03.20 |
---|---|
[SPRING] OAuth2 및 JWT를 사용한 스프링 보안 : 암호화 된 암호가 BCrypt처럼 보이지 않습니다. (0) | 2019.03.20 |
[SPRING] Spring Data REST - 관계가있는 새로운 엔티티 POST (0) | 2019.03.20 |
[SPRING] 부두 시동 지연 (0) | 2019.03.20 |
[SPRING] java.lang.IllegalStateException : LifecycleProcessor가 초기화되지 않았습니다. 컨텍스트를 통해 라이프 사이클 메소드를 호출하기 전에 'refresh'를 호출하십시오. (0) | 2019.03.20 |