Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is somewhat possible, but in a cumbersome way: You must use the <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/beans/factory/config/AutowireCapableBeanFactory.html" rel="nofollow"><code>AutowireCapableBeanFactory</code></a> mechanism.</p> <p>Here is a transactional class as example</p> <pre><code>public interface FooBar{ void fooIze(Object foo); } public class FooBarImpl implements FooBar{ @Transactional @Override public void fooIze(final Object foo){ // do stuff here } } </code></pre> <p>And here is how we can use it:</p> <pre><code>public class FooService implements ApplicationContextAware{ private ApplicationContext applicationContext; @Override public void setApplicationContext( final ApplicationContext applicationContext){ this.applicationContext = applicationContext; } public void serviceMethod(){ //declare variable as interface, initialize to implementation FooBar fooBar = new FooBarImpl(); // try to use it, won't work, as it's not a proxy yet Object target = new Object[0]; fooBar.fooIze(target); // no transaction // now let spring create the proxy and re-assign the variable // to the proxy: fooBar = // this is no longer an instance of FooBarImpl!!! (FooBar) applicationContext .getAutowireCapableBeanFactory() .applyBeanPostProcessorsAfterInitialization(fooBar, "someBeanName"); fooBar.fooIze(fooBar); // this time it should work } } </code></pre> <p>This is not a best practice. For one thing, it makes your application highly aware of the Spring Framework and also, it violates the dependency injection principles. So use this only if there is no other way!</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. This table or related slice is empty.
    1. This table or related slice is empty.
    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