AbstractMethodError: javax.ws.rs.core.UriBuilder.uri in REST, EJB Application

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35303669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 16:31:58  来源:igfitidea点击:

AbstractMethodError: javax.ws.rs.core.UriBuilder.uri in REST, EJB Application

javamavenjerseyejb

提问by Araneo

I have troubles with my pom.xmlfile. I know, there is many topics about this issue, but any of them answers my problem.

我的pom.xml文件有问题。我知道,关于这个问题有很多主题,但它们中的任何一个都回答了我的问题。

@Path("/actors")
public class MainController {

    @EJB
    private ActorDaoLocal actorDao;  

}

@Local
public interface ActorDaoLocal { 
  //some stuff here
}

@Stateless
public class ActorDao implements ActorDaoLocal {

  @PersistenceContext
  private EntityManager em ; 
  //some stuff here 
}

@ManagedBean(name = "ActorBean")
@ApplicationScoped
public class ActorBean {

    @EJB
    private ActorDaoLocal usersDao;

}

In my application, when I haven't annotations in ActorBeanas follows:

在我的应用程序中,当我没有ActorBean如下注释时:

@ManagedBean(name = "ActorBean")
@ApplicationScoped 

actorDao is null in MainController

actorDao 为 null MainController

However, when I added this annotation and dependencies for it I am obtaining Exceptions:

但是,当我为它添加此注释和依赖项时,我获得了异常:

java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
    at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:651)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

My pom.xml:

我的pom.xml

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
    <type>jar</type>
</dependency>
<dependency>
    <groupId>asm</groupId>
    <artifactId>asm</artifactId>
    <version>3.1</version>
</dependency>
<dependency>
    <groupId>org.codehaus.Hymanson</groupId>
    <artifactId>Hymanson-core-asl</artifactId>
    <version>1.9.2</version>
</dependency>
<dependency>
    <groupId>org.codehaus.Hymanson</groupId>
    <artifactId>Hymanson-jaxrs</artifactId>
    <version>1.9.2</version>
</dependency>
<dependency>
    <groupId>org.codehaus.Hymanson</groupId>
    <artifactId>Hymanson-mapper-asl</artifactId>
    <version>1.9.2</version>
</dependency>
<dependency>
    <groupId>org.codehaus.Hymanson</groupId>
    <artifactId>Hymanson-xc</artifactId>
    <version>1.9.2</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-client</artifactId>
    <version>1.18</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-core</artifactId>
    <version>1.18</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-json</artifactId>
    <version>1.18</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.18</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-servlet</artifactId>
    <version>1.18</version>
</dependency>
<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>jsr311-api</artifactId>
    <version>1.1.1</version>
</dependency>
<dependency>
    <groupId>javax.ejb</groupId>
    <artifactId>ejb-api</artifactId>
    <version>3.0</version>
</dependency>
<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>eclipselink</artifactId>
    <version>2.5.2</version>
</dependency>
<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
    <type>jar</type>
</dependency>

Please help me correct this, I can't find mistake in my pom file.

请帮我纠正这个问题,我在我的 pom 文件中找不到错误。

I am working at Tomcat 8

我在 Tomcat 8 工作

采纳答案by Bruno César

You have multiple dependencies in your classpath that contains javax.ws.rs.core.UriBuilder, two of JAX-RS 1.1:

您的类路径中有多个依赖项,其中包含javax.ws.rs.core.UriBuilder两个 JAX-RS 1.1:

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>jsr311-api</artifactId>
    <version>1.1.1</version>
</dependency>


<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-core</artifactId>
    <version>1.18</version>
</dependency>

And one of JAX-RS 2.0:

和 JAX-RS 2.0 之一:

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

Since JAX-RS 2.0 is from Java EE 7, probably you need downgrade javaee-apito version 6, using like this:

由于 JAX-RS 2.0 来自 Java EE 7,您可能需要降级javaee-api到版本 6,使用如下:

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>6.0</version>
</dependency>

Other way is upgrade Jersey version, like in this answer: AbstractMethodError using UriBuilder on JAX-RS

另一种方法是升级 Jersey 版本,就像在这个答案中一样:AbstractMethodError using UriBuilder on JAX-RS

In runtime UriBuilder#uri(String)is called, so you need to verify the dependencies in the servlet container.

在运行时调用了 UriBuilder#uri(String),因此需要验证 servlet 容器中的依赖关系。