gpt4 book ai didi

java - @Transactional 和 GenericApplicationContext 不能一起工作

转载 作者:行者123 更新时间:2023-11-29 09:09:14 24 4
gpt4 key购买 nike

我正在通过注解使用@Transactional 和事务管理(tx:annotation-driven...)。我在使用 GenericApplicationContext 创建应用程序上下文并从中获取一些 bean 时遇到问题:

GenericApplicationContext ctx = new GenericApplicationContext();

// Load beans definitions
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
xmlReader.loadBeanDefinitions(new ClassPathResource(CONTEXT_PATH));

// Register the datasource
ctx.getBeanFactory().registerSingleton(CONTEXT_DATASOURCE_BEAN_NAME, dataSource);

// Get the service
ServiceInterface service = (ServiceInterface) ctx.getBean("service");

我有 ServiceInterface 的实例,但我想要包含有关事务的信息的代理。

你能解释一下我错过了什么吗?

最佳答案

需要在调用ctx.getBean()之前调用ctx.refresh()。然后将调用 BeanPostProcessors。

关于java - @Transactional 和 GenericApplicationContext 不能一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13246469/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com