我有spring xml config
架构:
<?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.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
使用bean定义的属性:
<property name="airDates">
<util:set set-class="java.util.TreeSet">
<ref bean="first_event_dateTime"/>
</util:set>
</property>
<bean
name="first_event_dateTime"
class="java.time.LocalDateTime"
factory-method="of">
<constructor-arg type="int" value="2020"/>
<constructor-arg type="int" value="6"/>
<constructor-arg type="int" value="15"/>
<constructor-arg type="int" value="19"/>
<constructor-arg type="int" value="30"/>
</bean>
注射目标是NavigableSet
,相应的是setter和getter
private NavigableSet<LocalDateTime> airDates = new TreeSet<>();
问题是:
1)我的IDE突出显示util:set
,并说Bean必须是以下类型之一:
Bean必须是以下类型之一:java.time.LocalDateTime或 java.util.NavigableSet中
2)Spring执行对我说:
找不到元素[set]
的BeanDefinitionDecorator
您有什么想法如何解决这个问题?
答案 0 :(得分:1)
请提供first_event_dateTime
的定义更新:以下定义适用于我的环境:
XML:
...
<bean
name="first_event_dateTime" class="java.time.LocalDateTime" factory-method="of">
<constructor-arg type="int" value="2020"/>
<constructor-arg type="int" value="6"/>
<constructor-arg type="int" value="15"/>
<constructor-arg type="int" value="19"/>
<constructor-arg type="int" value="30"/>
</bean>
...
<bean id="client" class="<my package>.Client"
<property name="airDates">
<util:set set-class="java.util.TreeSet">
<ref bean="first_event_dateTime"/>
</util:set>
</property>
</bean>
爪哇:
import java.time.LocalDateTime;
import java.util.NavigableSet;
public class Client {
private NavigableSet<LocalDateTime> airDates;
public NavigableSet<LocalDateTime> getAirDates() {
return airDates;
}
public void setAirDates(NavigableSet<LocalDateTime> airDates) {
this.airDates = airDates;
}
...
}