Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8988479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:01:04+00:00 2026-06-15T22:01:04+00:00

In my spring controllers, annotated with aspects, I am attempting to remove CGLib proxies

  • 0

In my spring controllers, annotated with aspects, I am attempting to remove CGLib proxies and replace them with JDK dynamic proxies. I know that Spring AOP uses CGLib when the class does not implement an interface, since JDK dynamic proxies work only on interfaces. I also realize that annotations need to be present on both the interface and the implementing class. However, the problem I am running into is that the controller no longer shows up as a bean with a JDK proxy.

My controller bean is scanned for like such:

<context:annotation-config/>
<context:component-scan base-package="com.package.name"/>

This works, but controller shows up as CGLibController$$EnhancerByCGLIB$$5f0b2287:

package com.package.name;
@Controller
public class CGLibController {
  @AOP_Aspect
  @RequestMapping("some_url")
  public void foo();
}

//in a bean post processor
//in postProcessAfterInitialization(Object bean, String beanName)
  Controller controller = AnnotationUtils
      .findAnnotation(bean.getClass(), Controller.class);
//controller will exist
//bean name is CGLibController$$EnhancerByCGLIB$$5f0b2287

This doesn’t work, it never gets to the bean post processor:

package com.package.name;
@Controller
public interface ITest{
  @AOP_Aspect
  @RequestMapping("some_url")
  public void foo();
}

package com.package.name;
@Controller
public class DynamicController implements ITest{
  @AOP_Aspect
  @RequestMapping("some_url")
  public void foo();
}

However, if I explicitly create this DynamicController bean as in

<bean class="com.package.name.DynamicController"/>

then when I start up my server the ServletContext complains that

Initialization of bean failed; nested exception is
java.lang.IllegalStateException: Cannot map handler
‘dynamicController’ to URL path [some_url]: There is already handler
of type [class $Proxy61] mapped.

So something is happening here, DynamicController is a dynamic proxy. But I don’t know what else is happening and I know it’s not a bean/controller any longer. I don’t want “controller, aspect, dynamic proxy: pick any two” I want all three. Is this possible somehow?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:01:04+00:00Added an answer on June 15, 2026 at 10:01 pm

    In order to pick up this bean I had to handle it in postProcessBeforeInitialization NOT postProcessAfterInitialization like I was doing before. I surmise that it is proxied when initialized and that messes up something.

    As I hinted at, DynamicController is in fact a JDK dynamic proxy, but the real object behind the proxy is the bean. However! when using proxies and programming to interfaces, the annotations must be on the interface, according to some source which I have lost. Without them on the interface, spring wouldn’t know. AND the annotations must be on the concrete class in order for the bean post processor to work, on the interface alone is not enough.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to use Spring 3' MVC support for annotated controllers in my
I'm new to spring controllers using annotated controllers. Here is my configuration Bean definition
I have Spring 3.0 setup with annotated controllers and it is finding my controller
I'm using Spring MVC and am using aspects to advise my controllers. I'm running
I have a Spring MVC based REST service. My controllers have @ExceptionHandler annotated methods
I have a Spring MVC application using JPA 2. All the controllers are annotated
I've scourged the internet for an example that would use both spring-json and annotated
According to the Spring docs , to enable autodetection of annotated controllers, you add
I'm trying to complete that tutorial with annotated controllers. I got stuck on the
If I have a Spring Controller with two SEPARATE methods, one annotated by: @ExceptionHandler(Exception.class)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.