java - Adding a Pre-constructed Bean to a Spring Application Context -


I am writing a class that applies the following method:

  public zero Run (javax .sql.dataSource dataSource);  

Within this method, I want to create a spring app reference using a configuration file similar to the following:

  & lt; Bean id = "dataSource" abstract = "true" /> & lt; Bean id = "Dao" class = "My.Dao" & gt; & Lt; Property Name = "Data Source" Riff = "Data Sources" / & gt; & Lt; / Bean & gt;  

Is it possible to pass Spring using the datashours object in its own way, wherever "Datasource" bean is referred to in the configuration file?

I have been in the same state as no one proposes my solution (and I think That my solution is more beautiful), I will add it to future generations: -)

The solution consists of two steps:

  1. For parents Apply, and register your existing bean in it.
  2. Load the beans from the child's applicationcontact (pass in the original context) and the XML file

step # 1: / P>

  // Make Parents Beenfrieders Default StableBinFetiline ParentsBinFactor = New Default StableBanFactor (); // Register your pre-made item in your parents. Banner Factory.registerSingleton ("Data Source", Data Source); // wrap BeanFactory within ApplicationContext GenericApplicationContext parentContext = New GenericApplicationContext (parentBeanFactory); ParentContext.refresh ();  

Step # 2:

  // Create your "child" applicationcontact, which includes "Beans. XML" beans / / note that we Preset parent application as parent, contact passport reference reference = new classpath XML application context (new string [] {"beans.xml"}, parent code);  

Comments