Skip to content

Bean that could not be found Spring Boot

I have a problem when trying to start my Spring Boot application with tokenization. This is my service class:

public class JwtTokenService {
    private final JwtConfig jwtConfig;

    public JwtTokenService(JwtConfig jwtConfig) {
        this.jwtConfig = jwtConfig;

    public String generateToken(Authentication authentication) {
        Long now = System.currentTimeMillis();
        return Jwts.builder()
                .claim("authorities", authentication.getAuthorities().stream()
                .setIssuedAt(new Date(now))
                .setExpiration(new Date(now + jwtConfig.getExpiration() * 1000))
                .signWith(SignatureAlgorithm.HS512, jwtConfig.getSecret().getBytes())


This is my config class:

public class JwtConfig {
    private String Uri;

    private String header;

    @Value("${security.jwt.prefix:Bearer }")
    private String prefix;

    private int expiration;

    private String secret;

And I get the following error when I try to run my Application:



Parameter 0 of constructor in services.JwtTokenService required a bean of type 'config.JwtConfig' that could not be found.


Consider defining a bean of type 'config.JwtConfig' in your configuration.

I dont understand why i get this error.


I solved it. The problem was that the package where the config lays was not scanned by my spring boot application. In my @SpringBootApplication I added @ComponentScan with the package where JwtConfig lays.