Results 1 to 4 of 4

Thread: Can one define a placeholder within configuration file

  1. #1
    Join Date
    Oct 2004
    Posts
    7

    Default Can one define a placeholder within configuration file

    Is it possible to define a placeholder within the Spring configuration file, say simliar to the Ant "property".

    I understand how PropertyPlaceholderConfigurer works, but it is not always a beans property value that I want to shortcut.

    I would like to shortcut a classname that I use repeatedly within the config.

    Just some psuedo of what I am looking for:

    <define property="thisclass" value="com.xyz.MyClass" />

    <bean id="myId" class="${thisclass}" >
    ...
    </bean>

    Thanks for any info/solutions!

  2. #2

    Default

    Hi,

    I just had the same problem. I did not find a direct solution, but a I think I found a good work arround:

    I implemented a BeanFactory, creating a class per Reflection. The class name can be set using a property. Of course, my simple implementation does only work with bean having no constructor parameter.

    Code:
    public class ReflectionFactory extends AbstractFactoryBean implements
        FactoryBean &#123;
    
      private String className;
    
      public void setClassName&#40;String className&#41; &#123;
        this.className = className;
      &#125;
    
      protected Object createInstance&#40;&#41; throws Exception &#123;
        return getObjectType&#40;&#41;.newInstance&#40;&#41;;
      &#125;
    
      public Class getObjectType&#40;&#41; &#123;
        try &#123;
          return Class.forName&#40;className&#41;;
        &#125; catch &#40;ClassNotFoundException e&#41; &#123;
          throw new IllegalArgumentException&#40;"Given Classname " + className
              + " not found.", e&#41;;
        &#125;
      &#125;
    
    &#125;
    greetings
    Robert

  3. #3

    Default

    I forgot:

    Then you can use the factory bean in following way:

    Code:
    <bean id="namingStrategy" class="ReflectionFactory">
    		<property name="className" value="$&#123;tas.namingStrategy&#125;" />
       </bean>
    Robert

  4. #4
    Join Date
    Aug 2004
    Location
    Vancouver, Canada
    Posts
    25

    Default

    You can always use the parent attribute.

    Code:
    <bean id="baseId" class="yourpkg.yourclass" abstract="true"> 
    ...can specify any properties that should be reused... 
    </bean> 
    
    <bean id="myId" parent="baseId" > 
    ... can override properties from the base..
    </bean>

Similar Threads

  1. Saving large files to a db using hibernate?
    By Dan Washusen in forum Data
    Replies: 10
    Last Post: Sep 20th, 2006, 12:18 PM
  2. Can't find the configuration file in WebLogic...
    By anagnost68 in forum Container
    Replies: 1
    Last Post: Sep 8th, 2005, 01:00 AM
  3. Templating the Spring configuration file
    By meagle in forum Container
    Replies: 3
    Last Post: Mar 20th, 2005, 05:16 AM
  4. Scripting the container configuration file.
    By alruiz15 in forum Container
    Replies: 4
    Last Post: Jan 12th, 2005, 08:20 AM
  5. Replies: 5
    Last Post: Aug 27th, 2004, 07:13 PM

Posting Permissions

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