Spring启动时静态static注入@PostConstruct

当@PostConstruct注解不能使用代码提示补全,需要手动导包。** 

import javax.annotation.PostConstruct;


import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.xxx.mapp.service.common.CommonService;

@Component
public class UnionPayCommonUtil {
	
	@Autowired
	private CommonService commonService;
	private static UnionPayCommonUtil common;
	@PostConstruct
    public void init() {
		common = this;
    }
	public static String getCommonNo() {
		String commonNo=null;
		try {
			commonNo= common.commonService.getCommonNo();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return commonNo;
	}
}

猜你喜欢

转载自blog.csdn.net/jellyjiao2008/article/details/84401452