使用春季启动的OAuth2中的FileNotFoundException

时间:2020-10-13 18:13:10

标签: java spring-boot spring-security jwt spring-security-oauth2

我已经实现了具有Spring安全性并使用私钥对令牌进行签名的授权服务器应用程序。生成的非对称密钥存储在应用程序的资源路径中。当我运行应用程序时,发生以下错误。

错误

Caused by: java.io.FileNotFoundException: class path resource [jwt.jks] cannot be opened because it does not exist

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tokenStore' defined in class path resource [com/benz/oauth2/api/config/AuthorizationServerConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.provider.token.TokenStore]: Factory method 'tokenStore' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jwtAccessTokenConverter' defined in class path resource [com/benz/oauth2/api/config/AuthorizationServerConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter]: Factory method 'jwtAccessTokenConverter' threw exception; nested exception is java.lang.IllegalStateException: Cannot load keys from store: class path resource [jwt.jks]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]

AuthorizationServer类

@Bean
public TokenStore tokenStore()
{
 return new JwtTokenStore(jwtAccessTokenConverter());
}


public JwtAccessTokenConverter jwtAccessTokenConverter() {
    JwtAccessTokenConverter converter=new JwtAccessTokenConverter();
    converter.setKeyPair(new KeyStoreKeyFactory(new ClassPathResource("jwt.jks"),"1429Oop".toCharArray()).getKeyPair("springblog"));
    return converter;
}

注意-jwt.jks存储在资源路径下

0 个答案:

没有答案