开发者

how to load spring without a web container

I have a RESTful service using Jersey/Spring/Tomcat. My question is - is it possible to access the classes within my war from command line (without the web interface)?

The problem is the JDBC connections and some other beans are managed by spring. So how do I load all these beans without the web c开发者_StackOverflow社区ontainer?


You can easily initialize application context and load all the classes manually. Here is an example:

ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("/applicationContext.xml");
YourBean yourBean = applicationContext.getBean("yourBean", YourBean.class);        
applicationContext.close();


Classes in a WAR archive are tricky, because you'll have to tell the ClassLoader to look inside WEB-INF/classes and WEB-INF/lib/*.jar . Sounds non-trivial to me...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜