1

I have defined a Spring application context xml which will be edited by end users to add new beans.Something like:

<bean name="myBeanName1" class="com.xxx.Yyy">
    <property name="type" value="type1" />
    <property name="name" value="name1" />
    <property name="arguments" value="arg1" />
</bean>

<bean name="myBeanName2" class="com.xxx.Yyy">
    <property name="type" value="type2" />
    <property name="name" value="name2" />
    <property name="arguments" value="arg2" />
</bean>

.
.
.

Now I am asked to change this to a normal xml so that users wont be bothered by bean property and class names:

<def name="Name1">
    <type>type1</type>
    <argument>arg1</argument
</def>

<def name="Name2">
    <type>type2</type>
    <argument>arg2</argument
</def>

As my code is using the bean, how can I use the new xml with minimal code change so that it is converted to a bean definition as earlier and things work as before?.

I dont know if Spring has a solution for this out of the box. What I thought was applying stylesheet to the new xml to create my older bean. Any other better/elegant solution for this?

Edit: Now that user input is not inside the bean anymore, is it possible to use the new xml to inject to a @Component class?

1 Answer 1

4

Spring supports creating custom tags. You need to create xsd schema, NamespaceHandlerm, implement BeanDefinitionParsers and make spring aware of these by creating spring.handlers & spring.schemas special files.

Have a look at Extensible XML authoring

Example:

<beans xmlns declaration goes here>
    <yournamespace:yourcustomtag id="some id">
         <yournamespace:some_other_tag your-custom-attribute="some value" />
    </yournamespace:yourcustomtag>
</beans>
Sign up to request clarification or add additional context in comments.

2 Comments

+1 Will check this out. but looks like there is some amount of coding required to achieve this. Also will this change the xml to a different format, though minor?
Yes it will change xml to different format. Example updated in answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.