[英]How to load spring application context within submodule
I was writing simple app for data deletion in db with some command line interface. 我正在使用一些命令行界面编写用于在db中删除数据的简单应用程序。 As it got bigger, I decided to split it into two maven submodules (one cli, one for db operations).
随着它变得更大,我决定将其分成两个maven子模块(一个cli,一个用于db操作)。 Everything worked properly with one
applicationContext
loaded within Main
method. 使用
Main
方法中加载的一个applicationContext
一切正常运行。
After change, I left (at least I would like to) the spring only in the db module. 更改后,我仅在db模块中保留了(至少我想)弹簧。 This module has one public interface (with four implementations).
该模块具有一个公共接口(具有四个实现)。 If it will be included into other project, I do not want to manually load the application context of that db module in other one (not sure if it is even possible).
如果它将包含在其他项目中,则我不想在其他数据库中手动加载该db模块的应用程序上下文(不确定是否可能)。 I simply want to have a
jar
which could be used on the go - just add to the pom.xml and that's all. 我只想拥有一个可以随时随地使用的
jar
-只需添加到pom.xml中就可以了。 On the other hand I do not know how to initialize this context within submodule. 另一方面,我不知道如何在子模块中初始化此上下文。 Is it possible, or should I ask, is my pattern a good one?
我的模式是否可能(或者应该问)是一个好模式?
I know there exists @ContextConfiguration
annotation, but according to the documentation it is for integration tests. 我知道存在
@ContextConfiguration
批注,但是根据文档,它用于集成测试。
You can always import other configuration files into your current module. 您始终可以将其他配置文件导入当前模块。 That way you can group your contexts according to your business need.
这样,您可以根据业务需要对上下文进行分组。
<beans>
<import resource="classpath*:root-module-context.xml"/>
<bean>.. </bean>
</beans>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.