简体   繁体   English

Glassfish 4的Weld 001508异常:如何忽略接口?

[英]Weld 001508 exception on Glassfish 4: how to ignore interface(s)?

Problem: I keep getting the WELD exception below when trying to deploy my WAR to Glassfish 4.1.1. 问题:尝试将我的WAR部署到Glassfish 4.1.1时,我始终收到以下WELD异常。 The application deploys properly on Wildfly 9.0. 该应用程序可以在Wildfly 9.0上正确部署。

Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: org.jboss.weld.exceptions.DefinitionException: WELD-001508: Cannot create an InjectionTarget from [EnhancedAnnotatedTypeImpl] public abstract interface @Path class com.example.package.MyService as it is an interface 加载应用程序时发生异常:java.lang.IllegalStateException:ContainerBase.addChild:开始:org.apache.catalina.LifecycleException:org.apache.catalina.LifecycleException:org.jboss.weld.exceptions.DefinitionException: WELD-001508:无法创建来自[EnhancedAnnotatedTypeImpl]公共抽象接口@Path类com.example.package.MyService的InjectionTarget,因为它是一个接口

Here, MyService is indeed an interface, defined in a separate library. 在这里, MyService实际上是一个接口,在单独的库中定义。 My application pulls the library in so it can create a proxy against the MyService interface and make requests. 我的应用程序将库拉入,以便可以针对MyService接口创建代理并发出请求。 MyService looks like: MyService看起来像:

@Path("api")
public interface MyService {

    @GET
    public void someMethod();
}

I tried excluding MyService from WELD by adding the following to the beans.xml file, to no avail :( 我尝试通过将以下内容添加到beans.xml文件来将WELD中的MyService排除在外MyService

<scan>
    <exclude name="com.example.package.*"></exclude>
</scan>
  • Why is WELD trying to include that library's interface? 为什么WELD试图包含该库的接口?
  • How do I tell it to ignore it? 我如何告诉它忽略它?

You can also try to create package-info.java file and use @Vetoed : 您也可以尝试创建package-info.java文件并使用@Vetoed

@Vetoed
package com.example.package;

import javax.enterprise.inject.Vetoed;

Well, I didn't manage to find the root cause for this. 好吧,我没有找到根本原因。 However, I eventually got it to work by removing a bunch of Resteasy dependencies from the config file, which was probably the root cause of the problem. 但是,我最终通过从配置文件中删除了一堆Resteasy依赖来使它起作用,这可能是问题的根本原因。 (For context, I was migrating from Wildfly/Resteasy onto Glassfish/Jersey). (就上下文而言,我是从Wildfly / Resteasy迁移到Glassfish / Jersey的)。

At times, I still get this error (unsure why), but a clean and re-building of the package makes it go away. 有时,我仍然会收到此错误(不确定原因),但是对程序包进行全新的构建会使其消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM