Announcement Announcement Module
Collapse
No announcement yet.
I'd like to get all the BeanDefinitions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • I'd like to get all the BeanDefinitions

    We are using Spring DI in our project. However, certain types of errors in the configuration file take too long to become visible.

    What I'd like to do is be able to load a context file and get a hold of all the BeanDefinitions, without any of them being instantiated.

    Any pointers?
    David

  • #2
    I just don't know if there is any application context method to do it, see there, but maybe you can parse the file with XPATH to retrieve all bean definitions. Just don't know if this can be useful.

    Comment


    • #3
      beandoc

      Have you also looked at beandoc? I've found that has been helpful with some configuration issues (such as a typo in the name of a bean)

      Comment


      • #4
        I think a BeanFactoryPostProcessor would be suitable for your case. You can check it out in the javadoc.

        Comment


        • #5
          What *is* beandoc?

          Comment


          • #6
            Wouldn't BeanFactoryPostProcessor require me to have a bean IN the context? I'd like to remain outside of it.

            something like...

            new ApplicationContext("foo.xml").getBeanDefinitions() .

            Comment


            • #7
              Originally posted by dcorbin View Post
              Wouldn't BeanFactoryPostProcessor require me to have a bean IN the context? I'd like to remain outside of it.

              something like...

              new ApplicationContext("foo.xml").getBeanDefinitions() .
              I don't exactly understand what you mean, but BeanFactoryPostProcessor gets a chance to run before the beans get instantiated. The context that is passed to the beanfactorypostprocessor can be used to get the beandefinitions. You may want to take a look at PropertyPlaceholderConfigurer or PropertyOverriderConfigurer.

              Comment


              • #8
                All of those interfaces are things that Beans *in* the context implement, right? And then special processing takes place for beans that have defined those interfaces.

                I simply want to load a bunch of bean definitions, without having 'my tool code' defined in the context.

                Comment


                • #9
                  Originally posted by dcorbin View Post
                  What *is* beandoc?
                  http://opensource.atlassian.com/conf...play/BDOC/Home

                  Comment


                  • #10
                    Hi David

                    What I'd like to do is be able to load a context file and get a hold of all the BeanDefinitions, without any of them being instantiated.
                    I think that a simple BeanFactory is what you want. The BeanFactory contract is to not pre-instantiate any of your beans at startup. So you could be looking to do this...

                    Code:
                    BeanFactory container = new DefaultListableBeanFactory();
                    BeanDefinitionReader reader = new XmlBeanDefinitionReader(container);
                    
                    reader.loadBeanDefinitions(new ClassPathResource("service-beans.xml"));
                    You can the use the various methods on the various interfaces implemented by the DefaultListableBeanFactory (such as this one) to iterate over and otherwise get all of the BeanDefinitions before they are instantiated. You can then do whatever it is that you want to do... which is what exactly?

                    Cheers
                    Rick

                    Comment

                    Working...
                    X