Java/JSF/Tomcat/Spring - 代理对象与原始对象有不同的方法

发布于 2024-11-16 19:28:43 字数 769 浏览 3 评论 0原文

今天我遇到了这个问题,这确实让我烦恼,因为几乎代码已经可以工作了(即使在恢复到旧版本后也停止工作)。

我正在访问 Facelets 页面上的 Spring-Bean。 Spring 将这些对象包装在代理中以使用方面和其他一些东西。

问题是,当我尝试访问 bean 的属性时遇到异常。例外是这样的:

javax.el.PropertyNotFoundException: /customers.xhtml @23,27 value="#{customerBean.customer}": Property 'customer' not found on type $Proxy88

我确信(!!)存在相应的 getter/setter 方法。 到目前为止我尝试过的事情:

  • 将应用程序部署到另一个 tomcat-installation
  • 清除所有 tomcat-caches、webapp-directory
  • 清理 eclipse-project
  • 使用 javap 检查相应的方法(以及那里的方法/属性)
  • 更改范围bean
  • 更改 bean 的类名
  • 更改 spring bean-id
  • 更改 bean 的serialVersionUID

无论我做什么,该类都未正确包装或未由类加载器正确加载。

有人知道什么会导致这样的问题吗?我不知道还要尝试什么,所以非常感谢您的建议!

提前致谢!

问候, 罗伯特

today I ran into this problem which really bugs me, as almost the code already worked (and stopped working even after reverting to the older version).

I'm accessing a Spring-Bean on a Facelets-Page. Spring wraps these objects in Proxies to use aspects and some other stuff.

The problem is, that I get an exception when trying to access the property of a bean. The exception is something like this:

javax.el.PropertyNotFoundException: /customers.xhtml @23,27 value="#{customerBean.customer}": Property 'customer' not found on type $Proxy88

I know for sure (!!) that the according getter/setter methods are there.
Things i tried so far:

  • Deploy the application to another tomcat-installation
  • Clear all tomcat-caches, the webapp-directory
  • Clean the eclipse-project
  • Check for the according methods using javap (and the methods/properties where there)
  • Change the scope of the bean
  • Change the class name of the bean
  • Change the spring bean-id
  • Change the serialVersionUID of the bean

Whatever I do, the class is somehow not correctly wrapped or not correctly loaded by the class-loader.

Has anybody an idea what could cause a problem like this? I don't know what to try additionally, so any advice is greatly appreciated!

Thanks in advance!

Regards,
Robert

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

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

发布评论

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

评论(5

Hello爱情风 2024-11-23 19:28:43

我还使用 Tomcat 7、JSF 2、Spring 3、Spring Security 3。
我也有同样的问题。改变编织的配置没有帮助。

我的最终解决方案是在 spring 配置中添加一行:

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

Jou need CGLIB on your classpath.
希望这对某人有帮助。 :)

I also use Tomcat 7, JSF 2, Spring 3, Spring Security 3.
I had same problems. Changing configuration of weaving didn't help.

My final solution was to add one line in to spring config:

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

Jou need CGLIB on your classpath.
Hope this helps someone. :)

杀お生予夺 2024-11-23 19:28:43

好的,我找到了如何使用 AspectJ 编织来管理方法安全性。

您需要至少使用 Spring-security 3.0.5,您需要在 spring-security.xml 中使用正确的架构,至少:
http://www.springframework.org/schema/security/spring -security-3.0.5.xsd

您需要添加 spring-security-aspects 作为依赖项:

<dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-aspects</artifactId>             
   <version>3.0.5.RELEASE</version>
</dependency>

您可以将新属性“mode”添加到全局方法安全标记中:

<global-method-security pre-post-annotations="enabled" mode="aspectj"/>

我认为您还必须添加你的标准Spring-configuration.xml,启用AspectJ编织的标签:

<context:load-time-weaver aspectj-weaving="on"/>

并且它也很好地gedrid(删除)aop-proxy标签:

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

另外,最好使用Spring-security 3.1.0,但比你更好还必须至少使用 Spring 3.0.7。

希望这有帮助:)

OK, I found out how to manage method-security using AspectJ weaving.

You need to use at least Spring-security 3.0.5, you need to use right schemas in your spring-security.xml, at least:
http://www.springframework.org/schema/security/spring-security-3.0.5.xsd

You need to add spring-security-aspects as a dependency:

<dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-aspects</artifactId>             
   <version>3.0.5.RELEASE</version>
</dependency>

than you can add new attribute "mode" to your global-method security tag:

<global-method-security pre-post-annotations="enabled" mode="aspectj"/>

I think you also have to add to your standard Spring-configuration.xml, tag which enables AspectJ weaving:

<context:load-time-weaver aspectj-weaving="on"/>

And its also good to ged rid (remove) of the aop-proxy tag:

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

Also it's better to use Spring-security 3.1.0 but than you also have to use at least Spring 3.0.7.

Hope this helps :)

云之铃。 2024-11-23 19:28:43

如果加载时间编织未正确配置,通常会发生这些错误。确保您不仅配置了加载时间编织器,而且还加载了适当的 java 代理,或者应用程序服务器为您执行了该操作。

有关如何配置此环境的更多信息,请参阅 spring 文档,例如 第 7.8.4.6 章环境特定配置。虽然这涵盖了 AOP 的加载时间挥动主题,但对于需要加载时间挥动的 Spring 其他部分来说,它的配置是相同的。

These errors usually occur if the load time weaving isn't properly configured. Make sure that you do not just configure a load time weaver, but that you also load the an appropriate java agent, or that the application server does that for you.

See the spring documentation for more information on how to configure this environment, e.g. chapter 7.8.4.6 Environment-specific configuration. Although, this covers the load time waving topic for AOP, it's the same configuration for other parts of spring that require load time weaving.

羁〃客ぐ 2024-11-23 19:28:43

尝试删除具有 oneToMany 字段的 customerBean 域。

Try to remove customerBean's domains which have got oneToMany fields.

滿滿的愛 2024-11-23 19:28:43

我认为你的 bean 实现了Serialized。我今天遇到了这个问题,可序列化对代理做了一些奇怪的事情,我的方法都无法访问。去掉 Serialized 就可以了。

I think your bean implemented Serializable. I ran into this today, the Serializable does something weird to the proxies, none of my methods were accessible. Get rid of the Serializable and it should work.

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