Spring啟動時靜態static注入@PostConstruct
阿新 • • 發佈:2018-12-04
當@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; } }