ProxyFactoryBean returns a null object for the Target class

I ran into a problem in class ProxyFactoryBean,

We want to get the class name targetBean ProxyFactoryBean.

When we call getTypeon BeanFactory, giving the name bean, it always returns as null.

Our Java Code

public class TestSpring {
   public static void main(String args[]){    
     TestSpring ts = new TestSpring();
     ts.process();
   }

   private void process() {
     BeanFactory factory = new XmlBeanFactory(new FileSystemResource("E:\\beans.xml"));
     Class c = factory.getType("scor.imagedev.action.imageDevServerTaskActions");
     System.out.println(c);
   }
}

Our configuration file is as follows:

<bean id="scor.actionProxyTemplate" class="org.springframework.aop.framework.ProxyFactoryBean"  abstract="true" >
   <property name="proxyTargetClass" value="true" />    
</bean>

 <bean id="scor.imagedev.action.imageDevServerTaskActions" parent="scor.actionProxyTemplate" scope="prototype">    
   <property name="target"> 
     <bean class="test.spring.Foo"/>
   </property>
 </bean>

Some of the other things I want to add here.

  • If we create a bean as a singleton, it works. But in our case, we want it to be a prototype.
  • We must use BeanFactory.getType(<beanName>). This is our basic infrastructure. We cannot change our basic structure.
  • Can targetSourcesolve the problem? I tried, but it is useless. Perhaps I used it incorrectly.
  • I am using Spring 2.0.6.

Relationship Ankit

+3
2

, null, . , , , - . (bean , )

, null. , bean. , spring 2.5.6 ( 3.0.x) , .

0

, , , getTypeForFactoryBean AbstractBeanFactory . NULL protoType bean.

/**
     * Determine the bean type for the given FactoryBean definition, as far as possible.
     * Only called if there is no singleton instance registered for the target bean already.
     * <p>The default implementation creates the FactoryBean via <code>getBean</code>
     * to call its <code>getObjectType</code> method. Subclasses are encouraged to optimize
/
protected Class getTypeForFactoryBean(String beanName, RootBeanDefinition mbd) {
            if (!mbd.isSingleton()) {
                return null;
            }
            try {
                FactoryBean factoryBean = (FactoryBean) getBean(FACTORY_BEAN_PREFIX + beanName);
                return getTypeForFactoryBean(factoryBean);
            }
            catch (BeanCreationException ex) {
                // Can only happen when getting a FactoryBean.
                logger.debug("Ignoring bean creation exception on FactoryBean type check", ex);
                return null;
            }
        }

getObjectType ProxyFactoryInstance, - Singleton NULL.

0

Source: https://habr.com/ru/post/1767655/


All Articles