Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error starting Application: required a bean after adding jwt code #3

Open
khadkakrishna opened this issue May 8, 2021 · 8 comments

Comments

@khadkakrishna
Copy link

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
�[2m2021-05-09 01:29:41.191�[0;39m �[31mERROR�[0;39m �[35m32429�[0;39m �[2m---�[0;39m �[2m[  restartedMain]�[0;39m �[36mo.s.b.d.LoggingFailureAnalysisReporter  �[0;39m �[2m:�[0;39m 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in com.example.myproject.jwt.JwtSecretKey required a bean of type 'com.example.myproject.jwt.JwtConfig' that could not be found.


Action:

Consider defining a bean of type 'com.example.myproject.jwt.JwtConfig' in your configuration.
@khadkakrishna khadkakrishna changed the title Error starting Application: required a bean Error starting Application: required a bean after adding jwt code May 8, 2021
@lucasccampos
Copy link

lucasccampos commented Jun 7, 2021

just add @Configuration in JwtConfig class

@NiqueNat
Copy link

NiqueNat commented Jul 8, 2021

Hi, I added the @configuration and I am unable to access any file, I get 403 error and no token is generated

@lucasccampos
Copy link

lucasccampos commented Jul 8, 2021

try @Component

U can try not using JwtConfig class
just use

//Use @Value with the name of the value in application.properties
//put this code inside any class that is initialized by SpringBoot, like @Component @Configuration etc...
@Value("${application.jwt.token}")
    private String tokenKey;

@NiqueNat
Copy link

NiqueNat commented Jul 8, 2021 via email

@matisszilard
Copy link

Adding the @Component annotation inside the JwtConfig class solves the issue for me.

@NiqueNat
Copy link

NiqueNat commented Jul 14, 2021 via email

@aminweb007
Copy link

aminweb007 commented Dec 30, 2021

This is happening if you use any spring-boot release higher than 2.2.0 used by Nelson. So the code in this repository will compile fine. But if you use a new release then you can add @component annotation to JwtConfig class in order to be recognized as a Bean and be auowired.

package com.aelamine.sprintbootsecurity.jwt;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import com.google.common.net.HttpHeaders;

@ConfigurationProperties(prefix = "application.jwt")
@Component
public class JwtConfig {

	private String secretKey;
...

@tobidenagan
Copy link

tobidenagan commented Jan 1, 2022

Using only @component annotation solved the issue

This is happening if you use any spring-boot release higher than 2.2.0 used by Nelson. So the code in this repository will compile fine. But if you use a new release then you can add @component annotation to JwtConfig class in order to be recognized as a Bean and be auowired.

package com.aelamine.sprintbootsecurity.jwt;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import com.google.common.net.HttpHeaders;

@ConfigurationProperties(prefix = "application.jwt")
@component
public class JwtConfig {

private String secretKey;
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants