泛型推断类型不符合上限
生活随笔
收集整理的這篇文章主要介紹了
泛型推断类型不符合上限
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
程序報錯推斷類型不符合上限
springsecurity需要自定義用戶服務
代碼
@Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception {auth.userDetailsService(new CustomUserDetailsService());}
public class CustomUserDetailsService implements UserDetailsService {@Overridepublic UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
問題就在于無需自己實現
public interface UserDetailsService {public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException;
}
因為DaoAuthenticationConfigurer已經限定<T extends UserDetailsService>
public <T extends UserDetailsService> DaoAuthenticationConfigurer<AuthenticationManagerBuilder, T> userDetailsService(T userDetailsService) throws Exception {this.defaultUserDetailsService = userDetailsService;return apply(new DaoAuthenticationConfigurer<AuthenticationManagerBuilder, T>(userDetailsService));}
原因就是這個泛型方法是受限類型參數,語法參考:
刪掉自己聲明的UserDetailsService接口,就發現UserDetailsService的真正接口了
總結
以上是生活随笔為你收集整理的泛型推断类型不符合上限的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: junit集成Hamcrest测试集合中
- 下一篇: Java的JSON操作存储List到Re