Spring AOP 切 dwr的问题

发布于 2021-11-14 13:18:29 字数 314 浏览 358 评论 8

我想切一下dwr.jar中的一个类,用来将前台传入给dwr的参数打印出来。

请问这种需求spring aop能实现么,我试的时候,会出没有加bean的错误,也就是spring-aop只能对beans中的bean进行切面?而不能切外部的类,而必须加到bean中?

而且我实验的时候,spring-aop中配置好了的切点,只有通过spring的getBean引入(或类似)的方法引入的对象才能触发切点。

这一点太不灵活啦。

有高手能做来不。

另外,有通过其它方法实现对jar包中的某个类(没有源代码)进行监控的么?

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

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

发布评论

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

评论(8

眼眸里的那抹悲凉 2021-11-21 10:39:02

然后怎么切.JSP编译后产生的类?

执手闯天涯 2021-11-21 10:38:52

这里有BUG了。。。。。。。。。。。。。。。。好像我从其它复制过来的html中的样式没有过滤完。。。。

@红薯

 

温柔少女心 2021-11-21 10:38:51

hzwamdy commented on
DWR-161 (dwr doesn't support spring with AOP) saying:

I had solove this problem,
< aop:aspectj-autoproxy proxy-target-class="true" expose-proxy="true"></aop:aspectj-autoproxy>
if i don't set the arg expose-proxy,We only can call the method defined in his interfact,we can't user the implements class method.so just add expose-proxy ="true"

緦唸λ蓇 2021-11-21 10:34:46

Tried the issue with @Transactional annotation. Everything was solved using <aop:scoped-proxy />. Here's a complete example:

<tx:annotation-driven />

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="autodetectTransactionManager" value="true" />
        <property name="allowCustomIsolationLevels" value="true" />
< /bean>

<bean id="trcalc" class="com.internna.dwr.sample.RemotedTransactionalImpl">
<dwr:remote javascript="TransactionalCalculator">
<dwr:include method="add"/>
</dwr:remote>
<aop:scoped-proxy />
< /bean>

<aop:aspectj-autoproxy proxy-target-class="false" />

I will update the docs to mention this use case.

If the solution doesn't work for other kind of aspects please reopen and attach a sample project.

顾忌 2021-11-21 10:32:46

spring的代理实现分2种情况:1.如果被代理类实现了一个或多个接口,此时使用jdk自带的代理类也就是"java.lang.reflect.Proxy"来生成代理类,此时当我们从bean工厂取出这个bean时(即使用getBean(**)方法)得到的bean并不是原来定义的类的对象,而是被代理后的对象,这个对象实现了被代理类所实现的接口,所以可以被当作"接口实例"对待.2.当被代理没有实现任何接口,此时使用cglib来生成代理类,这个代理类是被代理类的子类,所以可以被当作定义时的类的对象对待.

你出现这种情况很可能是因为对象已经被代理,而程序中没有用代理后正确的类型来接收这个代理对象造成的.

无边思念无边月 2021-11-21 10:03:19

注解 也是算配置的吧,用注解和XML我都不关心。 我想要通过某一配置,让一个类如User类,所有对user的方法进行访问的,都记录下来,不论user的对象是通过spring.getBean,或是@Resource,亦或 new User() 前两种方式都能达到,但如何对 new User()产生的对象进行监控呢?AspectJ能做到为何Spring做不到?

爱的那么颓废 2021-11-21 05:40:53

你可以讲Aspectj与Spring结合着来用么~

各自安好 2021-11-19 23:15:41

加注释~~~

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