Java 运行Jersey测试时初始化Springbean

Java 运行Jersey测试时初始化Springbean,java,spring,spring-boot,jersey-2.0,spring-annotations,Java,Spring,Spring Boot,Jersey 2.0,Spring Annotations,我正在使用最新的Spring和Jersey测试框架。 我所有的资源都用球衣 我有一个Springbean,它正被@Service注释初始化。 每个服务都将自己注册到一个CustomerServiceContainer,它是一个bean单音 在我的资源中,我从容器中获取服务并使用注释。 我正在使用Jersey框架运行单元测试。如何使用@Service的注释初始化这些服务。我没有在我的资源中使用@Autowire/@Inject注释 我看了两个类似的案例,但没有任何帮助,有什么想法吗?以下是对我有效

我正在使用最新的Spring和Jersey测试框架。 我所有的资源都用球衣

我有一个Springbean,它正被@Service注释初始化。 每个服务都将自己注册到一个CustomerServiceContainer,它是一个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();

}

以下是对我有效的方法:

    @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();

}