Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8190297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:34:33+00:00 2026-06-07T03:34:33+00:00

I am trying to write a Spring BeanFactoryPostProcessor that can find any bean which

  • 0

I am trying to write a Spring BeanFactoryPostProcessor that can find any bean which defines an init-method. I am having luck finding beans that have names, but not nested nameless beans as in the target bean in following example:

<bean id="aclDao" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="target">
        <bean class="com.vidsys.dao.impl.acl.ACLDaoImpl" init-method="init">
            <property name="sessionFactory"><ref local="sessionFactory"/></property>
        </bean>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
  </property>
</bean>

When I list the beans in my BeanFactoryPostProcessor I only seem to get the ones with names as in the following code:

public class BeanInitializationFinder implements BeanFactoryPostProcessor, Ordered {
  @Override
  public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
    throws BeansException {

      //String[] beanDefs = BeanFactoryUtils.beanNamesIncludingAncestors(beanFactory);
      String[] beanDefs = beanFactory.getBeanDefinitionNames();
      for(String defName : beanDefs) {
          BeanDefinition def = beanFactory.getBeanDefinition(defName);
          if(null == def.getBeanClassName() || !(def instanceof AbstractBeanDefinition)) 
              return;
          }
          AbstractBeanDefinition abd = (AbstractBeanDefinition) def;
          try {
              if(abd.getFactoryMethodName() == null && abd.getFactoryBeanName() == null) 
                  Class<?> beanClass = Class.forName(abd.getBeanClassName()); 
                  if(InitializingBean.class.isAssignableFrom(beanClass) || null != abd.getInitMethodName()) {
                        beansWithInits.add(defName);
                  }
              }
          }
          catch(Exception e) {
              throw new BeanIntrospectionException("Failed to instrospect bean defs", e);
          }
      }
  }

}

I would like to get all the bean that have an init-method, including nested beans that are nameless. Can I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:34:36+00:00Added an answer on June 7, 2026 at 3:34 am

    You can retrieve nested BeanDefinitions, but not via beanFactory.getBeanDefinition. The only way to get to nested bean definitions is through the PropertyValues of the parent BeanDefinition – you need to walk the graph.

    By way of example (and missing any null-checking):

    BeanDefinition parentDef = beanFactory.getBeanDefinition(defName);
    for (PropertyValue property : parentDef.getPropertyValues().getPropertyValues()) {
        Object value = property.getValue();
        if (value instanceof BeanDefinitionHolder) {
            BeanDefinition nestedDef = ((BeanDefinitionHolder)value).getBeanDefinition();
        }
    }
    

    Given that graph traversal works well with the Visitor pattern, you can subclass org.springframework.beans.factory.config.BeanDefinitionVisitor to do this in a more concise fashion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a Spring web application on a Weblogic server that makes
I was trying to write an interceptor using spring AOP.The interceptor will find if
I'm trying to write a string to a file that a user can download
I am trying to write a portlet for Liferay (using Tomcat and Spring) and
I'm trying to write an equivalent of Rails data model evolution/rollback mechanism using Spring
I'm trying to write a custom method security interceptor. However, it isn't using the
I'm trying to write an interceptor for a web service that will modify the
I'm trying to write a web application using Spring MVC. I have a configuration
I am trying to write some content into file inside my spring controller. Before
I certainly hope someone can help ease my frustration. I am trying to find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.