简体   繁体   English

如何在子模块中加载spring应用程序上下文

[英]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.

相关问题 如何加载Spring Application Context - How to load Spring Application Context 如何使用Cucumber runner加载Spring应用程序上下文 - How to load Spring application context with Cucumber runner 如何加载应用程序上下文以使用 JUnit 4 测试 Spring 应用程序? - How to load application context for testing Spring application with JUnit 4? Spring Application Context Load Order - Spring Application Context Load Order 如何在Spring 2.5中从字符串加载应用程序上下文? - How to load application context from string in Spring 2.5? 如何在Spring 4.1.0应用程序上下文中加载系统属性和自定义资源? - How to load system properties and custom resources in the Spring 4.1.0 application context? 如何将bean加载到Spring MVC的应用程序上下文中? - How do you load a bean into Spring MVC's application context? Spring如何在不带OSGi的情况下通过Spring动态加载具有应用程序上下文的jar文件? - How to dynamically load jar files with application context by Spring (with no OSGi)? 如何在Tomcat / Java / Spring应用程序中将文件作为上下文参数值加载? - How to load a file as a context parameter value in a Tomcat/Java/Spring application? 弹簧应用程序上下文中的“回收”名称 - “Recycling” names within a spring application context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM