2017-10-11 119 views
0

我试图做一些REST服务与JBOSS AS7,但是当我尝试访问他们的日志说404。
我一直在寻找解决方案,但没有找到解决方案。
这些服务位于WAR项目中,该项目位于EAR文件中,用于在JBOSS中进行部署。REST服务does'n加载jboss AS 7

我使用CXF和CDI来提供服务。
JBOSS有EasyRest 3.0.5版本。

这是WAR项目的pom.xml:

<?xml version="1.0"?> 
<project 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" 
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 


<modelVersion>4.0.0</modelVersion> 
    <parent> 
     <groupId>projectParent</groupId> 
     <artifactId>projectParent</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
    </parent> 
    <groupId>projectParent</groupId> 
    <artifactId>projectWARModule</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>war</packaging> 
    <name>projectWARModule Maven Webapp</name> 
    <url>http://maven.apache.org</url> 
    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <org.apache.cxf.version>3.0.0</org.apache.cxf.version> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>3.8.1</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>javax.enterprise</groupId> 
      <artifactId>cdi-api</artifactId> 
      <version>1.1</version> 
     </dependency> 

     <dependency> 
      <groupId>org.apache.cxf</groupId> 
      <artifactId>cxf-integration-cdi</artifactId> 
      <version>${org.apache.cxf.version}</version> 
     </dependency> 
     <!-- https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api --> 
     <dependency> 
      <groupId>javax.annotation</groupId> 
      <artifactId>javax.annotation-api</artifactId> 
      <version>1.2</version> 
     </dependency> 

     <dependency> 
      <groupId>org.apache.cxf</groupId> 
      <artifactId>cxf-rt-transports-http</artifactId> 
      <version>${org.apache.cxf.version}</version> 
     </dependency> 
     <!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-wsdl --> 
     <dependency> 
      <groupId>org.apache.cxf</groupId> 
      <artifactId>cxf-rt-wsdl</artifactId> 
      <version>3.0.0</version> 
     </dependency> 
     <!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-ws-policy --> 
     <dependency> 
      <groupId>org.apache.cxf</groupId> 
      <artifactId>cxf-rt-ws-policy</artifactId> 
      <version>3.0.0</version> 
     </dependency> 

     <dependency> 
      <groupId>com.fasterxml.jackson.jaxrs</groupId> 
      <artifactId>jackson-jaxrs-json-provider</artifactId> 
      <version>2.2.3</version> 
     </dependency> 

     <dependency> 
      <groupId>com.fasterxml.jackson.core</groupId> 
      <artifactId>jackson-core</artifactId> 
      <version>2.2.3</version> 
     </dependency> 

     <dependency> 
      <groupId>org.jboss.weld.servlet</groupId> 
      <artifactId>weld-servlet</artifactId> 
      <version>2.1.2.Final</version> 
     </dependency> 

     <dependency> 
      <groupId>org.jboss.weld</groupId> 
      <artifactId>weld-core</artifactId> 
      <version>2.1.2.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.inject</groupId> 
      <artifactId>javax.inject</artifactId> 
      <version>1</version> 
     </dependency> 
    </dependencies> 

    <repositories> 
     <repository> 
      <id>maven2-repository.dev.java.net</id> 
      <url>http://download.java.net/maven/2/</url> 
     </repository> 
     <repository> 
      <id>jboss-public</id> 
      <url>http://repository.jboss.org/nexus/content/groups/public/</url> 
     </repository> 
    </repositories> 
    <build> 
     <finalName>projectWAR</finalName> 
    </build> 
</project> 

这是EAR包的pom.xml的,它有一个JAR的引用,因为在教程中,我发现了有关使耳朵Maven的它说,使用它,但没有任何东西:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
    <groupId>projectParent</groupId> 
    <artifactId>projectParent</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    </parent> 
    <artifactId>projectEARModule</artifactId> 
    <packaging>ear</packaging> 
    <dependencies> 
    <dependency> 
     <groupId>projectParent</groupId> 
     <artifactId>projectJARModule</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
    </dependency> 
    <dependency> 
     <groupId>projectParent</groupId> 
     <artifactId>projectWARModule</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
     <type>war</type> 
    </dependency> 
    </dependencies> 
    <build> 
    <finalName>projectEar</finalName> 
    </build> 
</project> 

这个类被命名为PeopleRestService和服务过的:

package com.example.rs; 

import java.util.Collection; 

import javax.inject.Inject; 
import javax.ws.rs.DELETE; 
import javax.ws.rs.DefaultValue; 
import javax.ws.rs.FormParam; 
import javax.ws.rs.GET; 
import javax.ws.rs.POST; 
import javax.ws.rs.PUT; 
import javax.ws.rs.Path; 
import javax.ws.rs.PathParam; 
import javax.ws.rs.Produces; 
import javax.ws.rs.QueryParam; 
import javax.ws.rs.core.Context; 
import javax.ws.rs.core.MediaType; 
import javax.ws.rs.core.Response; 
import javax.ws.rs.core.UriInfo; 

import com.example.model.Person; 
import com.example.services.PeopleService; 

@Path("/people") 
public class PeopleRestService { 


@Inject private PeopleService peopleService; 

    @Produces({ MediaType.APPLICATION_JSON }) 
    @GET 
    public Collection<Person> getPeople(@QueryParam("page") @DefaultValue("1") final int page) { 
     return peopleService.getPeople(page, 5); 
    } 

    @Produces({ MediaType.APPLICATION_JSON }) 
    @Path("/{email}") 
    @GET 
    public Person getPerson(@PathParam("email") final String email) { 
     return peopleService.getByEmail(email); 
    } 

    @Produces({ MediaType.APPLICATION_JSON }) 
    @POST 
    public Response addPerson(@Context final UriInfo uriInfo, 
      @FormParam("email") final String email, 
      @FormParam("firstName") final String firstName, 
      @FormParam("lastName") final String lastName) { 

     final Person person = peopleService.addPerson(email, firstName, lastName); 
     return Response.created(uriInfo.getRequestUriBuilder().path(email).build()).entity(person).build(); 
    } 

    @Produces({ MediaType.APPLICATION_JSON }) 
    @Path("/{email}") 
    @PUT 
    public Person updatePerson(   
      @PathParam("email") final String email, 
      @FormParam("firstName") final String firstName, 
      @FormParam("lastName") final String lastName) { 

     final Person person = peopleService.getByEmail(email); 

     if(firstName != null) { 
      person.setFirstName(firstName); 
     } 

     if(lastName != null) { 
      person.setLastName(lastName); 
     } 

     return person;    
    } 

    @Path("/{email}") 
    @DELETE 
    public Response deletePerson(@PathParam("email") final String email) { 
     peopleService.removePerson(email); 
     return Response.ok().build(); 
    } 
} 

而这个名为JaxRsApiApplication:

package com.example.rs; 

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

import javax.enterprise.inject.Produces; 
import javax.inject.Inject; 
import javax.ws.rs.ApplicationPath; 
import javax.ws.rs.core.Application; 

import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; 

@ApplicationPath("api") 
public class JaxRsApiApplication extends Application { 

} 

这是beans.xml中:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
     http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" 
     bean-discovery-mode="all"> 
</beans> 

这是在web.xml:

<!DOCTYPE web-app PUBLIC 
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
"http://java.sun.com/dtd/web-app_2_3.dtd" > 

<web-app> 
    <display-name>Archetype Created Web Application</display-name> 

    <context-param> 
     <param-name>resteasy.scan</param-name> 
     <param-value>false</param-value> 
    </context-param> 
    <context-param> 
     <param-name>resteasy.scan.providers</param-name> 
     <param-value>false</param-value> 
    </context-param> 
    <context-param> 
     <param-name>resteasy.scan.resources</param-name> 
     <param-value>false</param-value> 
    </context-param> 

    <listener> 
     <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class> 
    </listener> 

    <servlet> 
     <servlet-name>PeopleRestService</servlet-name> 
     <servlet-class>org.apache.cxf.cdi.CXFCdiServlet</servlet-class> 
     <init-param> 
      <param-name>org.apache.cxf.cdi</param-name> 
      <param-value>com.example.rs</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>PeopleRestService</servlet-name> 
     <url-pattern>/*</url-pattern> 
    </servlet-mapping> 

</web-app> 

当我尝试运行此一个tomcat完美的工作,但在JBOSS中只能得到一个404.
我认为可能是库的问题,但不知道什么问题especificaly。

如果有人知道会发生什么,这将是一个很大的帮助。 非常感谢,如果我的英语不好,我很抱歉。

祝您有愉快的一天。

UPDATE
作为@JanezKuhar说我reemplace在POM进口。现在的依赖关系是这样的:

<dependencies> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>3.8.1</version> 
      <scope>test</scope> 
     </dependency> 

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

<!--  <dependency> --> 
<!--   <groupId>javax.enterprise</groupId> --> 
<!--   <artifactId>cdi-api</artifactId> --> 
<!--   <version>1.1</version> --> 
<!--  </dependency> --> 
<!--  <dependency> --> 
<!--   <groupId>org.apache.cxf</groupId> --> 
<!--   <artifactId>cxf-integration-cdi</artifactId> --> 
<!--   <version>${org.apache.cxf.version}</version> --> 
<!--  </dependency> --> 
<!--  <dependency> --> 
<!--   <groupId>org.apache.cxf</groupId> --> 
<!--   <artifactId>cxf-rt-frontend-jaxrs</artifactId> --> 
<!--   <version>${org.apache.cxf.version}</version> --> 
<!--  </dependency> --> 
<!--  <dependency> --> 
<!--   <groupId>javax.annotation</groupId> --> 
<!--   <artifactId>javax.annotation-api</artifactId> --> 
<!--   <version>1.2</version> --> 
<!--  </dependency> --> 
<!--  <dependency> --> 
<!--   <groupId>org.apache.cxf</groupId> --> 
<!--   <artifactId>cxf-rt-transports-http</artifactId> --> 
<!--   <version>${org.apache.cxf.version}</version> --> 
<!--  </dependency> --> 
<!--  <dependency> --> 
<!--   <groupId>org.apache.cxf</groupId> --> 
<!--   <artifactId>cxf-rt-wsdl</artifactId> --> 
<!--   <version>3.0.0</version> --> 
<!--  </dependency> --> 
<!--  <dependency> --> 
<!--   <groupId>org.apache.cxf</groupId> --> 
<!--   <artifactId>cxf-rt-ws-policy</artifactId> --> 
<!--   <version>3.0.0</version> --> 
<!--  </dependency> --> 

     <dependency> 
      <groupId>com.fasterxml.jackson.jaxrs</groupId> 
      <artifactId>jackson-jaxrs-json-provider</artifactId> 
      <version>2.2.3</version> 
     </dependency> 

     <dependency> 
      <groupId>com.fasterxml.jackson.core</groupId> 
      <artifactId>jackson-core</artifactId> 
      <version>2.2.3</version> 
     </dependency> 

<!--  <dependency> --> 
<!--   <groupId>org.jboss.weld.servlet</groupId> --> 
<!--   <artifactId>weld-servlet</artifactId> --> 
<!--   <version>2.1.2.Final</version> --> 
<!--  </dependency> --> 
<!--  <dependency> --> 
<!--   <groupId>org.jboss.weld</groupId> --> 
<!--   <artifactId>weld-core</artifactId> --> 
<!--   <version>2.1.2.Final</version> --> 
<!--  </dependency> --> 
<!--  <dependency> --> 
<!--   <groupId>javax.inject</groupId> --> 
<!--   <artifactId>javax.inject</artifactId> --> 
<!--   <version>1</version> --> 
<!--  </dependency> --> 
    </dependencies> 

但现在给了我以下错误:

产生的原因:抛出java.lang.ClassNotFoundException:org.apache.cxf.cdi.CXFCdiServlet从[模块“的部署。 projectEar.ear.projectWARModule-0.0.1-SNAPSHOT.war:main“from Service Module Loader]

+0

相同的耳朵在tomcat中工作,但不在jboss的权利? –

+0

为什么要导入JavaEE API部件(焊接,CXF)的所有实现。让App服务器决定使用哪一个,并且只需将[javaee-api](https://mvnrepository.com/artifact/javax/javaee-api)工件(其中包含所有接口定义)添加到您的根项目与'提供'范围。 –

+0

@yılmaz.war在tomat中工作,但不在jboss中的.ear中工作。 –

回答

0

Finaly make this works。

由于@JanezKuhar说我评论的POM所有额外的库和增加了两个,现在看起来是这样的:

<?xml version="1.0"?> 
<project 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" 
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
     <groupId>projectParent</groupId> 
     <artifactId>projectParent</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
    </parent> 
    <groupId>projectParent</groupId> 
    <artifactId>projectWARModule</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>war</packaging> 
    <name>projectWARModule Maven Webapp</name> 
    <url>http://maven.apache.org</url> 
    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <org.apache.cxf.version>3.0.0</org.apache.cxf.version> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>3.8.1</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>javax</groupId> 
      <artifactId>javaee-api</artifactId> 
      <version>7.0</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.cxf</groupId> 
      <artifactId>cxf</artifactId> 
      <version>3.0.0</version> 
      <type>pom</type> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.weld.servlet</groupId> 
      <artifactId>weld-servlet</artifactId> 
      <version>2.1.2.Final</version> 
     </dependency> 
    </dependencies> 

    <repositories> 
     <repository> 
      <id>maven2-repository.dev.java.net</id> 
      <url>http://download.java.net/maven/2/</url> 
     </repository> 
     <repository> 
      <id>jboss-public</id> 
      <url>http://repository.jboss.org/nexus/content/groups/public/</url> 
     </repository> 
    </repositories> 

    <build> 
     <finalName>projectWAR</finalName> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-ejb-plugin</artifactId> 
       <version>2.3</version> 
       <configuration> 
        <ejbVersion>3.1</ejbVersion> 
        <archive> 
         <manifestEntries> 
          <Dependencies>org.apache.cxf.impl</Dependencies> 
         </manifestEntries> 
        </archive> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

评论servlet的一部分,并设置RestEasy的扫描真实,在网上。xml:

<!DOCTYPE web-app PUBLIC 
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
"http://java.sun.com/dtd/web-app_2_3.dtd" > 

<web-app> 
    <display-name>Archetype Created Web Application</display-name> 

    <context-param> 
     <param-name>resteasy.scan</param-name> 
     <param-value>true</param-value> 
    </context-param> 
    <context-param> 
     <param-name>resteasy.scan.providers</param-name> 
     <param-value>true</param-value> 
    </context-param> 
    <context-param> 
     <param-name>resteasy.scan.resources</param-name> 
     <param-value>true</param-value> 
    </context-param> 

    <listener> 
     <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class> 
    </listener> 

</web-app> 

现在,它可以工作,我可以访问部署在jboss中的REST服务。

感谢您提供的帮助。

0

jboss-app.xml在哪里? Maven是否创建它? 在jboss-app.xml中,你(或者maven)应该创建应用程序的上下文根。

jboss-app.xml: Every EAR application should specify a unique string name for the class loader. It's from JBoss doc. link