Bean Initialization Error
I am Getting this error ->
129 Replies
⌛
This post has been reserved for your question.
Hey @Danix! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
With this ->
i dont know why i am getting this
@dan1st | Daniel can u help
Are there any
@PostConstruct
annotated methods in the project?Yehh but they are just printing simple plain text in the console and i even removed them already
@Peter Rader
And the problem still exists?
Yehh
It's still there
@dan1st | Daniel can u see this problem
Try to add
@Lazy
annotation onto UserDetailsServiceImp
in security configuration.I did it but it doesn't work
Can you show the full stack trace? Also please don't ping individual users for help unless they tell you it's ok
Can you show your
UserDetailsServiceImp
?Can you share the project?
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
here it is
the config class ->
I mean can you zip whole project and put here so we can download and put to our IDEs to try it and resolve.
Other than that can you create password encoder as a separate class bean? Like a component?
Then to autowire it to the spring config.
And to use it in the
configureGlobal
method as a password encoder. This is how I have. Because earlier I also had circular referencies.
And I got rid of it as I created separate password encoder bean.Yehh but I feel I am not comfortable to put my whole project here . So if it's possible you can help me from there
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
The problem is not still solved
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
@dan1st | Daniel hey can u see it
Can you try without the PostConstruct there?
I did it but still getting the same issue !
Did you remove both
@PostConstruct
methods?yeh i did
Why did you mark
configureGlobal
with @Autowired
?Do you use constructor-injection?
should not i do that ?
I'm asking why to find out kinda
I don't know what it's supposed to do
ok i removed it and the error is gone but i am not able to login the user it says 302 ?
You still haven't said what you wanted to achieve by making it
@Autowired
actually i was getting error with some of the thing so one guy tells me to do that and after that a new error spawn !
but i dont know how to resolve 302 error and thats the reason why i have to do that and i am still upon that issue !
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Where are you getting the 302?
/LoginPage
endpoint
You wrote
anyRequest().authenticated()
before the formLogin
partyehhh
so how it is intrupted the user to login in even the user is in DB
so you are saying all requests need to be authenticated
Can you try moving that part below the
formLogin
part?nahh still the same
Can you try adding
/LoginPage
to the authorizeHttpRequests
matchers at the top?let me try
no still the same
This is How the UserDetailServie is Looks Like to check for the Authenticated User
what exactly redirects? GETing the /LoginPage or actually logging in?
The header looks like this ->
..
ah ok
hmm did u get it ?
is it due to my html stuff
is it the right way to config the Spring Security for login page right ? bcz after the Update i think a lot of things had been changed !
Can you try putting the content and parameter of configureGlobal in the filterChain method?
now it finally sent the message
wdym by this can u ellaborate ?
The holy error i got
Then try that
another error
You could try putting it in another class
wdym
or actually
I think it might be ok if you change
to
i think i doesnot Help
i have to do it like this
Does my other class might have some problem may be I am not sure about it but I think I really made them very well
¯\_(ツ)_/¯
So what do u think what's the problem here because I am stucked here from last 2 days !
idk some circular dependency maybe
you could try not using autowired as all/doing everything with constructor parameters
and don't do things like
encoder()
Why?Bcz it was giving me the red line error
.
like this
ah yeah you need to add a
.build()
no there is no .build() coming there
you might even need
.and().and().build()
but the error is still there
Where?
ah that error
Can you show your security config again?
Can you try removing
and add an
UserDetailsServiceImp detailsServiceImp
argument to filterChain
yeh
did i t
but what about the code who is in different class bcz i dont need any userImpService in filter chain now if the AuthManager is in diff class
?
the error i go t
Which Spring Boot version are you using?
Are you doing anything with
HttpSecurity
anywhere else?💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
No i don't think so It was not the error before changing classes !
its showing 3.3.1
Can we do anything here to resolve it ?
Now I have changed the USernameError to Runtime Error for Debug purpose and i am getting a Whole Error that no user Found But that user is in DB as well @dan1st | Daniel
SO, can you run your application?
Still messing with authentication?
I have my configuration that I can just show you.
In this Spring Security implementation remove
encoder()
method bean. Create new class for password encoder. Like MyPasswordEncoder
:
And in Spring Security configuration inject it and use in AuthenticationManagerBuilder
:
So I have to make a password encoder separate class ?
Yes
Not hard
And you definitely need one more bean -
AuthenticationManager
:
put it somewhere in Spring Configuration. For example above the configureGlobal
.
And have the @Autowired
above the configureGlobal
.
It's from my experience.Should i also have to autowored the UserDetailsImpService in the Config Class ?
Yes definitely. This is key interface needed for the Spring Security to work with Authentication
ok done let me try it
I had in mind
UserDetailsService
interface. Not your implemnetation at UserDetailsImpService
ohh
But try also with your class that implements the
UserDetailsService
interface.i tried with both of them but still getting 302 error !
Ahh.. don't know this. I just tried to help you to solve your first problem - circular reference. As of 302... I need more info.
What exactly happens?
You try to login, and you get 302?
so how exactly the circular referance is solved ? and why it was happening ?
yehh
I don't quite know what exact beans were involved and depended one on another. But it turned out that
PasswordEncoder encoder()
bean was that bean. I had the same circular reference and I read from stack trace this place:
that is the path to your project class methods.ok but how can i reslove this 302 thing
This is my classs where user is authenticated
I am trying to find out. You should too.
I never had this.
and this is where user is added
so normally what u do ?
The Custom UserDeatails
is it due to the
.defaultSuccessUrl
?I don't know. If you would give your project I would try to resolve it. I would start searching the Internet under what circumstances this is returned.
To give or not to give it's up to you.
i will show u every class what u need me to show to u bcz for this project me and my friends are working on it so i also have to take permission from them as well ! hope u understand
.defaultSuccessUrl("/", true)
means that under successful login a user is redirected to /
yess
Your login page should send credentials to
http://localhost:8080/LoginPage
yess
thymeleaf
yess
I use React.js. Or test endpoints with swagger or Postman
oh
Ensure that the login page URL ("/Login") and the login processing URL ("/LoginPage") are correctly mapped and handled in your application.
The Controller
Try to add one more method in controller:
nothing happens
i dont know what to do know !!!!!
The Hibernate Query is working but how it is not finding the user ???
Hibernate: select u1_0.email,u1_0.name,u1_0.password from registered_user u1_0 where u1_0.email=?
Not sure. it should.
Does
Founded User
is printed in Spring console when you login from webpage?No
The console i got after clicking login and try to login the user
Is
UserDetailsServiceImp
reached?
Try this:
The UserDetailsServiceImp Reached thats why the error we got in the console
You add exisiting user username and password but No User found?
That's why you get 302
redirect
Do you really have the user in the database?
yehh
The console
Can you show how your user look in databse?
Mine looks like this:
I can select a user by email
Does your user has id?
is it possible to show the code by live streaming if u dont mind its really help to understand the problem
what's your user entity class?
yeh
yes you can call and share screen
ohh let me
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
Dan, I have found why that
@Autowired
is necessary. In order Spring Boot Security would be able to join itself PasswordEncoder
. Because if not then we get such exception:When UserDetailsService interface implemetation is this:
And if we add
@Autowired
on that:
method then there is no that exception and password is encoded. Authentication gets password needed to be with PasswordEncoder
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.