GlassFish / Jersey Exception "java.lang.IllegalArgumentException: object is not an instance of declaring class" And Solution

The exception:

SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
java.lang.IllegalArgumentException: object is not an instance of declaring class
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(
	at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(
	at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(
	at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(
	at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(

is caused by exposing EJB 3.1 methods directly via REST without having a no-interface view declared. This happens when your EJB 3.1 REST-endpoint implements an additional interface without declaring the no-interface view:

import javax.ejb.*;

public class RESTEndpoint implements SomeLocalInterface{}

Adding a @LocalBean annotation (and activating the no-interface view) solves the problem:

import javax.ejb.*;

public class RESTEndpoint implements SomeLocalInterface{}


This is indeed very discouraging. I faced the same problem when working with local EJB - the simple stateless bean implementing some non-ejb interface must be annotated with @LocalBean to provide the possibility to inject bean through CDI. The exception was non-intuitive and it took long time for me to get the reason. As I saw in weld forum Gavin King was too sorry about this as he was against such additional actions and wanted to avoid additional annotations in this case.

Posted by Anton on February 01, 2012 at 09:27 AM CET #

Thank you! You make my day!

Posted by Hendrik on May 02, 2012 at 02:34 PM CEST #


Should I annotate my facade Ejb which is a REST interface to my other Local Ejb with @LocalBean ?

Posted by Ehsun on April 19, 2013 at 07:19 PM CEST #

Thanks a lot!

Posted by on April 17, 2016 at 09:58 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments