java - 简单的 JAX-RS 应用程序在部署到 Wildfly 8 时抛出 UnsupportedOperationException

标签 java web-services maven jax-rs wildfly

我有一个 jax-rs 应用程序,我想在 Wildfly 8 中运行。

当我尝试迁移它时,我在部署时遇到了一个奇怪的异常。因为它看起来像是一个依赖问题,所以我想从一个简单的 Wildfly 快速入门示例应用程序中学习。这些是重要的部分:

pom.xml:

<groupId>org.wildfly.quickstarts</groupId>
<artifactId>wildfly-helloworld-rs</artifactId>
<version>8.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>WildFly Quickstarts: JAX-RS Helloworld</name>
<description>WildFly Quickstarts: Helloworld using JAX-RS</description>

<url>http://wildfly.org</url>
<licenses>
    <license>
        <name>Apache License, Version 2.0</name>
        <distribution>repo</distribution>
        <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
    </license>
</licenses>

<properties>
    <!-- Explicitly declaring the source encoding eliminates the following message: -->
    <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered 
        resources, i.e. build is platform dependent! -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <!-- JBoss dependency versions -->

    <version.wildfly.maven.plugin>1.0.1.Final</version.wildfly.maven.plugin>

    <version.jboss.spec.javaee.7.0>1.0.0.Final</version.jboss.spec.javaee.7.0>


    <!-- other plugin versions -->
    <version.compiler.plugin>3.1</version.compiler.plugin>
    <version.war.plugin>2.1.1</version.war.plugin>

    <!-- maven-compiler-plugin -->
    <maven.compiler.target>1.7</maven.compiler.target>
    <maven.compiler.source>1.7</maven.compiler.source>
</properties>

<dependencyManagement>
    <dependencies>
        <!-- Define the version of JBoss' Java EE 7 APIs we want to import.
            Any dependencies from org.jboss.spec will have their version defined by this 
            BOM -->
        <!-- JBoss distributes a complete set of Java EE 7 APIs including
            a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or
            a collection) of artifacts. We use this here so that we always get the correct
            versions of artifacts. Here we use the jboss-javaee-7.0 stack (you can
            read this as the JBoss stack of the Java EE 7 APIs). You can actually
            use this stack with any version of WildFly that implements Java EE 7, not
            just WildFly 8! -->
        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-7.0</artifactId>
            <version>${version.jboss.spec.javaee.7.0}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>

    <!-- Import the CDI API, we use provided scope as the API is included in JBoss WildFly -->
    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the Common Annotations API (JSR-250), we use provided scope 
        as the API is included in JBoss WildFly -->
    <dependency>
        <groupId>org.jboss.spec.javax.annotation</groupId>
        <artifactId>jboss-annotations-api_1.2_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the JSON API to build JSON Objects -->
    <dependency>
        <groupId>org.jboss.spec.javax.json</groupId>
        <artifactId>jboss-json-api_1.0_spec</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Import the JAX-RS API, we use provided scope as the API is included in JBoss WildFly -->
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>jaxrs-api</artifactId>
        <scope>provided</scope>
    </dependency>


</dependencies>

<build>
    <!-- Set the name of the war, used as the context root when the app 
        is deployed -->
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>${version.war.plugin}</version>
            <configuration>
           <!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <!-- WildFly plugin to deploy war -->
        <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <version>${version.wildfly.maven.plugin}</version>
        </plugin>
        <!-- Compiler plugin enforces Java 1.6 compatibility and activates 
            annotation processors -->
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${version.compiler.plugin}</version>
            <configuration>
                <source>${maven.compiler.source}</source>
                <target>${maven.compiler.target}</target>
            </configuration>
        </plugin>
    </plugins>
</build>

我添加了一个配置类:

@ApplicationPath("/rest")
public class Configuration extends Application {
    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> classes = super.getClasses();
        classes.add(HelloWorld.class);
        return classes;
    }
}

当我部署它时,它看起来像这样:

14:31:01,325 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./wildfly-helloworld-rs: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./wildfly-helloworld-rs: Failed to start service

...

Caused by: java.lang.UnsupportedOperationException at java.util.AbstractCollection.add(AbstractCollection.java:252) [rt.jar:1.7.0_25]

编辑:当然,在 getClasses 方法中设置的类是指这里 - 剪裁太多

这与我自己的应用程序遇到的问题完全相同。

我错过了什么吗?

提前致谢!

最佳答案

它的行为与 javadoc 完全相同指定:

Implementations MUST NOT modify the returned set.

The default implementation returns an empty set.

所以,而不是 Set<Class<?>> classes = super.getClasses();只需创建一个新的集合实例。

关于java - 简单的 JAX-RS 应用程序在部署到 Wildfly 8 时抛出 UnsupportedOperationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23236315/

相关文章:

java - 使用ArrayList存储扩展线程的类

asp.net - 使用 Sharepoint Web 服务

java - 对象引用未保存的 transient 实例 - 在刷新 : com. entity.Role 之前保存 transient 实例

.NET网络服务 "Could not create type"

php - 使用 PHP 访问 Sabre Web 服务

java - 由于 StackOverflowError,无法完成对 Web 应用程序 [/app] 注释的扫描

java - 如何设置 get junit 以显示正确的错误或异常堆栈跟踪

java - 在 Groovy 脚本中声明的类可以在 javassist 中访问吗?

java - Google App Engine 的 JRE 不支持 GWT 和 LocalDate

java - JScrollPane 中的透明 JList