0

So I have a spring configuration file:

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

    <bean id="DisputeId" class="com.mycompany.validation.Attributes">
        <property name="validator" value="com.mycompany.validation.StringValidator" />
        <property name="maxLen" value="21" />
        <property name="nullable" value="false" />
    </bean>

I simply want to replace "com.mycompany.validation.Attributes" with something along the lines of "${attributes.class}".

How can I do this? I don't need to define ${attributes.class} in a different file, would prefer it to be in this same xml file. I know I'm just not searching for the correct terms...

Thanks!

2 Answers2

0

Declare a map in spring context, and use it by key

Vitalii Kravchenko
  • 395
  • 1
  • 2
  • 9
  • Tried , but was not able to find a way to reference the defined variable in the xml configuration, like ${attrib.class}. I just may not be doing it correctly? – Paul Ackley Aug 31 '16 at 15:12
0

So what I ended up doing was:

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="properties">
         <value>attrib.class=com.mycompany.validation.Attributes</value>
      </property>
    </bean>

    <bean id="DisputeId" class="${attrib.class}">
      <property name="maxLen" value="21" />
      <property name="nullable" value="false" />
    </bean>

This worked fine, I really just wanted to shorten the amount of xml to write/read. Is there another way to do this - just curious.