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

标签 java spring

我正在尝试将 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.

Here's my ioc xml file:


<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>

最佳答案

这是 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>

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

关于Java Spring : Error message "no declaration can be found for element ' util:constant',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10523162/

相关文章:

java - Hadoop:java.lang.Exception:java.lang.RuntimeException:配置对象时出错

java - Spring MVC非阻塞和阻塞的性能差异

java - Spring 4 中的 DeferredResult 是否支持 Servlet 3.1 (Read|Write)Listener?

Css 和 js 未在 spring mvc 应用程序中加载

java - java中的高效排列算法

java - 从网站提取数据时出现异常

java - 为什么我的代码必须输入两个输入才能开始运行?

java - 使动态创建的 AttributeDefImpl 在填充后只读

java - Spring JPA 获取ManyToMany

java - 具有不同时间差的调度程序