加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

spring – 使用tx:annotation-driven可以防止自动装配bean

发布时间:2020-12-15 01:35:22 所属栏目:大数据 来源:网络整理
导读:我正在使用Spring MVC和Virgo Webserver在OSGi应用程序上开发一个模块. 在我的模块上,我有一个Controller,它可以访问Manager,它有一个负责处理报告生成的处理程序列表. 一切都很好,直到我不得不从外部服务调用事务方法.由于我的所有类都不是事务性的,因此我

我正在使用Spring MVC和Virgo Webserver在OSGi应用程序上开发一个模块.

在我的模块上,我有一个Controller,它可以访问Manager,它有一个负责处理报告生成的处理程序列表.

一切都很好,直到我不得不从外部服务调用事务方法.由于我的所有类都不是事务性的,因此我必须添加对转换管理器和注释驱动的引用.然后,我的经理停止接到通知.

我知道当使用注释驱动时,我的所有bean必须实现一个公共接口才能使代理机制起作用.据我所知,所有课程都是(其中一个不是,但后来我改了).

我的配置文件是:

束-context.xml中:

我的bundle-osgi.xml如下:

因此,在发布所有服务之后,调用oSGIChangeReportHandler.register(我能够对其进行调整):

@Service(value="oSGIChangeReportHandler")
public class OSGIChangeReportHandlerImpl implements OSGIChangeReportHandler {

    private ReportManager reportManager;

    /**
     * @param reportManager the reportManager to set
     */
    @Autowired
    public void setReportManager(ReportManager reportManager) {
        this.reportManager = reportManager;
    }

    @SuppressWarnings("rawtypes")
    public void register(ReportHandler reportHandler,Map properties) {
        reportManager.addReportHandler(reportHandler);
    }

    @SuppressWarnings("rawtypes")
    public void unregister(ReportHandler reportHandler,Map properties) {
        reportManager.removeReportHandler(reportHandler);
    }


}

虽然调试器在register方法上显示了reportManager和reportHandler的Proxies,但调试器不会在ReportManagerImpl.addReportHandler方法上停止:

@Service(value="reportManager")
@Transactional(propagation = Propagation.MANDATORY,rollbackFor = Exception.class)
public class ReportManagerImpl implements ReportManager {

    private ReportConfigurationDAO reportConfigurationDAO;

    private ArrayList

我必须强调,当我从bundle-context.xml文件中删除tx:annotation-driven标记时,一切正常(处理程序在启动期间正确添加到列表中).

那么,我在这里错过了什么?

最佳答案
问题解决了!

正如您在上面的代码中看到的那样,我通过XML和Annotation定义了bean,因此每个bean都在运行时被复制.然后,当我添加tx:annotation-driven标签时,应用程序开始拦截错误的bean.它确实是在通知一个豆子,而是一个孤儿豆.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读