在spring的bean中注入enum类型
1 定义枚举类型
public enum EnumType {
TRANSACTION,
EXTENDED
}
2 定义要注入枚举类型的bean
package example;
public class Client {
private EnumType persistenceContextType;
public void setPersistenceContextType(EnumType type) {
this.persistenceContextType = type;
}
}
3 相应的spring配置文件
<bean class="example.Client">
<!-- 这里直接写枚举类型的值得名称 spring自动去转换 -->
<property name="persistenceContextType" value="TRANSACTION" />
</bean>