"-6ren"> "-我正在尝试对 ioc 使用 util:constant 标记,但收到以下错误消息: Exception in thread "main" org.springframework.beans.facto-6ren">
gpt4 book ai didi

Java Spring : getting error "Unknown property sub-element: "

转载 作者:行者123 更新时间:2023-12-04 05:47:12 24 4
gpt4 key购买 nike

我正在尝试对 ioc 使用 util:constant 标记,但收到以下错误消息:

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Error registering bean with name 'threadPoolExecutor' defined in class path resource [spring.xml]: Unknown property sub-element: <util:constant>



这是我的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: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">


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

更新:

这是我的带有 <value> 的 xml添加的标签会导致不同的错误消息:

发现以元素“util:constant”开头的无效内容。此时不需要子元素。

(旁注:由于某种原因,我的格式控件在 SO 中发布时消失了)


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


<属性名称="位置">
类路径:config.properties

















<值>










最佳答案

对于枚举,您可以直接分配值,Spring 会负责将其绑定(bind)到正确的枚举:

<constructor-arg index="3" value="SECONDS">

此外,您的原始条目对我来说非常有用:
<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>

关于Java Spring : getting error "Unknown property sub-element: <util:constant>",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10523535/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com