嘿,伙计们,我正在尝试使用Embedded-jetty和jax-rs来配置和运行Restful服务,我发现了这个tutorial,它工作得非常出色,但是我的一个要求是在applicationContext.xml文件中通过spring xml尽可能多地进行配置。
我想在xml中做的部分是AppConfig.java类。
@Configuration
public class AppConfig {
@Bean( destroyMethod = "shutdown" )
public SpringBus cxf() {
return new SpringBus();
}
@Bean
public Server jaxRsServer() {
JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint( jaxRsApiApplication(), JAXRSServerFactoryBean.class );
factory.setServiceBeans( Arrays.< Object >asList( peopleRestService() ) );
factory.setAddress( '/' + factory.getAddress() );
factory.setProviders( Arrays.< Object >asList( jsonProvider() ) );
return factory.create();
}
@Bean
public JaxRsApiApplication jaxRsApiApplication() {
return new JaxRsApiApplication();
}
@Bean
public StatsRestService peopleRestService() {
return new StatsRestService();
}
@Bean
public StatsService peopleService() {
return new StatsService();
}
@Bean
public JacksonJsonProvider jsonProvider() {
return new JacksonJsonProvider();
}
}以及在哪里使用它
context.setInitParameter( "contextClass", AnnotationConfigWebApplicationContext.class.getName() );
context.setInitParameter( "contextConfigLocation", AppConfig.class.getName() );不幸的是,我在网上找不到任何关于如何在XML中做到这一点的像样的帖子,我将非常感谢一些帮助。
发布于 2013-04-14 18:13:19
如果您想通过XML配置Spring,那么您需要将所有内容从AppConfig类移动到${project}/src/applicationContext.xml中,并像这样引用它:
context.setInitParameter("contextConfigLocation", "classpath:applicationContext.xml");和工作applicationContext.xml的an example。您应该查看Spring Framework的网站以获取API参考。但是您可以从这个tutorial开始。
https://stackoverflow.com/questions/15997560
复制相似问题