Java/JSF/Tomcat/Spring - Proxy-Object has different methods than original object

泪湿孤枕 提交于 2019-12-10 02:48:18

问题


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


回答1:


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.




回答2:


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. :)




回答3:


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 :)




回答4:


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




回答5:


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.



来源:https://stackoverflow.com/questions/6460599/java-jsf-tomcat-spring-proxy-object-has-different-methods-than-original-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!