Java Spring 从另一个项目导入应用程序上下文

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6468195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 06:12:01  来源:igfitidea点击:

Spring import application context from another project

javahibernatespringtransactionsannotations

提问by Michel

I have 2 projects, one of them is included in the other one build path, both of them have his own application context defining his beans.

我有 2 个项目,其中一个包含在另一个构建路径中,它们都有自己的应用程序上下文来定义他的 bean。

I want to manage Global Transactions so I have to have in one application context the import of both of them, but I didn't find the way to do that.

我想管理全局事务,所以我必须在一个应用程序上下文中导入它们,但我没有找到这样做的方法。

It is possible have 2 application context in different project and import one of them to the other.

可以在不同的项目中有 2 个应用程序上下文并将其中一个导入另一个。

If there is no possible which would be the best solution?

如果没有可能,哪个是最好的解决方案?

I have think in become the 2 projects in 1.

我想成为 1 中的 2 个项目。

采纳答案by abalogh

Yes it is possible to import; in one of your appcontext xmls:

是的,可以导入;在您的 appcontext xml 之一中:

<beans>

    <import 
        resource="classpath*:/META-INF/whatever/root/to/otherAppContext.xml" />

    <bean id="beanA" class="..."/>
    <bean id="beanB" class="..."/>

</beans>

回答by Nick

This oldish Spring blog post describes pretty much exactly what you're trying to do.

这篇古老的 Spring 博客文章几乎准确地描述了您想要做什么。

http://blog.springsource.com/2007/06/11/using-a-shared-parent-application-context-in-a-multi-war-spring-application/

http://blog.springsource.com/2007/06/11/using-a-shared-parent-application-context-in-a-multi-war-spring-application/