Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 已定义bean以获取枚举构造函数arg_Spring_Enums - Fatal编程技术网

Spring 已定义bean以获取枚举构造函数arg

Spring 已定义bean以获取枚举构造函数arg,spring,enums,Spring,Enums,用于所有数据源连接的连接池类。它有一个静态枚举来指示连接类型 class ConnectionPool { public static enum Type { t1, t2, t3; } … } 另一个类没有默认的contractor,构造函数将该类型作为contractor参数 class Update { public Update(Type type) { this.type = type; } ... } 在appl

用于所有数据源连接的连接池类。它有一个静态枚举来指示连接类型

class ConnectionPool {

   public static enum Type {
     t1,
     t2,
     t3;
   }
…
}
另一个类没有默认的contractor,构造函数将该类型作为contractor参数

class Update {
   public Update(Type type) {
      this.type = type;
   }
...
}
在applicationContext.xml中,定义了一个bean

<bean id="update" class="package.Update">
    <contructor-arg type="package.ConnectionPool.Type">
        <value>Type.t1</value>
    </contructor-arg>
</bean>
这应该起作用:

<bean id="update" class="package.Update">
    <contructor-arg type="package.ConnectionPool.Type">
        <value>t1</value>
    </contructor-arg>
</bean>

对不起,Tomasz我应该在我的原始问题中多加一点,我也试过t1,它也不起作用
<bean id="update" class="package.Update">
    <contructor-arg type="package.ConnectionPool.Type">
        <value>t1</value>
    </contructor-arg>
</bean>
<bean id="update" class="package.Update">
    <contructor-arg type="package.ConnectionPool.Type" value="t1"/>
</bean>
@Configuration
public class Config {

    @Bean
    public Update update() {
        return new Update(t1);
    }

}