开发者

How can I programmatically create a transactional proxy?

I created a bean instance with

Type instance = new Type(); 

and autowired it using

ctx.getAutowireCapableBeanFactory().autowireBean(instance);

The beans run method is executed by a ThreadPoolTaskExecuter and is annotated with the @Transactional annotation which has no effect in this case. Since lazy loading problems occur. I need a transaction here.

How can I create a transactional proxy and wrap my instance?

Is there a way other than using transaction-man开发者_如何转开发ager manually?


You should get the correct proxy if you apply BeanPostProcessors from the context:

instance = ctx.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(instance);


You can certainly create a PlatformTransactionManager subclass manually and use its methods to create and commit or rollback transactions.

If you want to proxy an object, the class you probably want is org.springframework.transaction.interceptor.TransactionProxyFactoryBean. Setup an instance of that and call getObject() to get your proxied class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜