#New to Spring

1 messages · Page 1 of 1 (latest)

graceful summit
#

The Autowiring is not working and I keep getting the error,

Cannot invoke "learn.PasswordGenerator.generatePassword(int)" because "this.passwordGenerator" is null

Can someone please help with this and clarify how it ought to work? Clumped all the classes in one file for the sake of posting.
I've added @Component and @Configuration to pretty much everything in order to get this to function.

Thanks a lot in advance!

slow laurelBOT
#

<@&987246883653156906> please have a look, thanks.

amber ocean
#

first thing, 'new' and spring don't really match

#

second, drop the @configuration

#

thrid, if u have omitted section make sure u got component scanning on

#

and 4th, its not a spring error that your having 😉

#

@graceful summit

graceful summit
#

Thanks for the quick response bud.

  • I haven't omitted any section, just clubbed everything together. Modified a program I found online to learn Autowiring beans and components,
  • Should I not use the new with @deft cosmos?
  • If I don't use @Configuration in the 2nd class, won't the @deft cosmos have problems?
  • And I understand the null pointer exception is not exactly a Spring error but isn't @Autowired supposed to inject PasswordGenerator automatically?
amber ocean
#

right

#

then your main problem is the configuration and your big mistake is the new keyword

#

once u use that, the object is not spring managed, but a regular one

#

That's why the code is saying its a simple java error instead of giving 2-3 pages of stactrace with cannot inintiate bean with ....

graceful summit
#

Okay. I'll try and rework the points you've mentioned. It's not clear in my head so as to how it'll work but hopefully I'll learn something while tackling this. Thank you!

amber ocean
#

trying to find an easy guide on how it works

#

there is this, but its quite big to quickly read

#

but it does has a step by step guide on a hello world

graceful summit
#

No worries, I got time peepo_comfy

#

Thank you

amber ocean
#

have a read, but just seeing its mostly using xml config , there is also annotation based, but the concept and work method is the same

graceful summit
#

Yup, doing that. Need more clarity on how beans function in this whole autowiring situation

amber ocean
#

yeah well for now u basicly made a spring attempt, and then by using your new ... command, your going out of spring

#

so no matter what u add, it wont work