Announcement Announcement Module
Collapse
No announcement yet.
How to externalize "class" attribute in applicationContext to a prop file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      How to externalize &quot;class&quot; attribute in applicationContext to a prop file

      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?

      Comment


      • #4
        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?

        Comment

        Working...
        X