哪些容器提供商支持 org.apache.cxf.jaxrs.JAXRSServerFactoryBean?

What container provider supports org.apache.cxf.jaxrs.JAXRSServerFactoryBean?

使用下面提供的信息,您可以回答以下问题:

  1. 哪个容器提供程序支持 org.apache.cxf.jaxrs.JAXRSServerFactoryBean 以便我可以在创建端点时使用 org.glassfish.jersey.server.ContainerFactory 添加我的应用程序?
  2. 下面的应用程序有什么问题导致 (JAXRSServerFactoryBean)RuntimeDelegate.getInstance().createEndpoint(app, JAXRSServerFactoryBean.class); 抛出非法参数异常?

我正在尝试将使用注释的 JAX-RS 应用程序(无 web.xml)部署到使用 [=66= 的系统] 应用程序管理器(它是一个专有系统,已经移植了一些应用程序管理器库,但我不确定这些是什么,因为它周围的支持文档很少)。

在较高级别上,我有一个 Java 应用程序,它使用 JAX-RS 注释,例如 ApplicationPath、Path、Produces/Consumes 和 JsonProperty,以尝试在 "application server"。我说 "application server" 是因为我没有关于这个系统的文档,所以我就这样称呼它。尝试启动应用程序时出现以下异常:

java.lang.IllegalArgumentException: No container provider supports the type class org.apache.cxf.jaxrs.JAXRSServerFactoryBean
    at org.glassfish.jersey.server.ContainerFactory.createContainer(ContainerFactory.java:64)
    at org.glassfish.jersey.server.internal.RuntimeDelegateImpl.createEndpoint(RuntimeDelegateImpl.java:47)
    at com.app.Server.startServer(Server.java:182)

我研究了org.glassfish.jersey.server.internal.RuntimeDelegateImpl.createEndpoint函数抛出的java.lang.IllegalArgumentException。我不确定它为什么会这样做,因为在封面上它看起来像应用程序 class 被正确注释并且 extends Application.

我能够查看服务器的 class 代码,这是正在做的事情:

服务器代码

这里是 com.app.Server.startServer(Server.java:182) 代码的片段部分,我无法更改此代码:

inside of startServer...

Application app = (Application) Class.forName("com.app.MyApplication").newInstance();

JAXRSServerFactoryBean jaxrsServerFactory = (JAXRSServerFactoryBean)RuntimeDelegate.getInstance().createEndpoint(app, JAXRSServerFactoryBean.class);

现在我的代码:

申请代码

我的申请

package com.app;

import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

import com.app.services.ServiceOne;

@ApplicationPath("base/path")
public class MyApplication extends Application {

    public MyApplication() {
        System.out.println(Long.toString(System.nanoTime()) + " " + this.getClass().getName() + " constructor called...");
    }

    /* (non-Javadoc)
     * @see javax.ws.rs.core.Application#getClasses()
     */
    @Override
    public Set<Class<?>> getClasses() {
        System.out.println(Long.toString(System.nanoTime()) + " " + this.getClass().getName() + " getClasses() method called...");
        Set<Class<?>> classes = new HashSet<>();
        classes.add(ServiceOne.class);
        return classes;
    }
}

我的应用程序的服务

package com.app.services.ServiceOne;

import java.util.ArrayList;

import javax.ws.rs.Consumes;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

// pretend the model imports are here...

@Path("serviceOne")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class ServiceOne {

    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public ResponseObject performService(InputObject body) throws NotFoundException {
        // do whatever to get result and send...
    }

}

Pom.xml 插件和依赖项

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0.1</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.9.8</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.test-framework.providers</groupId>
            <artifactId>jersey-test-framework-provider-jdk-http</artifactId>
            <version>2.28-RC4</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <version>2.28-RC4</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.inject</groupId>
            <artifactId>jersey-hk2</artifactId>
            <version>2.28-RC4</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
            <version>2.28-RC4</version>
        </dependency>
    </dependencies>

再次感谢您的帮助!

我找到了问题的答案。

我试图将我的应用程序部署到的系统已经在系统的各个目录中安装了 jar 文件。

我更新了我的应用程序以包含那些 jar 文件。这是通过更新我用来将应用程序部署到系统的描述符来完成的。

然后我把我的pom.xml里面的某些依赖的scope设置成<scope>provided</scope>这样当应用被maven打包的时候,那些依赖就不会被包含在最后的罐子。

下面是一个例子:

<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.9.8</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.test-framework.providers</groupId>
            <artifactId>jersey-test-framework-provider-jdk-http</artifactId>
            <version>2.28-RC4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <version>2.28-RC4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.inject</groupId>
            <artifactId>jersey-hk2</artifactId>
            <version>2.28-RC4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
            <version>2.28-RC4</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>