Wednesday, May 28, 2014

Spring-MVC - WARN [CglibAopProxy] Unable to proxy method


ENVIRONMENT

Spring-MVC using Spring Security.


PROBLEM

Suddenlly, the compiler begins warning:

WARN [CglibAopProxy] (CglibAopProxy.java:...) - Unable to proxy method [public final void org.springframework.web.servlet.mvc.AbstractController.setSynchronizeOnSession(boolean)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.

SOLUTION

First it was commented the annotation:
  @PreAuthorize("permitAll")
on the Controller class.

Recompiled and the warns disappeared.
So, the problem comes from the procedure triggered by this annotation.

To fix, it was taken off the following attribute from "security:global-method-security" element:
  proxy-target-class="true"
on the spring-security.xml configuration.



- spring-security.xml configuration setup:

BEFORE:
    <security:global-method-security pre-post-annotations="enabled" secured-annotations="enabled"
        jsr250-annotations="enabled" proxy-target-class="true">
    </security:global-method-security>
AFTER:
    <security:global-method-security pre-post-annotations="enabled" secured-annotations="enabled"
        jsr250-annotations="enabled" >
    </security:global-method-security>

COMMENT

The proxy-target-class attribute enabled (proxy-target-class="true") forces the use of CGLIB proxying (for example, to proxy every method defined for the target object, not just those implemented by its interfaces).
However, there are some issues to consider, like the final methods that cannot be advised, as they cannot be overriden.
See more at Spring AOP documentation .



FULL WARN MESSAGES:
  2014-05-28 14:18:26,148  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.web.servlet.mvc.AbstractController.setSynchronizeOnSession(boolean)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,150  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final boolean org.springframework.web.servlet.mvc.AbstractController.isSynchronizeOnSession()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,150  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.web.servlet.support.WebContentGenerator.setSupportedMethods(java.lang.String[])] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,151  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final java.lang.String[] org.springframework.web.servlet.support.WebContentGenerator.getSupportedMethods()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,151  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.web.servlet.support.WebContentGenerator.setRequireSession(boolean)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,152  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final boolean org.springframework.web.servlet.support.WebContentGenerator.isRequireSession()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,152  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.web.servlet.support.WebContentGenerator.setUseExpiresHeader(boolean)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,152  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final boolean org.springframework.web.servlet.support.WebContentGenerator.isUseExpiresHeader()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,153  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.web.servlet.support.WebContentGenerator.setUseCacheControlHeader(boolean)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,153  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final boolean org.springframework.web.servlet.support.WebContentGenerator.isUseCacheControlHeader()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,153  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.web.servlet.support.WebContentGenerator.setUseCacheControlNoStore(boolean)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,154  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final boolean org.springframework.web.servlet.support.WebContentGenerator.isUseCacheControlNoStore()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,154  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.web.servlet.support.WebContentGenerator.setCacheSeconds(int)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,154  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final int org.springframework.web.servlet.support.WebContentGenerator.getCacheSeconds()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,155  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.web.context.support.WebApplicationObjectSupport.setServletContext(javax.servlet.ServletContext)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,155  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final void org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(org.springframework.context.ApplicationContext) throws org.springframework.beans.BeansException] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
  2014-05-28 14:18:26,155  WARN [CglibAopProxy] (CglibAopProxy.java:263) - Unable to proxy method [public final org.springframework.context.ApplicationContext org.springframework.context.support.ApplicationObjectSupport.getApplicationContext() throws java.lang.IllegalStateException] because it is final: All calls to this method via a proxy will be routed directly to the proxy.



1 comment:

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...