我正在使用最新的 Spring 和 Jersey 测试框架。 我所有的资源都使用 Jersey 。
我有 spring bean,它们正在由 @Service 注释初始化。 每个服务将自己注册到一个客户 ServiceContainer,它是一个单例 bean。
在我的资源中,我从容器中获取服务并使用注释。 我正在使用 Jersey 框架运行单元测试。如何使用 @Service 注释来初始化这些服务。我没有在我的资源中使用 @Autowire/@Inject 注释。
我查看了几个类似的案例,但没有任何帮助,有什么想法吗?
最佳答案
这是对我有用的:
@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();
}
关于java - 运行 Jersey 测试时初始化 Spring beans,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36661807/