Search code examples
javaglassfishjax-rscdiweld

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. The application deploys properly on 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

Here, MyService is indeed an interface, defined in a separate library. My application pulls the library in so it can create a proxy against the MyService interface and make requests. MyService looks like:

@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 :(

<scan>
    <exclude name="com.example.package.*"></exclude>
</scan>
  • Why is WELD trying to include that library's interface?
  • How do I tell it to ignore it?

Solution

  • 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. (For context, I was migrating from Wildfly/Resteasy onto Glassfish/Jersey).

    At times, I still get this error (unsure why), but a clean and re-building of the package makes it go away.