Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Separate the pointcut and aspect(advice), and allow user to override them

See original GitHub issue

Issue Description


We have faced a problem with proxying a @Component that has final methods.
Since CGLIB cannot proxy the final methods (final classes was handled by #188), it produces a log like this:

org.springframework.aop.framework.CglibAopProxy@263 - Unable to proxy interface-implementing method [public final void com.example.Foo.execute(com.example.Bar)] because it is marked as final: Consider using interface-based JDK proxies instead!

Then, the component was not properly dependency injected and failed with NPE at runtime.

The underlying problem is that the SpringComponentAspect and its friends are too generalized to grab many of the application’s beans. Yet, there is no control available to users.

We want to have a control for excluding certain classes or packages for proxying. Or, maybe proxy only the specific set of beans.

One way is to override the aspect bean(e.g. SpringComponentAspect). However, since it is an aspect that contains both the pointcuts and the proxy logic(advice), the overriding custom bean needs to copy/paste the advice from the original bean if I were to change only the pointcut. This is not an ideal approach.

I would like to suggest, rather than using Aspect, use the underlying spring infrastructure for the AOP. Since chaos-monkey-spring-boot is a library, it is preferable to provide a flexible approach rather than an aspect for creating proxies.

The DefaultAdvisorAutoProxyCreator allows dynamically creating proxies by taking advisors.

So, for example with sudo code:

// just a marker interface for the advisor to the component classes
public interface ComponentAdvisor implements Advisor {

// just a marker interface for the advice to the component classes
public interface ComponentAdvice implements Advice {
public ComponentAdvice componentAdvice() {
  // the advice logic for @Component beans. e.g. introduction/interceptor

public ComponentAdvisor componentAdvisor(ObjectProvider<ComponentAdvice> advices) {
   // provide default pointcut for @Component beans

public DefaultAdvisorAutoProxyCreator componentProxyCreator(ObjectProvider<ComponentAdvisor> advisors) {
  // create proxy creator based on the advisors for @Component beans

This way, since these beans are @ConditionalOnMissingBean, the user can provide own implementation to override the default ones independently.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

F43nd1rcommented, Jan 24, 2022

@ttddyy bean watchers and watchCustomServices are two separate things. Usechaos.monkey.watcher.beans instead.

manishrathi4commented, Mar 7, 2022

I am facing the same issue - “Could not generate CGLIB subclass of class xxxxx” and application doesn’t boot-up. Happens for a class with private or final methods. Can’t change the code as these classes are part of third-party libraries.

Is this being fixed in the upcoming version of the framework? Any workaround?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chapter 6. Aspect Oriented Programming with Spring
Pointcuts enable advice to be targeted independently of the Object-Oriented hierarchy. For example, an around advice providing declarative transaction ...
Read more >
Spring AOP Example Tutorial - Aspect, Advice, Pointcut ...
After Throwing Advice: This advice gets executed only when join point method throws exception, we can use it to rollback the transaction ...
Read more >
AspectJ How to override an advice - java - Stack Overflow
In my application I need to override the logic under the given advice. How can I achive this? I tried to provide my...
Read more >
Combine and Reuse pointcut expressions in Spring AOP
In this tutorial, you will learn to combine and reuse multiple Pointcut expressions in Spring AOP. We have only discussed a glimpse of...
Read more >
Spring aop aspectJ pointcut expression examples
In this tutorial, I am listing down some examples which will help you to write pointcut expressions to match any kind of method...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found