spring cvc-complex-type.2.4.c:匹配的通配符是严格的,但找不到元素“context:property-placeholder”的声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14557219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:property-placeholder'
提问by Radhakrishna
could anyone help me resolving the following error as i am new to spring?
任何人都可以帮助我解决以下错误,因为我是 Spring 新手吗?
cvc-complex-type.2.4.c: The matching wildcard is strict, but no
declaration can be found for element 'context:property-placeholder'.
I have the following configuration in applicationContext.xml:
我在 applicationContext.xml 中有以下配置:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
xmlns:context="http://www.springframework.org/schema/context">
<bean id="dataSource"class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<context:property-placeholder location="src/jdbc.properties"/>
回答by Jasper Blues
Spring provides a bunch of additional name-spaces that provide short-hand ways to do things - things like tx (transactions), util (utils), mvc (spring MVC declarations):
Spring 提供了一堆额外的命名空间,这些命名空间提供了做事的速记方式——比如 tx(事务)、util(utils)、mvc(spring MVC 声明):
To use one, you have to set up the schema mapping in your XML file. If this is done, you get basic code-completion (your IDE may provide more). .
要使用一个,您必须在 XML 文件中设置模式映射。如果这样做,您将获得基本的代码完成(您的 IDE 可能提供更多)。.
In your declaration context was not set-up/mapped.
在您的声明上下文中没有设置/映射。
Change your declaration to the following:
将您的声明更改为以下内容:
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
</beans>
You can also set up your own namespaces for in-house components, if you wish.
如果您愿意,您还可以为内部组件设置自己的命名空间。
回答by Devayan Thakur
If you use Spring >= 3.1, use PropertySourcesPlaceholderConfigurer rather than the old.
如果您使用 Spring >= 3.1,请使用 PropertySourcesPlaceholderConfigurer 而不是旧的。
Workaround: Replace
解决方法:更换
<context:property-placeholder location="classpath:sport.properties"/>
BY
经过
`
`
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:sport.properties</value>
</property>
</bean>
`
`

