Код: Выделить всё
Error:(41, 17) java: no suitable method found for signWith(java.security.PrivateKey)
method io.jsonwebtoken.JwtBuilder.signWith(io.jsonwebtoken.SignatureAlgorithm,byte[]) is not applicable
(actual and formal argument lists differ in length)
method io.jsonwebtoken.JwtBuilder.signWith(io.jsonwebtoken.SignatureAlgorithm,java.lang.String) is not applicable
(actual and formal argument lists differ in length)
method io.jsonwebtoken.JwtBuilder.signWith(io.jsonwebtoken.SignatureAlgorithm,java.security.Key) is not applicable
(actual and formal argument lists differ in length)
Код: Выделить всё
@Service
public class JwtUtilTwo
{
private KeyStore keyStore;
@PostConstruct
public void init() {
try
{
keyStore = KeyStore.getInstance("JKS");
InputStream resourceAsStream = getClass().getResourceAsStream("/springblog.jks");
keyStore.load(resourceAsStream, "secret".toCharArray());
}
catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | IOException e)
{
throw new SpringRubbishRewardsException("Exception occurred while loading keystore");
}
}
public String generateToken(Authentication authentication) {
User principal = (User) authentication.getPrincipal();
return Jwts.builder()
.setSubject(principal.getUsername())
.signWith(getPrivateKey()) //ERROR HERE
.compact();
}
private PrivateKey getPrivateKey()
{
try
{
return (PrivateKey) keyStore.getKey("springblog", "secret".toCharArray());
}
catch (KeyStoreException | NoSuchAlgorithmException | UnrecoverableKeyException e)
{
throw new SpringRubbishRewardsException("Exception occurred while retrieving public key from keystore");
}
}
}
Код: Выделить всё
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
rubbish-rewards
rubbish-rewards-api
1.0-SNAPSHOT
org.springframework.boot
spring-boot-starter-parent
2.3.0.RELEASE
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-data-jpa
mysql
mysql-connector-java
runtime
org.springframework.boot
spring-boot-starter-security
io.jsonwebtoken
jjwt-api
0.10.5
io.jsonwebtoken
jjwt-impl
runtime
0.10.5
io.jsonwebtoken
jjwt-jackson
runtime
0.10.5
javax.xml.bind
jaxb-api
2.3.0
Код: Выделить всё
2020-07-14 11:52:35.833 WARN 14616 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'authenticateController': Unsatisfied dependency expressed through field 'authenticateService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'authenticateService': Unsatisfied dependency expressed through field 'jwtUtil2'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jwtUtilTwo': Invocation of init method failed; nested exception is rubbishrewards.exceptions.SpringRubbishRewardsException: Exception occurred while loading keystore
Вот ссылка на руководство YouTube (с отметкой времени) и ссылка на видеоролики, сопровождающие репозиторий GitHub.
Я новичок в Spring, поэтому понятия не имею, что происходит. Если кто-нибудь сможет помочь, буду признателен.
Подробнее здесь: https://stackoverflow.com/questions/628 ... d-signwith
Мобильная версия