First of all, itβs very difficult to give a name ending in the controller, DAO, it is very confusing, Controller and DAO have different goals.
When you add @Transactional to a service or dao class, for spring, to make it work in a transaction, you need to create a proxy of this class, this is a kind of shell where, before executing the proxy class (the class that is proxied), the spring method starts the transaction and after execution, if no exceptions complete the transaction, this can be done in spring through AOP and Annotations. Describe in code.
public class OriginalDaoImpl implements OriginalDao extends DaoSupport { public void save(Object o){ manager.save(o); } } public class ProxyDaoImpl implements OriginalDao { private OriginalDao originalDaoImpl;
As you can see, this is not an exact implementation, but the basis code of how the transaction magically works for you. The key point is the OriginalDao interface, which makes this injection easy, as OriginalDaoImpl and ProxyDaoImpl implement the same interface. Therefore, they can be interchanged, i.e. A proxy server that has the original. This dynamic proxy can be created in Java through the Java dynamic proxy. Now the question is that if your class does not implement an interface, it becomes harder for it to replace. One of the CGLIB libraries, as far as I know, helps in this scenario, due to which it generates a dynamic subclass for the class in question, and the overriden method does the magic as described above, calling super.save(o) delegate the source code.
Now to the problem of injection.
- Create an interface and make your dao implemented, and spring will use the JDK proxy by default, as it behaves now.
- Add
proxy-target-class="true" attribute <tx:annotation-driven transaction-manager="transactionManager"/>
Regarding the exception, it throws, since it is expected that the entered bean will be of type "HibernateController", but it is not.
For reference, you can link to the links below.
Hope this helps !!!!!.
baba.kabira
source share