Results 1 to 4 of 4

Thread: How to externalize "class" attribute in applicationContext to a prop file

  1. #1
    Join Date
    Jun 2006
    Posts
    2

    Question How to externalize "class" attribute in applicationContext to a prop file

    Hi,
    My question may look weird to you but thats what I need to do.

    Can somebody tell me how to externalize the class name in a bean definition in the applicationContext.xml.

    Thru a PropertyPlaceHolderConfigurer one can externalize the property values, but in my case I want to pick the value of the "class" attribute in the bean element from a property file. for example

    <bean id="myClass" class="a.b.c.TestClass">

    The package name i.e. a.b.c is kept in a properties file and I want to build the fully qualified name of the class by combining the package name and the "TestClass".

    Thanks in advance

  2. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,854

    Default

    If you are able to use Spring 2.0-rc1, the PropertyPlaceholderConfigurer can now resolve the "class" attribute when specified as a placeholder on a lazy-init bean.

  3. #3
    Join Date
    Jun 2006
    Posts
    2

    Default How to externalize "class" attribute in applicationContext to a prop file

    Quote Originally Posted by Mark Fisher
    If you are able to use Spring 2.0-rc1, the PropertyPlaceholderConfigurer can now resolve the "class" attribute when specified as a placeholder on a lazy-init bean.
    Thanks a lot for you reply...

    But the problem with using a post processor is that the Spring tries to load the bean classes first and only after that it invokes any post-processor. Thus the code breaks with a ClassNotFound Exception in an attempt to load a class in applicationContext with value "${test.package}.TestClass".

    Could you please suggestion any other way?

  4. #4
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,854

    Default

    If you are using 2.0-rc1 and the bean has lazy-init="true", then the post processor will defer loading of the bean's class until it is first accessed (after the placeholder is resolved). Are you able to use 2.0-rc1 and lazy-init in this case?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •