Java Spring:错误消息“找不到元素‘util:constant’的声明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10523162/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 01:25:09  来源:igfitidea点击:

Java Spring: Error message "no declaration can be found for element 'util:constant'

javaspring

提问by opike

I'm trying to use util-constant for ioc but I'm getting the following error message:

我正在尝试将 util-constant 用于 ioc,但收到以下错误消息:

cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'util:constant'.

All of the spring 3.1.1 dist jars are in my classpath and I was able to successfully run my program prior to making the changes that included the use of the util:constant tag.

所有 spring 3.1.1 dist jar 都在我的类路径中,并且在进行包括使用 util:constant 标记的更改之前,我能够成功运行我的程序。

Here's my ioc xml file:

这是我的 ioc xml 文件:


<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:tool="http://www.springframework.org/schema/tool"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">


<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <value>classpath:config.properties</value>
    </property>
</bean>

<bean id="main" class="pikefin.Main">
<property name="executorSample" ref="executorSample"/>
</bean>


<bean id="executorSample" class="pikefin.ExecutorSample">
    <constructor-arg ref="threadPoolExecutor" />

</bean>


<bean id="threadPoolExecutor" class="java.util.concurrent.ThreadPoolExecutor">
    <constructor-arg index="0" value="2"/>
    <constructor-arg index="1" value="2"/>
    <constructor-arg index="2" value="10"/>
    <constructor-arg index="3"><util:constant static-field="java.util.concurrent.TimeUnit.SECONDS"/></constructor-arg>
    <constructor-arg index="4" ref="arrayBlockingPool"/>
</bean>

<bean id="arrayBlockingPool" class="java.util.concurrent.ArrayBlockingQueue">
    <constructor-arg value="5"/>
</bean>

</beans>

回答by Tomasz Nurkiewicz

This is the correct declaration of utilnamespace (don't forget about specifying schemaLocation):

这是util命名空间的正确声明(不要忘记指定schemaLocation):

<?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"
   xsi:schemaLocation="
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
     http://www.springframework.org/schema/util  http://www.springframework.org/schema/util/spring-util-3.1.xsd">


</beans>

See more at C.2.2 The util schema.

C.2.2 The util schema 中查看更多信息。