我在使用@BeanParam注释

时间:2017-05-02 08:53:07

标签: maven annotations jax-rs pom.xml wildfly-swarm

我正在使用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.war   2017-05-02 09:57:40,561 INFO   [org.hibernate.validator.internal.util.Version](MSC服务线程   1-4)HV000001:Hibernate Validator 5.2.3.Final 2017-05-02 09:57:40,861   ERROR [org.jboss.msc.service.fail](MSC服务主题1-4)MSC000001:   无法启动服务   。jboss.deployment.unit “e15735ec-96f3-42f3-be84-4dbd08e05e0d.war” .INSTALL:   服务中的org.jboss.msc.service.StartException   。jboss.deployment.unit “e15735ec-96f3-42f3-be84-4dbd08e05e0d.war” .INSTALL:   WFLYSRV0153:无法处理部署的阶段INSTALL   “e15735ec-96f3-42f3-be84-4dbd08e05e0d.war”at   org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:154)     在   org.jboss.msc.service.ServiceControllerImpl $ StartTask.startService(ServiceControllerImpl.java:1948)     在   org.jboss.msc.service.ServiceControllerImpl $ StartTask.run(ServiceControllerImpl.java:1881)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617)     在java.lang.Thread.run(Thread.java:745)引起:   java.lang.NoClassDefFoundError:com / test / example / models /用户来自   java.lang.Class.getDeclaredMethods0(Native Method)at   java.lang.Class.privateGetDeclaredMethods(Class.java:2701)at at   java.lang.Class.privateGetPublicMethods(Class.java:2902)at at   java.lang.Class.getMethods(Class.java:1615)at   io.swagger.jaxrs.Reader.read(Reader.java:255)at   io.swagger.jaxrs.Reader.read(Reader.java:147)at   io.swagger.jaxrs.config.BeanConfig.setScan(BeanConfig.java:172)at at   org.wildfly.swarm.swagger.deployment.SwaggerServiceActivator.activate(SwaggerServiceActivator.java:73)     在   org.jboss.as.server.deployment.service.ServiceActivatorProcessor.deploy(ServiceActivatorProcessor.java:74)     在   org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:147)     ... 5更多引起:java.lang.ClassNotFoundException:   com.test.example.models.User来自[Module   “deployment.e15735ec-96f3-42f3-be84-4dbd08e05e0d.war:main”来自   服务模块加载器]   org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)     在   org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)     在   org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)     在   org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)     ......还有15个

我的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;
}
}

我正在我的端点中注入前一类:

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

在感谢你的帮助之前:)

1 个答案:

答案 0 :(得分:0)

问题解决了! 我忘了在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");  

感谢您的帮助! :)