Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a big topic. The Spring reference doc devotes multiple chapters to it. I recommend reading the ones on <a href="http://static.springsource.org/spring/docs/2.5.x/reference/aop.html" rel="noreferrer">Aspect-Oriented Programming</a> and <a href="http://static.springsource.org/spring/docs/2.5.x/reference/transaction.html" rel="noreferrer">Transactions</a>, as Spring's declarative transaction support uses AOP at its foundation.</p> <p>But at a very high level, Spring creates proxies for classes that declare <strong>@Transactional</strong> on the class itself or on members. The proxy is mostly invisible at runtime. It provides a way for Spring to inject behaviors before, after, or around method calls into the object being proxied. Transaction management is just one example of the behaviors that can be hooked in. Security checks are another. And you can provide your own, too, for things like logging. So when you annotate a method with <strong>@Transactional</strong>, Spring dynamically creates a proxy that implements the same interface(s) as the class you're annotating. And when clients make calls into your object, the calls are intercepted and the behaviors injected via the proxy mechanism. </p> <p>Transactions in EJB work similarly, by the way.</p> <p>As you observed, through, the proxy mechanism only works when calls come in from some external object. When you make an internal call within the object, you're really making a call through the "<strong>this</strong>" reference, which bypasses the proxy. There are ways of working around that problem, however. I explain one approach in <a href="http://forum.springsource.org/showthread.php?t=11656" rel="noreferrer">this forum post</a> in which I use a <strong>BeanFactoryPostProcessor</strong> to inject an instance of the proxy into "self-referencing" classes at runtime. I save this reference to a member variable called "<strong>me</strong>". Then if I need to make internal calls that require a change in the transaction status of the thread, I direct the call through the proxy (e.g. "<strong>me.someMethod()</strong>".) The forum post explains in more detail. Note that the <strong>BeanFactoryPostProcessor</strong> code would be a little different now, as it was written back in the Spring 1.x timeframe. But hopefully it gives you an idea. I have an updated version that I could probably make available.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload