10

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

Robert M.
  • 1,339
  • 1
  • 12
  • 34
  • You say "Spring wraps these objects in Proxies". How have you configured it to do this? What mechanism? What config? – skaffman Jun 23 '11 at 21:40
  • Well there is no configuration for that, as spring does this by default. This is needed to make things like autowiring of properties without a setter method possible. – Robert M. Jun 23 '11 at 21:55
  • 1
    Spring doesn't do that by default. Something, somewhere, you told it to do that. Autowiring via field injection is done with reflection, not proxies. – skaffman Jun 23 '11 at 21:56
  • Thanks for your answer. What I didn't mention is that I'm using Spring Security, which could be the source of the proxies, as it uses Aspects for method-security. The spring documentation says that a proxy in spring is either a JDK Dynamic proxy or a CGLIB proxy. I also tried to output the bean itself (h:outputText with value="#{customerBean}). This prints the correct Object-toString() Method with the correct class-name and the object identifier. So accessing the bean itself works, but a method such as the getCustomer() method does not. – Robert M. Jun 23 '11 at 22:19
  • Ok now I did some more research and tried to think about where I indirectly configured Proxies. I use DAO objects with @Transactional annotations. According to the documentation, the transaction handling is accomplished with proxies. I additionally had the @Transactional annotation on a method of my bean (i.e. customerBean). I removed this and right now it works. But I guess there is still something going wrong, as a proxy-object should have the same public interface as the wrapped object. – Robert M. Jun 23 '11 at 22:35
  • What have you done, since it worked the last time? – Ralph Jun 24 '11 at 06:52
  • just for testing if the getter is on the Proxy, you can call the getter directly like this : #{customerBean.getCustomer} what does it happens ? – EricParis16 Jun 24 '11 at 13:55
  • Sorry for my late response. @Ralph: This is exactly what I don't understand. I can't really think of something i changed that would affect transations or proxies. @Eric: Right now I removed all the @Transactional annotations from my backing-beans. But it didn't work when i tried to invoke a particular method as the action of a commandButton. The same exception occured, so I guess this answers your question?! – Robert M. Jun 25 '11 at 22:37
  • @Robert M. : Could you please post the code (JSF, Bean, Entity). – Ralph Jun 27 '11 at 07:41

5 Answers5

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

Ondrej Bozek
  • 10,987
  • 7
  • 54
  • 70
2

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

Ondrej Bozek
  • 10,987
  • 7
  • 54
  • 70
  • I'm using Spring 4.3.4, Java 8 and Weblogic 12.2.1.0 and this answer helped me resolve `javax.el.PropertyNotFoundException`. Thank you @ondrej-bozek – Mehdi Javan Dec 17 '17 at 10:49
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.

Steffen
  • 8,033
  • 1
  • 28
  • 34
0

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.

David Polák
  • 1,581
  • 4
  • 18
  • 33
0

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

bora.oren
  • 3,439
  • 3
  • 33
  • 31