我已经定义了一个Spring-bean:
<bean id="myBean" class="package.MyBean">
<property name="name1" ref="otherBean" />
<property name="name2" vallue="2" />
</bean>我知道,它实现了一个特定的方法,例如MyBean.execute()。
我能从命令行启动这个方法吗?多么?(类似于java -jar ... myBean.execute)
发布于 2012-10-02 20:35:13
只需将其加载到main方法中,查找bean并以这种方式调用该方法:
public class Main {
public static void main(String[] args) {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:yourcontext.xml");
ctx.registerShutdownHook();
MyBean myBean = ctx.getBean("myBean", MyBean.class);
myBean.execute();
}
}https://stackoverflow.com/questions/12690067
复制相似问题