Announcement Announcement Module
Collapse
No announcement yet.
Configure a library built with Spring from outside Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configure a library built with Spring from outside

    Hi!
    We've built a library with spring composing it with an applicationContext.xml.

    The configuration parameters are handled by a PropertyPlaceHolderConfigurer. The property file is loaded from the class path.

    Now the component using the library is deployed in a servlet context. This means that the property file is searched for in the servlet context's class path.

    But we want to configure the component with the container's configuration facility.

    The library exposes a Factory that loads the applicationContext.xml and finds a bean and returns a bean from the beans factory to the client.

    The solution I came up with is following:
    - the client sets an instance of a class Resolver on the Factory.
    - the factory adds a subclass of the PropertyPlaceHolderConfigurerer (MyConfigurer) as a BeanFactoryPostProcessor to the context if the resolver instance is set
    - the factory refrehes the application context
    - During refresh MyConfigurer calls the Resolver instance that was set by the client


    This seems a bit complicated. Is there an easier way. Or is it completely stupid to build a library with spring and expect it to be intregratable iinto any component?

    Regards Martin

  • #2
    Martin,

    It is definitely not stupid to build a spring library. I have built an entire architecture based on generic component using spring libraries that are used in stand-alone and web applications.

    I am not too clear on what you are trying to acheive:

    1. Is the client web application configured with Spring as well?

    2. Please elaborate on
    "But we want to configure the component with the container's configuration facility. "
    In any case, how I have handled a possible scenario is as follows:

    - Client A is my webapp, which utilises a spring library called B.
    - B does some processing, however needs some info from A.
    - I would then define a properties file (x.prop) within A with a token representing a fully qualified class name which is housed within A.
    - Upon boostrapping application context B, the context would reference this specific token and utilise it. Hence, any other client applications which use B, would need to define x.prop would the token, and its done.

    Does this help at all?

    /wolf

    Comment

    Working...
    X