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>
Shravan Ramamurthy
  • 3,896
  • 5
  • 30
  • 44

2 Answers2

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"
})
Community
  • 1
  • 1
Abdelghani Roussi
  • 2,707
  • 2
  • 21
  • 39
  • 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? – Shravan Ramamurthy Feb 10 '17 at 16:18
0

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

Jaiwo99
  • 9,687
  • 3
  • 36
  • 53
  • 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 – Shravan Ramamurthy Feb 10 '17 at 15:20