Spring bean to represent a Table

时间:2019-04-17 00:12:30

标签: java spring dependency-injection

This is how we can represent a map in Spring beans

<bean id="MyBean" class="org.MyClass">
    <constructor-arg name="componentName">
        <util:map>
            <entry key="T1" value-ref="A"/>
            <entry key="T2" value-ref="B"/>
            <entry key="T3" value-ref="C"/>
        </util:map>
</bean>

For this class:

public class MyClass {
    public MyClass(Map<String, String> componentName)
}

How would I represent a class that needs a Table instead of a Map as input.

import com.google.common.collect.Table;

public class MyClass {
    public MyClass(Table<String, String, String> componentName)
}

I would also like to understand how this can be extended for more complex structures like a class itself.

1 个答案:

答案 0 :(得分:0)

Only four major collection types are supported.

List – <list/>
Set – <set/>
Map – <map/>
Properties – <props/>

From Docs,

In the list, set, map, and props elements, you set the properties and arguments of the Java Collection types List, Set, Map, and Properties, respectively.

Spring Doc Ref [7.4.2] : https://docs.spring.io/spring/docs/4.3.12.RELEASE/spring-framework-reference/htmlsingle/#beans-factory-class