idea对于使用@autowired 注解进行依赖注入是不推荐的,一直都是黄色下划线警告,其次它不可以将final关系的依赖注入
// Variable 'keyPair' might not have been initialized @Autowired private final KeyPair keyPair;2、构造方法依赖注入
依赖关系明确,依赖关系可以是final,关键是可以不在使用autowired注解
@RestController
@RequestMapping("oauth")
public class KeyController {
private final KeyPair keyPair;
public KeyController(KeyPair keyPair) {
this.keyPair = keyPair;
}
@GetMapping("key")
public Map getKey() {
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
RSAKey key = new RSAKey.Builder(publicKey).build();
return new JWKSet(key).toJSONObject();
}
}



