gpt4 book ai didi

java - 运行 Jersey 测试时初始化 Spring beans

转载 作者:太空宇宙 更新时间:2023-11-04 12:42:45 25 4
gpt4 key购买 nike

我正在使用最新的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com