来自现有 bean 的 Spring XML - 如何?
我有 java bean:
package com.denisk.beans;
...
public class SomeBean {
private String someProperty;
private AnotherBean anotherBean;
...
}
public class AnotherBean {
private String anotherProperty;
....
}
我想为这些 bean 生成一个 stub xml spring 配置,就像
<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>
我希望使用某种工具来完成此操作,该工具将接受我的 bean 的路径作为输入,例如那:
denisk@denisk-work:~$ generateSpringXml -p "/home/denisk/myProject/src/main/java/com/denisk/beans" -output "/home/denisk/mySpringConfig.xml"
应该没什么大不了的,但我无法用谷歌搜索出类似的东西。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这个:
https://github.com/mangstadt/Spring-Application-Context-Generator
这将获取 Java 类列表并为它们生成 XML bean 定义。它为每个公共类生成一个元素(如果只有一个构造函数并且该构造函数不是默认构造函数)。
元素,为每个公共字段和 setter 方法生成一个
元素,以及一个
元素。 code>示例:
如果您尝试此操作,请告诉我是否有任何问题,以便我进行改进。
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:
If you try this out, let me know if there are any problems so I can make improvements.