Note that there are some explanatory texts on larger screens.

plurals
  1. POuse ClassPathXmlApplicationContext to crateBean programmaticly but cannot get the bean ; Spring
    primarykey
    data
    text
    <pre><code>ClassPathXmlApplicationContext ct = new ClassPathXmlApplicationContext(); ct.refresh(); ConfigurableListableBeanFactory bf = ct.getBeanFactory(); Ad bean = (Ad) bf.createBean(Ad.class); System.out.println("bean ="+bean); System.out.println("size= "+bf.getBeansOfType(Ad.class).size()); // print 0 </code></pre> <p>Ad class ,here is the Ad class information ,AD extends AbstractAd class:</p> <pre><code>public class Ad { @Override public String toString() { return "ad[adid=" + this.getId() + "]"; } </code></pre> <p>}</p> <p>here is the log:</p> <pre><code>[DEBUG] Creating instance of bean 'com.Ad' [DEBUG] Finished creating instance of bean 'com.Ad' bean = ad[adid=null] size= 0 </code></pre> <p>in my opinion ,<strong>size should be 1</strong> ,what is wrong?</p> <p><strong>ps:</strong> finally I use GenericApplicationContext and BeanDefinition and success createBean and get From context ,</p> <pre><code> GenericApplicationContext ct = new GenericApplicationContext(); ct.refresh(); ConfigurableListableBeanFactory bf = ct.getBeanFactory(); System.out.println("--------------start------------/n--------------------------/n-------------------/n"); BeanDefinition definition = new RootBeanDefinition(Ad.class); ct.registerBeanDefinition("sampleService", System.out.println(bf.getBeansOfType(Ad.class).size()); //print 1 </code></pre> <p>log:</p> <pre><code>[DEBUG] Creating instance of bean 'sampleService' [DEBUG] Eagerly caching bean 'sampleService' to allow for resolving potential circular references [DEBUG] Finished creating instance of bean 'sampleService' 1 </code></pre> <p>but I still wonder : <strong>why getBeansOfType(Ad.class).size() is 0</strong> after ClassPathXmlApplicationContext creteBean ?</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.
 

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