exposeProxy = true not in effect

See original GitHub issue

Sorry, my English is not very good.

describe: I use @EnableAspectJAutoProxy(exposeProxy = true),but I can not get the current AOP proxy by AopContex.currentProxy().

environment: Spring Boot (2.1.4.RELEASE).

There are only two classes of this project:

@SpringBootApplication
@EnableAsync
@EnableAspectJAutoProxy(exposeProxy = true)
public class DemoTest2Application {

	public static void main(String[] args) {
		SpringApplication.run(DemoTest2Application.class, args);
	}
}
@Controller
public class EmailController {

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    @ResponseBody
    public Object asyncCall() throws InterruptedException {
        System.out.println("before....");
        ((EmailController) AopContext.currentProxy()).testAsyncTask();
        System.out.println("after....");
        return "OK";
    }


    @Async
    public void testAsyncTask() throws InterruptedException {
        Thread.sleep(10000);
        System.out.println("异步任务执行完成!");
    }
    }

when I request “localhost:8080/test” .I get exception:

java.lang.IllegalStateException: Cannot find current proxy: Set 'exposeProxy' property on Advised to 'true' to make it available.
	at org.springframework.aop.framework.AopContext.currentProxy(AopContext.java:69) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]

Looking through all kinds of documents, I don’t know where I was wrong.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
IFT8commented, Jun 25, 2019
    @Resource
    private AsyncAnnotationBeanPostProcessor asyncAdvisor;

    @PostConstruct
    private void init(){
        asyncAdvisor.setExposeProxy(true);
    }
2reactions
yarnpingcommented, Dec 5, 2019

this works for me, set the property manually

@Component
public class AsyncBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        BeanDefinition beanDefinition = beanFactory.getBeanDefinition(org.springframework.scheduling.config.TaskManagementConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME);
        beanDefinition.getPropertyValues().add("exposeProxy", true);
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using proxy-target-class="true" with Spring beans
This behavior is not exhibited when using JDK proxies. ... are usually only assignments taking place and no real logic is implemented in...
Read more >
9.5 Using the ProxyFactoryBean to create AOP proxies - Spring
exposeProxy : determines whether or not the current proxy should be exposed in ... property is set to true will cause CGLIB-based proxying...
Read more >
6 Spring Transaction Failure Scenarios that Everyone Has ...
Use the real class instead of the proxy class when doInsert() calling, so the transaction will fail. The solution can be to directly...
Read more >
cannot find current proxy: set 'exposeproxy' property on advised to ...
测试前请确保开启了(exposeProxy = true),此参数暴露代理对象,否则AopContext. ... The bean could not be injected as a because it is a JDK dynamic proxy that ...
Read more >
Chapter 12. Aspect Oriented Programming with Spring.NET
NET IoC container does not depend on AOP, meaning you don't need to use AOP if you ... If a target needs to...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found