0

I am converting existing spring based application from xml to java config. There are some spring xml configurations to which i do not have access to modify them. So i need to add my java based spring config to web.xml how do i do it? below is my contextConfigLocation definition in web.xml

<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:/moduleApplicationContext.xml classpath*:/webModuleApplicationContext.xml <!--need to add spring java config here--> </param-value> </context-param> 

2 Answers 2

2

I think you should have a look at this How to register Spring @Configuration annotated class instead of applicationContext.xml file in web.xml?


Edit

regarding your request, you can do it like so:

(copied From the other Q&A)

<servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextClass</param-name> <param-value> org.springframework.web.context.support.AnnotationConfigWebApplicationContext </param-value> </init-param> <init-param> <param-name>contextConfigLocation</param-name> <param-value> org.package.YourConfigurationAnnotatedClass </param-value> </init-param> </servlet> 

And in your config class (YourConfigurationAnnotatedClass) add :

@ImportResource({ "classpath*:/moduleApplicationContext.xml", "classpath*:/webModuleApplicationContext.xml" }) 
Sign up to request clarification or add additional context in comments.

1 Comment

This post talks about how to specify Java spring config's in web.xml. But my question is how to combine java and spring configurations without modifying any existing(Since i dont have access to the xml files) spring configs. Is there any way i can specify both java and xml config in contextConfigLocation in web.xml?
0

you can declare your java config as bean in xml, then you can have both in web.xml

1 Comment

I do not want create a separate xml to just to specify context:component-scan for the java configs. Also the spring configuration file i need to specify in the xml is in the library and hence i can't modify them

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.