Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 212
Robert M. Avatar asked Jun 23 '11 21:06

Robert M.


People also ask

What is a proxy object and what are the two different types of proxies spring can create?

Spring AOP is proxy based. Spring used two types of proxy strategy one is JDK dynamic proxy and other one is CGLIB proxy. JDK dynamic proxy is available with the JDK. It can be only proxy by interface so target class needs to implement interface.

How to create a proxy object in Java?

We create an instance of a proxy class for the specified interface that dispatches method invocations to the specified invocation handler, using newProxyInstance(ClassLoader loader, Class<?>[] interfaces, InvocationHandler h) API method of Proxy. Then we invoke the method of the object.

What is a proxy method Java?

Proxy is a structural design pattern that provides an object that acts as a substitute for a real service object used by a client. A proxy receives client requests, does some work (access control, caching, etc.) and then passes the request to a service object.

How Java dynamic proxy works?

Dynamic proxies allow one single class with one single method to service multiple method calls to arbitrary classes with an arbitrary number of methods. A dynamic proxy can be thought of as a kind of Facade, but one that can pretend to be an implementation of any interface.


1 Answers

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

like image 88
Ondrej Bozek Avatar answered Nov 15 '22 19:11

Ondrej Bozek