Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring XML from existing beans - how?

I have java beans:

package com.denisk.beans;
...
public class SomeBean {
    private String someProperty;
    private AnotherBean anotherBean;
    ...
}

public class AnotherBean {
    private String anotherProperty;
    ....
}

I want to generate a stub xml spring configuration for these beans, something like

<beans>
    <bean id="someBean">
        <property name="someProperty" value="sldfjslkdfjas;lfj"/>
        <property name="anotherBean" ref="anotherBean"/>
    </bean>
    <bean id="anotherBean">
        <property name="anotherProperty" value="klj;df;ksdjflsjkd;lfj"/>
    </bean>
</beans>

I want this to be done using some tool, which would accept a path to my beans as an input, like that:

denisk@denisk-work:~$ generateSpringXml -p "/home/denisk/myProject/src/main/java/com/denisk/beans" -output "/home/denisk/mySpringConfig.xml"

Shouldn't be a big deal, but I can't google out anything like that.

Thanks

like image 493
Denis Kniazhev Avatar asked Oct 11 '22 00:10

Denis Kniazhev


1 Answers

Check this out:

https://github.com/mangstadt/Spring-Application-Context-Generator

This will take a list of Java classes and generate the XML bean definitions for them. It generates a <bean /> element for each public class, a <property /> element for each public field and setter method, and a list of <constructor-arg /> elements if there is only one constructor and that constructor is not the default constructor.

Example:

java com.mangst.appcontext.ApplicationContextGenerator --source=/home/denisk/myProject/src/main/java --package=com.denisk.beans

If you try this out, let me know if there are any problems so I can make improvements.

like image 184
Michael Avatar answered Oct 14 '22 04:10

Michael