Making Spring 3 MVC controller method Transactional

前端 未结 2 1463
情深已故
情深已故 2020-12-19 12:28

I am using Spring 3.1 and have my DAO and service layer(transactional) written.

However in a special case to avoid a lazy init exception I have to make a spring mvc

相关标签:
2条回答
  • 2020-12-19 13:03

    You'll need to implement an interface so that Spring has something it can use as a Proxy interface:

    @Controller
    public interface AuthenticationController {
      ModelAndView home(HttpServletRequest request, HttpServletResponse response);
    }
    
    @Controller
    public class AuthenticationControllerImpl implements AuthenticationController {
    
    @RequestMapping(value="/home.html",method=RequestMethod.GET)
    @Transactional
    @Override
    ModelAndView home(HttpServletRequest request, HttpServletResponse response){
    .....
    }
    }
    
    0 讨论(0)
  • 2020-12-19 13:07

    Spring will implement the transactional logic using JDK dynamic proxies, these rely on proxied classes implementing suitable interfaces. It's also possible to use CGLib proxies which don't require interfaces.

    There is a nice article about this link

    0 讨论(0)
提交回复
热议问题