我使用的是最新的Spring和Jersey测试框架。我所有的资源都用泽西。
我有通过@Service注解初始化的spring beans。每个服务都将自己注册到一个客户ServiceContainer,它是一个bean单例。
在我的资源中,我从容器中获取服务并使用注释。我正在使用Jersey框架运行单元测试。如何使用@Service的注释初始化这些服务。我没有在我的资源中使用@Autowire / @Inject注解。
我看了几个类似的案例,但都没有帮助,有什么想法吗?
发布于 2016-04-17 06:01:48
以下是对我有效的方法:
@Override
protected DeploymentContext configureDeployment() {
ResourceConfig config = new ResourceConfig();
config.packages("com.my.application");
return ServletDeploymentContext
.forServlet(new ServletContainer(config))
.addListener(ContextLoaderListener.class)
.contextParam("contextConfigLocation", "classpath:applicationContext.xml")
.build();
}https://stackoverflow.com/questions/36661807
复制相似问题