0

我正在使用 JAX-RS 注释,但在使用 @BeanParam 时遇到问题。我正在使用 Wildfly-Swarm 和 Maven。下面几行是我的错误的一部分:

2017-05-02 09:57:39,513 INFO [org.wildfly.swarm.runtime.deployer](主要)部署 e15735ec-96f3-42f3-be84-4dbd08e05e0d.war 2017-05-02 09:57:39,543 INFO [org .jboss.as.server.deployment](MSC 服务线程 1-7)WFLYSRV0027:开始部署“e15735ec-96f3-42f3-be84-4dbd08e05e0d.war”(运行时名称:“e15735ec-96f3-42f3-be84-4dbd08e05e0d .war") 2017-05-02 09:57:40,419 WARN [org.jboss.as.dependency.private](MSC 服务线程 1-4)WFLYSRV0018:部署“deployment.e15735ec-96f3-42f3-be84-4dbd08e05e0d。 war" 正在使用一个私有模块 ("org.jboss.jts:main"),它可能在未来的版本中被更改或删除,恕不另行通知。2017-05-02 09:57:40,488 INFO [org.jboss.weld.deployer](MSC 服务线程 1-4)WFLYWELD0003:处理焊接部署 e15735ec-96f3-42f3-be84-4dbd08e05e0d。

我的 pom.xml:

<modelVersion>4.0.0</modelVersion> 
<groupId>com.test.example</groupId> 
<artifactId>ws-be-example1</artifactId> 
<name>ws-be-example1</name>
<version>1.0.0-SNAPSHOT</version> 
<packaging>jar</packaging> 
<properties>
    <version.wildfly.swarm>2016.8.1</version.wildfly.swarm>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.wildfly.swarm</groupId>
            <artifactId>bom-all</artifactId>
            <version>${version.wildfly.swarm}</version>

            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>


<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>

    <!-- Wildfly Swarm Fractions -->
    <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>logging</artifactId>
    </dependency>
    <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>jaxrs-cdi</artifactId>
    </dependency>
    <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>swagger</artifactId>
    </dependency>


    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongo-java-driver</artifactId>
        <version>3.4.2</version>
    </dependency>

    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1</version>
    </dependency>
</dependencies>

<build>
    <finalName>ws-be-example1</finalName>

    <plugins>

        <plugin>
            <groupId>org.wildfly.swarm</groupId>
            <artifactId>wildfly-swarm-plugin</artifactId>
            <version>${version.wildfly.swarm}</version>

            <configuration>
                <mainClass>com.test.example.Main</mainClass>
                <properties>
                    <swarm.http.port>3001</swarm.http.port> 
                    <swarm.debug.port>5005</swarm.debug.port>
                </properties>

                <environment>
                    <EXAMPLE2_HOST>localhost</EXAMPLE2_HOST>
                    <EXAMPLE2_PORT>8082</EXAMPLE2_PORT>
                    <EXAMPLE2_CONTEXT>/example2/frame</EXAMPLE2_CONTEXT>
                </environment>
            </configuration>

            <executions>
                <execution>
                    <goals>
                        <goal>package</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我的豆子:

package com.test.example.models;
import javax.ws.rs.FormParam;

public class User {


   @FormParam("nombre")
   private String nombre;

   @FormParam("apellido1")
   private String apellido1;

   @FormParam("apellido2")
   private String apellido2;

   @FormParam("direccion")
   private String direccion;

public User(String nombre, String apellido1, String apellido2, String direccion) {
    this.nombre = nombre;
    this.apellido1 = apellido1;
    this.apellido2 = apellido2;
    this.direccion = direccion;
}

public String getNombre() {
    return nombre;
}

public String getApellido1() {
    return apellido1;
}

public String getApellido2() {
    return apellido2;
}

public String getDireccion() {
    return direccion;
}
}

我在我的端点中注入了 before 类,如下所示:

@Path("/test")
@POST
@Produces(MediaType.APPLICATION_JSON)
public Response prueba(@BeanParam User user){
   return Response.ok().build();
}

首先感谢您的帮助:)

4

1 回答 1

1

问题解决了 !我忘了在 JAXRSArchive 中添加我的类的包...

    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);

    deployment.setContextRoot("example1");
    deployment.addPackage("com.test.example.rest");
    deployment.addPackage("com.test.example.services");

    //I forgot to add this line
    deployment.addPackage("com.test.example.models");  

谢谢你们的帮助!:)

于 2017-05-03T10:14:22.163 回答