首先,我一直在寻找答案,但我仍然找不到答案,即使经过5个小时的搜索。
摘要:当从我的Controller类调用事务类时,它不会回滚,而是在我的JUnit测试类中调用它时执行回滚。
控制器
@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
@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();
}
...
}请注意,当在我的Test类中调用它时,它会成功回滚。它只是在从RestController调用时不起作用。
发布于 2017-12-11 07:36:50
显然,我的tx注释语句在我的db-context.xml中,这就是为什么它不能在实际构建中工作,而是在我的测试类中工作,因为在我的测试类中,我专门加载了我的配置。因此,我将我的tx-注释语句放在我的dispatcherServlet(servlet-context.xml)中,它起了作用。
https://stackoverflow.com/questions/47747207
复制相似问题