在 Spring 中,为什么 POJO 上的 CGLib 的行号会丢失?

发布于 2024-11-18 02:09:41 字数 1083 浏览 3 评论 0原文

Spring MVC Web 应用程序:

我有一个不带行号的堆栈跟踪(显示在底部)。

我认为这是由于 CGLib 在控制器上运行所致。但这对我来说很奇怪,实际的异常发生在 ServerBatchRemoteRequestAcceptor 中,这是一个未注入的 pojo,而不是控制器。它仅在 Controller 对象中创建。

示例:

@Controller
class MyController {
    MyPojo pojo = new MyPojo();

    @RequestMapping("myaction")
    public void doMyAction(){
        pojo.methodToCauseNullPointerException()
    }
}

java.lang.NullPointerException
at mycommons.services.batchremoteprocessor.ServerBatchRemoteRequestAcceptor.acceptRequest(Unknown Source)
at com.proxyandvpn.web.controllers.RESTServicesController.handleGenericClientRequest(Unknown Source)
at com.proxyandvpn.web.controllers.RESTServicesController$$FastClassByCGLIB$$dff24f0f.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688)

有人可以向我解释这种行为吗?由于 CGLib,我的控制器下的每个调用都会没有行号吗?

我应该将控制器写入接口以便使用代理吗?这正常吗?我这样做是为了服务,但将控制器作为简单的 POJO 来完成。

Spring MVC web app:

I have a stack trace w/o line numbers (shown at bottom).

I presume that this is due to CGLib running on the controller. But this is odd to me, the actual exception occurs in ServerBatchRemoteRequestAcceptor, a pojo that is not injected, not the controller. It is only created in the Controller object.

Example:

@Controller
class MyController {
    MyPojo pojo = new MyPojo();

    @RequestMapping("myaction")
    public void doMyAction(){
        pojo.methodToCauseNullPointerException()
    }
}

java.lang.NullPointerException
at mycommons.services.batchremoteprocessor.ServerBatchRemoteRequestAcceptor.acceptRequest(Unknown Source)
at com.proxyandvpn.web.controllers.RESTServicesController.handleGenericClientRequest(Unknown Source)
at com.proxyandvpn.web.controllers.RESTServicesController$FastClassByCGLIB$dff24f0f.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688)

Can someone explain this behavior to me? Will every call under my Controllers be without line numbers due to CGLib?

Should I write my Controllers to an interface so that proxies are used? Is that normal? I do it for services, but have done the controllers as simple POJOs.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

_蜘蛛 2024-11-25 02:09:41

Spring 使用 CGLIB 生成位于某些组件/控制器前面的代理对象。对这些组件的调用通过 CGLIB 代理传递。这些代理是在运行时生成的,没有源代码,因此它们没有行号。

不过,您几乎可以忽略提到 CGLIB 的堆栈跟踪行 - 假装它们不存在,它们应该是透明的。

在堆栈跟踪中,对 RESTServicesController.handleGenericClientRequest 的调用已被代理,但调用仍在到达那里。 NPE 发生在 ServerBatchRemoteRequestAcceptor 内,该接收器是从 RESTServicesController.handleGenericClientRequest 调用的。

但是,您发布的源代码与堆栈跟踪无关,因此很难评论它发生的原因。

Spring uses CGLIB to generate proxy objects that sit in front of some of your components/controllers. Calls to those components pass through the CGLIB proxies. These proxies are generated a runtime, with no source code, so they have no line numbers.

You can pretty much ignore the stack trace lines that mention CGLIB, though - pretend they're not there, they should be transparent.

In your stack trace, the call to RESTServicesController.handleGenericClientRequest has been proxied, but the call is still getting there. The NPE is occurring within ServerBatchRemoteRequestAcceptor, which is being invoked from RESTServicesController.handleGenericClientRequest.

However, the source code you posted has no relation to the stack trace, so it's hard to comment as to why it happened.

雪花飘飘的天空 2024-11-25 02:09:41

我将添加这个答案,因为我现在知道了我的问题。当你不理解问题时,通常是我没有问正确的问题。

我最近转而使用 ANT 构建而不是 Eclipse 构建器。我没有意识到我需要在任务中明确启用调试信息。当我看到 CGLib 出现这个错误时,我无意中责怪了它,但所需要的只是 ANT 构建修改。

I will add to this answer as I now know my problem. As is common when you don't understand a problem, I didn't ask the right question.

I had recently switched to using ANT builds instead of Eclipse builder. I didn't realize that I needed to expressly enable debugging information in the task. I unwittingly blamed CGLib when I saw it sitting in front of this error, but all that was necessary was an ANT build modification.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文