How to import spring -config.xml of one project into spring -config.xml of another project?

I have two projects named simple-core-impl and simple-core-web .

Both projects are spring based , and both have the parent name of the simple-core project.

I have simple-impl-config.xml in a simple-core-impl and simple-web-config.xml in simple-impl-config.xml .

I have a bean that has a class: simple service , which has one method that returns the message "hello World" to me.

I want to import simple-impl-config.xml into simple-web-config.xml so that the bean is available in my controller, which is in the simple-core-web project.

simple-core-web project has a simple-core-impl project bank.

So, please tell me, how can I import spring-config.xml one project into spring-config.xml another project so that all the beans of the first are accessible in another project, just by importing?

I do not want to rewrite all the beans.

+65
java spring
Feb 25 '11 at 4:22
source share
5 answers
 <import resource="classpath:spring-config.xml" /> 

Reference:

+98
Feb 25 '11 at 9:05
source share

A slight variation of Sean's answer:

 <import resource="classpath*:spring-config.xml" /> 

With an asterisk for spring, spring -config.xml 'search files anywhere in the classpath.

Another link: Split spring configuration for multiple projects

Spring difference between classpath prefixes

+54
Oct 18 2018-11-18T00:
source share

For some reason, the import suggested by Ricardo did not work for me. I got his work with the following statement:

<import resource="classpath*:/spring-config.xml" />

+8
Apr 16 '13 at 4:26
source share

You must add the jar / war of module B in module A and add the classpath to the new spring-module file. Just add this line

spring -moduleA.xml is the file in module A in the resource folder. By adding this line, it imports the entire bean definition from module A to module B.

MODULE B / spring -moduleB.xml




 import resource="classpath:spring-moduleA.xml"/> <bean id="helloBeanB" class="basic.HelloWorldB"> <property name="name" value="BMVNPrj" /> </bean> 
+1
Nov 12 '13 at 17:40
source share

Here is an example based on annotation:

 @SpringBootApplication @ImportResource({"classpath*:spring-config.xml"}) public class MainApplication { public static void main(String[] args) { SpringApplication.run(MainApplication.class, args); } } 
+1
Sep 13 '17 at 8:47 on
source share



All Articles