@Deprecated
public enum BizUtil {
INSTANCE;
/** 日志对象 */
private final static Logger logger = SpecLoggerFactory
.getLogger(BizUtil);
}
spring enum class inject
<bean id="bizUtil" class="com.xxx.util.BizUtil" factory-method="valueOf">
<constructor-arg index="0" value="com.xxx.util.BizUtil" />
<constructor-arg index="1" value="INSTANCE" />
</bean>
为什么要怎么注入?
想一下spring如何通过你的配置获取这个INSTANCE的
用的valueOf
配置转换为代码就是:
BizUtil INSTANCE = BizUtil(“com.xxx.component.util.BizUtil”,”INSTANCE”);
public enum Singleton {
INSTANCE;
public static void main(String args[]) {
Singleton singleton = Singleton.valueOf(Singleton.class, "INSTANCE");
System.out.println(singleton);
}
}