初始化 项目一启动方法就运行 一使用对象就有map

项目一启动方法就运行

Spring容器加载bean,postConstruct就运行了

类加@Commoent 方法加@PostConstruct

@Commoent
public class Constant {
	@PostConstruct
	public void test(){
   		 System.out.println("项目启动就运行了呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃,因为spring容器注册bean");
 	}	
}

一使用对象就有map

代码块

public class Constant {	
	public static String EvaluationInfo = "EvaluationInfo";
	public static String WholeDepartment = "WholeDepartment";
	
	public static Map<Integer, String> REVIEW_MAP;
	
	static {
    		 System.out.println("Constant运行了啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊");
   		 REVIEW_MAP = new HashMap<Integer, String>();
   		 REVIEW_MAP.put(0, EvaluationInfo);
   		 REVIEW_MAP.put(5, WholeDepartment);
	}
}
发布了172 篇原创文章 · 获赞 0 · 访问量 5692

猜你喜欢

转载自blog.csdn.net/weixin_44635157/article/details/104678952