Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you can use autowiring support provided by spring, in order to inject dependencies (and possibly apply post processors) to an object that is not part of the application context.</p> <p>In your case, this object is your standalone application.</p> <p>Here is the way to achieve this. In this example, I use @Autowired (for b1), traditional DI (for b2) and initialization hook for b3. The autowiring support with annotations assumes you have defined the appropriate spring post-processor in your application context (e.g. by declaring <code>&lt;context:annotation-config/&gt;</code>).</p> <pre><code>public class StandaloneApp implements InitializingBean { @Autowired private Bean1 b1; private Bean2 b2; private Bean3 b3; public void afterPropertiesSet() throws Exception { this.b3 = new Bean3(b1, b2); } public void setB2(Bean2 b2) { this.b2 = b2; } public static void main(String... args) { String[] locations = // your files relative to the classpath ApplicationContext ac = new ClasspathXmlApplicationContext(locations); // or use FileSystemXmlApplicationContext if the files are not in the classpath StandaloneApp app = new StandaloneApp(); AutowireCapableBeanFactory acbf = ac.getAutowireCapableBeanFactory(); acbf.autowireBeanProperties(app, AUTOWIRE_BY_NAME, false); acbf.initializeBean(app, "standaloneApp"); // any name will work } } </code></pre> <p>In this example, all b1, b2 and b3 should be non-null (assuming b1 and b2 beans exist in your application context).</p> <p>I haven't tested it (might not even compile due to some typo), but the idea is in the last 3 lines. See the javadocs for <code>AutowireCapableBeanFactory</code> and mentionned methods to see exactly what happens.</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. 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.
    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