spring @Autowired注入對象,在構造方法中為null問題


出現問題的代碼如下:

@Service
public class BaseHttpServiceImpl implements BaseHttpClient {

    private final static Logger logger = LoggerFactory.getLogger(BaseHttpClient.class);

    private OkHttpClient mOkHttpClient;
    @Autowired
    private AthenaConfig configure ;
    private CookiesStoreImpl cookiesStoreImpl;


    /**
     * 初始化客戶端
     */
    
    public BaseHttpServiceImpl(AthenaConfig configure) {
    ……
  String url=configure.getName("url");
  } 
}

運行該代碼會提示:configure為null 空指針錯誤

構造器改為:

@Autowired
    public BaseHttpServiceImpl(AthenaConfig configure) {
        this.configure=configure;
        ……          
}

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM