user3375659
user3375659

Reputation: 65

Loading an ApplicationContext File from AnnotationConfigWebApplicationContext

I have an application using Java config in Spring MVC. I have a WebAppInitializer and on Startup method I am using AnnotationConfigWebApplicationContext to load the rootContext.

From the Startup method of WebAppInitializer, how do I load a Client Jar that has applicationContext.xml file. Basically I am looking at something like this.

AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(MyAppContext.class);

Looking at something Like this.

rootContext.register(applicationContext.xml);

Upvotes: 0

Views: 662

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279930

The whole point of AnnotationConfigWebApplicationContext is to have an ApplicationContext configured through annotations. So there is no direct method for parsing and importing XML configurations.

What you can do is define a @Configuration type that imports an XML resource

@Configuration
@ImportResource(value = "classpath:application.xml")
class XmlConfig {}

and register that

rootContext.register(XmlConfig.class);

Upvotes: 2

Related Questions