[英]Transactional rollback not working when called from Controller class but works when called from Test Class
First of all, I've been looking for an answer to this but I still can't find an answer even after 5 hours of of searching. 首先,我一直在寻找答案,但是即使经过5个小时的搜索,我仍然找不到答案。
Summary: My Transactional class does not rollback when it is called from my Controller class but when it is called in my JUnit test class, it executes the rollback. 简介:从我的Controller类调用它时,我的Transactional类不会回滚, 但是在我的JUnit测试类中调用它时,它将执行回滚。
Controller 控制者
@RestController
public class NotifyServerController extends BaseController {
...
@RequestMapping(value = PathConstants.PATH_NOTIFY_SERVER, method = RequestMethod.POST)
public WiremoRoot notifyServer(// parameters //) throws SQLException {
... authentication and other if statements
// State monitoring request (control box information)
else if(content instanceof SpecificRequest){
response.getContents().setContent(serviceObj.processRequest(request));
} else
throw new InputErrorException();
return response;
}
}
ServiceObjectImplementation ServiceObjectImplementation
@Service(// Qualifier //)
@Transactional
public class ServiceClassImplementation implements ServiceClass {
// -- Dao objects here
/**
* {@inheritDoc}
*/
public Response processRequest(// parameters //) throws SQLException {
...
methodA();
}
public void methodA(){
...
throw new RuntimeException();
}
...
}
Please note that it successfully rolls back when it is called in my Test class. 请注意,在我的Test类中调用它时,它会成功回滚。 It just doesn't work when called from RestController. 从RestController调用时,它只是不起作用。
Apparently, my tx-annotation statement was inside my db-context.xml that's why it was not working in the actual build but was working in my test class because in my test class, I load specifically the my configurations. 显然,我的tx-annotation语句位于db-context.xml中,这就是为什么它在实际构建中不起作用,但在我的测试类中起作用的原因,因为在我的测试类中,我专门加载了我的配置。 So I put my tx-annotation statement in my dispatcherServlet(servlet-context.xml) and it worked. 因此,我将tx-annotation语句放入了dispatcherServlet(servlet-context.xml)中,它开始工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.