我正在尝试在 spring xml 配置文件中创建和填充 guava HashBasedTable
,但我无法做到。
我的表格是这样的:
Table<String, Foo, Bar> myTable;
我已经在我的 xml 中试过了,但不知道如何将新值放入表中:
<property name="myTable">
<bean class="com.google.common.collect.HashBasedTable" factory-method="create">
<!--- how do I insert value in here??? -->
</bean>
</property>
最佳答案
如果您想专门在 xml 中执行此操作,则有点棘手:我发现 guava 没有提供太多用于将值放入该表的选项。 有一种方法,但是对于多个插入来说很奇怪:
<bean id="myTable" class="com.google.common.collect.HashBasedTable" factory-method="create" />
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject">
<ref local="myTable" />
</property>
<property name="targetMethod">
<value>put</value>
</property>
<property name="arguments">
<list>
<value>1</value>
<value>1</value>
<value>value</value>
</list>
</property>
</bean>
关于java - 在 spring xml 配置中定义 guava HashBasedTable/Table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23897335/