RESTEasy 无法在 scala 类上调用我的带注释的方法
尝试在 Scala 中实现 JAX-RS 资源。我的 Java 版本具有以下类型签名:
@GET
@Path(value="echoold")
@Produces("application/json")
public Map<String,Object> get(
@QueryParam("param") String param,
@QueryParam("asOf") @DefaultValue(NOW) DateWrapper asOf,
@QueryParam("httpError") @DefaultValue("200") int httpError,
@QueryParam("httpErrorMessage") @DefaultValue("") String httpErrorMessage,
@QueryParam("fail") @DefaultValue("false") boolean fail) {
Scala 版本是这样的:
@GET
@Path(value="echo")
@Produces(Array("application/json"))
def get() = {
@QueryParam("param") param:String,
@QueryParam("asOf") @DefaultValue(NOW) asOf:DateWrapper,
@QueryParam("httpError") @DefaultValue("200") httpError:java.lang.Integer,
@QueryParam("httpErrorMessage") @DefaultValue("") httpErrorMessage:String,
@QueryParam("fail") @DefaultValue("false") fail:java.lang.Boolean):java.util.Map[String,Object] = {
当我启动我的应用程序时,我从 RESTEasy 收到这个奇怪的错误(我已对其进行格式化以便于阅读):
org.jboss.resteasy.spi.InternalServerErrorException:
Bad arguments passed to
public java.util.Map opower.api.endpoint.echo.Echo.get(java.lang.String,
opower.api.support.DateWrapper,
java.lang.Integer,
java.lang.String,
java.lang.Boolean)
( java.lang.String someValue,
opower.api.support.DateWrapper opower.api.support.DateWrapper@28a34522,
java.lang.Integer 400,
java.lang.String This is the message,
java.lang.Boolean false )
底层异常是:
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
现在,这个类是通过Spring配置的,所以它可能是一些疯狂的代理类并且它变得一团糟,但是有其他人见过这样的东西吗?
(如果您不知道 RESTEasy/JAX-RS 在做什么,基本上容器 (RESTEasy) 会在具有这些注释的类上查找方法,然后在命中某些 URL 端点时调用它们)
Trying to implement a JAX-RS resource in Scala. My Java version of this has the following type signature:
@GET
@Path(value="echoold")
@Produces("application/json")
public Map<String,Object> get(
@QueryParam("param") String param,
@QueryParam("asOf") @DefaultValue(NOW) DateWrapper asOf,
@QueryParam("httpError") @DefaultValue("200") int httpError,
@QueryParam("httpErrorMessage") @DefaultValue("") String httpErrorMessage,
@QueryParam("fail") @DefaultValue("false") boolean fail) {
The Scala version is thus:
@GET
@Path(value="echo")
@Produces(Array("application/json"))
def get() = {
@QueryParam("param") param:String,
@QueryParam("asOf") @DefaultValue(NOW) asOf:DateWrapper,
@QueryParam("httpError") @DefaultValue("200") httpError:java.lang.Integer,
@QueryParam("httpErrorMessage") @DefaultValue("") httpErrorMessage:String,
@QueryParam("fail") @DefaultValue("false") fail:java.lang.Boolean):java.util.Map[String,Object] = {
When I start up my application, I get this strange error from RESTEasy (which I've formatted for readability):
org.jboss.resteasy.spi.InternalServerErrorException:
Bad arguments passed to
public java.util.Map opower.api.endpoint.echo.Echo.get(java.lang.String,
opower.api.support.DateWrapper,
java.lang.Integer,
java.lang.String,
java.lang.Boolean)
( java.lang.String someValue,
opower.api.support.DateWrapper opower.api.support.DateWrapper@28a34522,
java.lang.Integer 400,
java.lang.String This is the message,
java.lang.Boolean false )
The underlying exception is:
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
Now, this class is configured via Spring, so it could be some crazy proxy class and it's getting messed up, but has anyone else seen something like this?
(If you don't know what RESTEasy/JAX-RS is doing, basically the container (RESTEasy) finds methods on classes that have those annotations on them, and then calls them when certain URL endpoints are hit)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对 Spring/Scala 和 @Transactional 方法注释也有同样的看法。
需要更改 proxy-target-class 中
proxy-target-class 的默认值为 false。它需要类路径中的 cglib。
我想 mode="acpectj" 也可能有效(没有尝试)
I had the same with Spring/Scala and @Transactional method annotation.
needed to change proxy-target-class in
Default value for proxy-target-class is false. It requires cglib in classpath.
I guess mode="acpectj" might also work (didn't try)