java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to org.andrea.myexample.myDeclarativeTransactionSpring.StudentJDBCTemplate

后端 未结 4 1554
[愿得一人]
[愿得一人] 2021-02-10 01:49

I am trying to implement this tutorial about Declarative Transaction in Spring Framework application but don\'t work because when I try to execute the MainApp c

4条回答
  •  花落未央
    2021-02-10 02:37

    Option 1, change your configuration to inject transactions at the interface level:

    
        
        
    
    

    and obtain the bean as an instance of that interface:

    StudentDAO studentDao = (StudentDAO) context.getBean("studentJDBCTemplate");
    

    Option 2, indicate that the proxy should extend the target class using proxy-target-class attribute:

    
        ...
    
    

    The first option is the cleaner one, but frankly I'd prefer to use@Transactional annotations rather than AOP declarations within the Spring bean XML. It's sometimes diffucult to get the latter correct and if you don't have specific transactionality tests on your components, you will not necessarily notice that things are incorrect.

提交回复
热议问题