简体   繁体   中英

How to load spring application context within submodule

I was writing simple app for data deletion in db with some command line interface. As it got bigger, I decided to split it into two maven submodules (one cli, one for db operations). Everything worked properly with one applicationContext loaded within Main method.

After change, I left (at least I would like to) the spring only in the db module. 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). I simply want to have a jar which could be used on the go - just add to the pom.xml and that's all. 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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM