0

I come across this code in my web.xml but I don't understand how to add securityConfig.xml to the classpath along with dispatcherContext.xml

<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:dispatcherContext.xml</param-value>
</context-param>

can anyone please give me some suggestion

UPDATE

when i include <import resource="classpath:securityConfig.xml" /> in dispatcherContext.xml like as shown below

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/tx 
            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
            http://www.springframework.org/schema/util
            http://www.springframework.org/schema/util/spring-util.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc.xsd">

   <import resource="classpath:securityConfig.xml" />

I am getting the below Exception

ContextLoader - Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:securityConfig.xml]
Offending resource: class path resource [dispatcherContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [securityConfig.xml]; nested exception is java.io.FileNotFoundException: class path resource [securityConfig.xml] cannot be opened because it does not exist
    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)

1 Answer 1

1

Just use import within the root context definiton (dispatcherContext.xml in yr case) file :

<!-- Load spring security related configuration -->
<import resource="classpath:securityConfig.xml"/>

But you can supply mutiple by putting a space btween the file names :

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>dispatcherContext.xml securityConfig.xml</param-value>
</context-param>
Sign up to request clarification or add additional context in comments.

9 Comments

But what about the classpath, classpath: is missing in <param-value>dispatcherContext.xml securityConfig.xml</param-value>
but got exception --> org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/securityConfig.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/securityConfig.xml]
i have placed the securityConfig.xml in the same place where dispatcherContext.xml is been placed i.e within the resource folder
dispatcherContext.xml is picking up if i remove the dispatcherContext.xml
the convential way is to reference other files from within the xml file, or java class if doing java based conf. Mutlple context definition in the web.xml would imply different applications, but thats not actually what you want.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.