中文字幕精品亚洲无线码二区,国产黄a三级三级三级看三级,亚洲七七久久桃花影院,丰满少妇被猛烈进入,国产小视频在线观看网站

HandlerInterceptor里@Autowired對象為(wei)空(kong)的解(jie)決方(fang)法

That's because Spring isn't managing your PagePopulationInterceptor instance. You are creating it yourself in the below (攔截(jie)器內使用@Autowired時出(chu)現了null,這是由于你(ni)的spring對象注入時機在你(ni)的攔截(jie)器之后(hou)了)

public @Override void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(new PagePopulationInterceptor());
}

change that to

@Bean
public PagePopulationInterceptor pagePopulationInterceptor() {
    return new PagePopulationInterceptor();
}

public @Override void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(pagePopulationInterceptor());
}

in this way, Spring will manage the lifecycle of the PagePopulationInterceptor instance since it's generated from a @Bean method. Spring will scan it for @Autowired targets and inject them.
This assumes that PagePopulationInterceptor is in a package to be @ComponentScaned.

posted @ 2018-07-03 17:49  張占嶺  閱讀(3837)  評論(0)    收藏  舉報