我正在使用Spring MVC和Virgo Webserver在Osgi应用程序上开发一个模块.
在我的模块上,我有一个Controller,它可以访问Manager,它有一个负责处理报告生成的处理程序列表.
一切都很好,直到我不得不从外部服务调用事务方法.由于我的所有类都不是事务性的,因此我必须添加对转换管理器和注释驱动的引用.然后,我的经理停止接到通知.
我知道当使用注释驱动时,我的所有bean必须实现一个公共接口才能使代理机制起作用.据我所知,所有课程都是(其中一个不是,但后来我改了).
我的配置文件是:
束-context.xml中:
spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
fig />
figDao" class="reportmodule.repository.impl.ReportConfigurationHibernateDAOImpl"/>
sgiChangeReportHandler" class="reportmodule.osgi.impl.OsgiChangeReportHandlerImpl"/>
我的bundle-osgi.xml如下:
sgi="http://www.springframework.org/schema/osgi"
xmlns:osgi-compendium="http://www.springframework.org/schema/osgi-compendium"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd
http://www.springframework.org/schema/osgi-compendium
http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium-1.2.xsd">
sgi:reference id="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager" />
sgi:reference id="sessionFactory" interface="org.hibernate.SessionFactory" />
sgi:reference id="smaCoreUtilService" interface="core.util.service.SmaCoreUtilService" />
sgi:service ref="reportControllerHandlerMapping"
interface="org.springframework.web.servlet.HandlerMapping"
context-class-loader="service-provider"
auto-export="interfaces"/>
sgi:service interface="reportmodule.api.manager.ReportManager" ref="reportManager" auto-export="interfaces"/>
sgi:service interface="reportmodule.api.manager.ReportHandler" ref="mvpepReportHandler" auto-export="interfaces"/>
sgi:service interface="reportmodule.repository.ReportConfigurationDAO" ref="reportConfigDao" auto-export="interfaces"/>
sgi:service interface="reportmodule.osgi.OsgiChangeReportHandler" ref="osgiChangeReportHandler" auto-export="interfaces"/>
sgi:list cardinality="0..N" id="reportHandler" interface="reportmodule.api.manager.ReportHandler" greedy-proxying="true">
sgi:listener ref="osgiChangeReportHandler" bind-method="register" unbind-method="unregister"/>
sgi:list>
因此,在发布所有服务之后,调用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 ArrayListaram reportConfigurationDAO the reportConfigurationDAO to set
*/
@Autowired
public void setReportConfigurationDAO(ReportConfigurationDAO reportConfigurationDAO) {
this.reportConfigurationDAO = reportConfigurationDAO;
}
@Override
@Transactional
public InputStream gerarRelatorio(ReportRequest repoReq) throws NegocioException {
// Generates the report...
}
/* (non-Javadoc)
* @see reportmodule.api.manager.ReportManager#addReportHandler(reportmodule.api.manager.ReportHandler)
*/
@Override
public void addReportHandler(ReportHandler handler) {
if (handler != null) {
this.reportHandlers.add(handler);
}
}
/* (non-Javadoc)
* @see reportmodule.api.manager.ReportManager#removeReportHandler(reportmodule.api.manager.ReportHandler)
*/
@Override
public void removeReportHandler(ReportHandler handler) {
if (handler != null) {
this.reportHandlers.remove(handler);
}
}
}
我必须强调,当我从bundle-context.xml文件中删除tx:annotation-driven标记时,一切正常(处理程序在启动期间正确添加到列表中).
那么,我在这里错过了什么?
正如您在上面的代码中看到的那样,我通过XML和Annotation定义了bean,因此每个bean都在运行时被复制.然后,当我添加tx:annotation-driven标签时,应用程序开始拦截错误的bean.它确实是在通知一个豆子,而是一个孤儿豆.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。