I made an application with spring-boot-starter-oauth2-resource-server in pom.xml and a value for spring.security.oauth2.resourceserver.jwt.issuer-uri in application.properties. It works fine when I start it for the first time. Then I added a @Service class with org.springframework.security.oauth2.jwt.JwtDecoder injected as below
@Slf4j
@Service
public class MyService {
private final JwtDecoder jwtDecoder;
private final WebClient webClient;
public MyService(
JwtDecoder jwtDecoder,
WebClient webClient
) {
this.jwtDecoder = jwtDecoder;
this.webClient = webClient;
}
// method definitions
}
When I run, it throws error
Parameter 0 of constructor in MyService required a bean of type 'org.springframework.security.oauth2.jwt.JwtDecoder' that could not be found.
When I remove the injection it works fine again.
What should I do?
In a separate config class, You might have to add a bean for the jwt decoder like this:
The import for the properties would be: