{"action":"created","issue":{"url":"https://api.github.com/repos/spring-projects/spring-boot/issues/2013","labels_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/2013/labels{/name}","comments_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/2013/comments","events_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/2013/events","html_url":"https://github.com/spring-projects/spring-boot/issues/2013","id":50280855,"number":2013,"title":"Annotation AOP cannot run with @EnableAutoConfiguration","user":{"login":"izerui","id":1773233,"avatar_url":"https://avatars.githubusercontent.com/u/1773233?v=3","gravatar_id":"","url":"https://api.github.com/users/izerui","html_url":"https://github.com/izerui","followers_url":"https://api.github.com/users/izerui/followers","following_url":"https://api.github.com/users/izerui/following{/other_user}","gists_url":"https://api.github.com/users/izerui/gists{/gist_id}","starred_url":"https://api.github.com/users/izerui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/izerui/subscriptions","organizations_url":"https://api.github.com/users/izerui/orgs","repos_url":"https://api.github.com/users/izerui/repos","events_url":"https://api.github.com/users/izerui/events{/privacy}","received_events_url":"https://api.github.com/users/izerui/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/spring-projects/spring-boot/labels/waiting-for-feedback","name":"waiting-for-feedback","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2014-11-27T11:21:23Z","updated_at":"2015-04-30T17:06:23Z","closed_at":null,"body":"like this is ok:\r\n\r\n```java\r\n@Around(\"execution(* sample..*Service.*(..))\")\r\npublic Object logServiceAccess(ProceedingJoinPoint joinPoint) throws Throwable {\r\n\tSystem.out.println(\"Completed: \" + joinPoint);\r\n\treturn joinPoint.proceed();\r\n}\r\n```\r\n\r\nbut when use annotation AOP fail:\r\n\r\n```java\r\n@Component\r\n@Aop\r\npublic class HelloWorldService {\r\n......\r\n}\r\n\r\n@Around(\"@target(sample.aop.monitor.Aop)\")\r\npublic Object logAopAnnotation(ProceedingJoinPoint joinPoint) throws Throwable {\r\n\tSystem.out.println(\"Completed 2 : \"+joinPoint);\r\n\treturn joinPoint.proceed();\r\n}\r\n```\r\n\r\nexception:\r\n\r\n```\r\norg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.AutoConfigurationPackages': Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)\r\n\tat org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)\r\n\tat org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706)\r\n\tat org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762)\r\n\tat org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)\r\n\tat org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:320)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:952)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:941)\r\n\tat sample.aop.SampleAopApplication.main(SampleAopApplication.java:46)\r\n\tat sample.aop.SampleAopApplicationTests.testCommandLineOverrides(SampleAopApplicationTests.java:64)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.lang.reflect.Method.invoke(Method.java:606)\r\n\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)\r\n\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\r\n\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)\r\n\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\r\n\tat org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)\r\n\tat org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)\r\n\tat org.springframework.boot.test.OutputCapture$1.evaluate(OutputCapture.java:50)\r\n\tat org.junit.rules.RunRules.evaluate(RunRules.java:20)\r\n\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)\r\n\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)\r\n\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)\r\n\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)\r\n\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)\r\n\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)\r\n\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)\r\n\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)\r\n\tat org.junit.runners.ParentRunner.run(ParentRunner.java:309)\r\n\tat org.junit.runner.JUnitCore.run(JUnitCore.java:160)\r\n\tat com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)\r\n\tat com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)\r\n\tat com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)\r\nCaused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages\r\n\tat org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:212)\r\n\tat org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:109)\r\n\tat org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:496)\r\n\tat org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:381)\r\n\tat org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:341)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:421)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1559)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)\r\n\t... 39 common frames omitted\r\nCaused by: java.lang.IllegalArgumentException: Cannot subclass final class class org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages\r\n\tat org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:446)\r\n\tat org.springframework.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)\r\n\tat org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)\r\n\tat org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)\r\n\tat org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)\r\n\tat org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:317)\r\n\tat org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:57)\r\n\tat org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:202)\r\n\t... 46 common frames omitted\r\n\r\n\r\norg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.AutoConfigurationPackages': Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)\r\n\tat org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)\r\n\tat org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706)\r\n\tat org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762)\r\n\tat org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)\r\n\tat org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:320)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:952)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:941)\r\n\tat sample.aop.SampleAopApplication.main(SampleAopApplication.java:46)\r\n\tat sample.aop.SampleAopApplicationTests.testCommandLineOverrides(SampleAopApplicationTests.java:64)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)\r\n\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\r\n\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)\r\n\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\r\n\tat org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)\r\n\tat org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)\r\n\tat org.springframework.boot.test.OutputCapture$1.evaluate(OutputCapture.java:50)\r\n\tat org.junit.rules.RunRules.evaluate(RunRules.java:20)\r\n\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)\r\n\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)\r\n\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)\r\n\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)\r\n\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)\r\n\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)\r\n\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)\r\n\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)\r\n\tat org.junit.runners.ParentRunner.run(ParentRunner.java:309)\r\n\tat org.junit.runner.JUnitCore.run(JUnitCore.java:160)\r\n\tat com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)\r\nCaused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages\r\n\tat org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:212)\r\n\tat org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:109)\r\n\tat org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:496)\r\n\tat org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:381)\r\n\tat org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:341)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:421)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1559)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)\r\n\t... 39 more\r\nCaused by: java.lang.IllegalArgumentException: Cannot subclass final class class org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages\r\n\tat org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:446)\r\n\tat org.springframework.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)\r\n\tat org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)\r\n\tat org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)\r\n\tat org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)\r\n\tat org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:317)\r\n\tat org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:57)\r\n\tat org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:202)\r\n\t... 46 more\r\n```"},"comment":{"url":"https://api.github.com/repos/spring-projects/spring-boot/issues/comments/97882957","html_url":"https://github.com/spring-projects/spring-boot/issues/2013#issuecomment-97882957","issue_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/2013","id":97882957,"user":{"login":"wilkinsona","id":914682,"avatar_url":"https://avatars.githubusercontent.com/u/914682?v=3","gravatar_id":"","url":"https://api.github.com/users/wilkinsona","html_url":"https://github.com/wilkinsona","followers_url":"https://api.github.com/users/wilkinsona/followers","following_url":"https://api.github.com/users/wilkinsona/following{/other_user}","gists_url":"https://api.github.com/users/wilkinsona/gists{/gist_id}","starred_url":"https://api.github.com/users/wilkinsona/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wilkinsona/subscriptions","organizations_url":"https://api.github.com/users/wilkinsona/orgs","repos_url":"https://api.github.com/users/wilkinsona/repos","events_url":"https://api.github.com/users/wilkinsona/events{/privacy}","received_events_url":"https://api.github.com/users/wilkinsona/received_events","type":"User","site_admin":false},"created_at":"2015-04-30T17:06:23Z","updated_at":"2015-04-30T17:06:23Z","body":"Your `@Around` advice is very broad as it's targeting anything that's annotated with `@Profiler`. That causes Spring Framework's AOP infrastructure to try to proxy every bean in the application context. I'd recommend narrowing the scope of the advice by requiring the class to be in a particular package, for example:\r\n\r\n    @Around(\"execution(* aop..*(..)) && target(aop.Profiler)\")\r\n\r\nYou're also not using the `ProceedingJoinPoint`. You need to call `proceed` on it and return its result:\r\n\r\n```\r\n@Around(\"execution(* aop..*(..)) && target(aop.Profiler)\")\r\npublic Object around(ProceedingJoinPoint joinPoint) throws Throwable {\r\n    System.out.println(\"Before proceeding\");\r\n    Object result = joinPoint.proceed();\r\n    System.out.println(\"After proceeding. Result: \" + result);\r\n    return result;\r\n}\r\n```\r\n"}}