0
votes

Below is the code for servlet-context.xml in my spring project. I want to import demo.xml file in case the profile is prod and demo-test.xml if the profile is test.

<beans:beans xmlns="http://www.springframework.org/schema/mvc"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:beans="http://www.springframework.org/schema/beans"
             xmlns:task="http://www.springframework.org/schema/task"
             xmlns:context="http://www.springframework.org/schema/context"
             xsi:schemaLocation="
                http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
                http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <beans profile="test">
        <import resource="demo-test.xml"></import>
    </beans>
    <beans profile="prod">
        <import resource="demo.xml"></import>
    </beans>


    <task:annotation-driven
            executor="defaultExecutor"/>
    <!-- add an exception handler here. -->

    <task:executor id="defaultExecutor"
                   pool-size="50-200"
                   queue-capacity="1200"
                   keep-alive="10"
                   rejection-policy="CALLER_RUNS"/>

</beans:beans>

But I am getting error The matching wildcard is strict, but no declaration can be found for element 'beans'. for line <beans profile="test"> and 'resource' attribute should be defined for <import resource="demo-test.xml"></import>

Based on error in spring xml config relating to bean profiles I even tried changing context to "http://www.springframework.org/schema/beans/spring-beans-3.2.xsd" but no luck. Can some one help me understand what does this error mean and how can I fix this?

1

1 Answers

0
votes

The <beans:beans xmlns="http://www.springframework.org/schema/mvc" at the top of your xml file uses mvc instead of beans, meaning that the default namespace is mvc instead of beans. Either, qualify the bean tag: use <beans:beans profile="test">... instead of <beans profile="test">... and <beans:import resource... instead of <import resource..., OR change the default namespace to beans to use the xml as is