springBoot中static類引用普通類的方法【工作】
阿新 • • 發佈:2019-03-16
需求:
要在一個工具類中引用其他專案包提供的一個API,直接引用會報錯。
解決方案:
直接貼程式碼,主要是注意註解的使用;
import com.test.api.basecode.BaseCodeAPI;
/**
* 功能描述:獲取使用者的工具類
*
* @author: LIUY
* @create: 2019-01-21 17:15
*/
@Component
@Slf4j
public class SessionUtil {
@Autowired
private LoginAPI loginAPI;
@Autowired
private static LoginAPI staticLoginAPI;
@PostConstruct
public void init(){
staticLoginAPI = loginAPI;
}
/**
* 功能描述
*
* @Description: 獲取userToken的value值
* @Author: LIUY
* @Date: 2019/1/21 14:38
*/
public static String getCookieVal() {
BaseResponse baseResponse = staticLoginAPI.getCookieVal();
Object data = baseResponse.getData();
if (null != data)
{
return data.toString();
}else {
return null;
}
}
}