Spring problem with the configuration of the frame "context prefix for element context: annotation-config is not bound"

I have a strange problem that I cannot track down. I have work with other servers without problems, but I cannot get this work to work. The closest message that I see in my problem was this post The context prefix for the context: component scan element is not connected

All the rest were just because the prefix was not in the xml file. I hope someone can point me in the right direction.

Spring XML File:

<?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:context="http://www.springframework.org/schema/context" xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr" xmlns:mongo="http://www.springframework.org/schema/data/mongo" 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/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd"> <context:annotation-config/> 

So, I have this, but I get this error:

 org.xml.sax.SAXParseException: The prefix "context" for element "context:annotation-config" is not bound. 

Appreciate any help. Let me know what else I can provide.

thanks

+6
source share
4 answers

I ran into the same problem until I realized that the beans xmlns:context tag attribute is missing. Just add the following lines

 xmlns:context="http://www.springframework.org/schema/context" 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 ...." 

Then rebuilt the project.

Now it worked well.

+12
source

The following works for me:

test.xml

 <?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:context="http://www.springframework.org/schema/context" xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr" xmlns:mongo="http://www.springframework.org/schema/data/mongo" 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/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd"> <context:annotation-config/> </beans> 

When I use the following class to run it:

Test.java

 import org.springframework.context.support.ClassPathXmlApplicationContext; public class Test { public static void main(String[] args) throws Exception { new ClassPathXmlApplicationContext("test.xml"); System.out.println("Finished!"); } } 

Can you see if this works for you? In the class path, you will need the following libraries: commons-logging, spring -asm, spring-beans, spring -context, spring -core and spring -expression.

Please let me know if this works. If not, send a full stack. Finally, I used Spring 3.1.1 for the above.

+9
source

This error occurs if xmlns:context missing from your spring xml file. So add it. Your beans header should look something like this:

 <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd" > <context:annotation-config /> <context:component-scan base-package="controller" /> </beans> 
+4
source

I ran into the same problem, but I was able to solve it by moving

from applicationContext.xml to spring -servlet.xml and adding xmlns: context to spring -servlet.xml

0
source

Source: https://habr.com/ru/post/951358/


All Articles