Announcement Announcement Module
No announcement yet.
How to map properties from non managed bean to other spring managed beans Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to map properties from non managed bean to other spring managed beans


    I use the ClassPathXmlApplicationContext to load my configuration from spring-config.xml.
    My project is basically a framework which will be used by other developers so I don't
    want them to edit my spring-config or inherit it and define the beans themselves.

    Instead, they provide me with the configuration needed to run the framework via and XML file
    (I don't use properties because they can supply complex types)
    Before I start spring I unmarshall the XML and hold all the info needed in a spring managed bean.
    I was wondering if there is a way to map properties from that bean to other spring managed beans
    Something like what we do with the "org.springframework.beans.factory.annotation.Valu e" annotation but instead of using the properties file I need to use an XML file or another managed bean.


  • #2
    Hi Tomer,

    I'll give you an idea, so you can further develop it.

    Implement a custom BeanExpressionResolver. You may look at StandardBeanExpressionResolver in order to get an idea about how to do it.
    With this custom implementation you should be free to do whatever you want when to parse @Value annotations.

    Now, create a custom post processor, implementing BeanFactoryPostProcessor, and do the next:
    public class YourCustomPostProcessor implements BeanFactoryPostProcessor{
        private BeanExpressionResolver beanExpressionResolver; // and add setter/getter
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)  throws BeansException {
    // Then in your xml file
    <bean class="YourCustomPostProcessor">
        <property name="beanExpressionResolver">
            <bean class="YourCustomExpressionResolver" />
    I left many details out of the loop, but I think you can get idea and continue by your own from here.