How to import spring-config.xml of one project into spring-config.xml of another project?
<import resource="classpath:spring-config.xml" />
Reference:
- Composing XML-based configuration
metadata - Resources (here the
classpath:
part is explained)
Importing a spring config file via EL in spring XML
I am not sure, but it could work if you build the path completly in EL:
<import resource="#{'../core/'.concat(systemProperties['test.demo.enable'] eq 'true'?'XXXX':'YYYY').concat('/my-context.xml')}" />
It works in one of my spring security intercept URL definition, but i have not testet it with your case.
how to reference a bean of another xml file in spring
You have a couple of options:
Import
<import resource="classpath:config/spring/that-other-xml-conf.xml"/>
<bean id="yourCoolBean" class="org.jdong.MyCoolBean">
<property name="anotherBean" ref="thatOtherBean"/>
</bean>
Include in the ApplicationContext
Construction
Make both files a part of your ApplicationContext
when you create it => then no import is needed.
For example if you need it during testing:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath:META-INF/conf/spring/this-xml-conf.xml",
"classpath:META-INF/conf/spring/that-other-xml-conf.xml" })
public class CleverMoneyMakingBusinessServiceIntegrationTest {...}
In case it is a web app, you'd do it in web.xml
:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/conf/spring/this-xml-conf.xml</param-value>
<param-value>WEB-INF/conf/spring/that-other-xml-conf.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
If it is a stand alone app, library, etc.. you would load your ApplicationContext
as:
new ClassPathXmlApplicationContext(
new String[] { "classpath:META-INF/conf/spring/this-xml-conf.xml",
"classpath:META-INF/conf/spring/that-other-xml-conf.xml" } );
How to import spring-context from one sub-module to another sub-module in maven project?
Simply add this to the child xml document
<import resource="classpath:second-config.xml" />
How to import Java-config class into XML-config so that both contexts have beans?
This actually ended up being fairly simple. To get a Java-config bean definition into the xml-config, simply define the Java-config class as a bean within the XML-config. There are no extra jars necessary.
@Configuration
public class SomeJavaConfig {
@bean
... [bean definition]
}
inside the XML-config, you define this class as a bean.
<!-- needed to pick up the annotated java-config -->
<context:annotation-config />
<!-- Importing java-config class, which are annotated with @Configuration -->
<bean name="SomeJavaConfig" class="[fully qualified path].SomeJavaConfig" />
The XML-config, which may be part of a different context, now has all the bean definitions defined within the JavaConfig class.
UPDATED - to included Alan Franzoni's comment below in the answer.
Related Topics
Where Should I Put the Log4J.Properties File
Easy Way of Running the Same Junit Test Over and Over
Java: How to Access Methods from Another Class
How to Set Dpi Information in an Image
Variable's Scope in a Switch Case
Java Equivalent of an Openssl Aes Cbc Encryption
A For-Loop to Iterate Over an Enum in Java
Jpa: Unidirectional Many-To-One and Cascading Delete
Read File from Resources Folder in Spring Boot
Jfreechart Series Tool Tip Above Shape Annotation
Integer.Valueof() VS. Integer.Parseint()
Format File Size as Mb, Gb, etc
Difference Between Java.Exe and Javaw.Exe
Compiler Error When Declaring a Variable Inside If Condition and No Curly Braces