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

时间:2019-01-29 19:10:28

标签: java jax-rs

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

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

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

总体而言,我有一个Java应用程序,该应用程序使用JAX-RS批注(例如ApplicationPath,Path,Products / Consums和JsonProperty)来尝试在“应用程序服务器”上创建端点。我之所以说“应用程序服务器”,是因为我没有有关该系统的文档,因此我将其称为“应用程序服务器”。尝试启动应用程序时,出现以下异常:

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)

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

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

服务器代码

这是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);

现在我的代码:

应用代码

MyApplication

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>

再次感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我想出了我问题的答案。

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

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

然后,我将scope中某些依赖项的pom.xml设置为<scope>provided</scope>,以便当应用程序由maven打包时,这些依赖项将不包含在最终的jar中。

下面是一个示例:

<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>