spring - What will happen if bean having prototype scope included in bean having singleton scope -


i have class having singleton scope (car) , contain reference of class(steering) having prototype scope.now whenever trying print hashcode of class having singleton scope , class having prototype scope , value of hashcode coming same.

car car=(car)ac.getbean("singletonbean"); steering steering=car.getsteering(); system.out.println("singleton obj >"+car.hashcode()); system.out.println("singleton obj >"+steering.hashcode()); car car1=(car)ac.getbean("singletonbean"); steering steering1=car.getsteering(); system.out.println("singleton obj >"+car1.hashcode()); system.out.println("singleton obj >"+steering1.hashcode()); 

the hashcode of car coming same because same object being returned scope singleton. that's why hashcode of steering coming same because same car object being returned. if steering in prototype scope , hashcode should different ??

thanks

what happening reasonable. since there 1 bean of type car, there 1 steering object being used , hence same hash code.

if have type, bus , had spring managed bean of type had dependency on steering, steering object injected bean of type bus not same 1 injected bean of type car.

in following code snippet, assertion pass

car car=(car)ac.getbean("singletonbean"); bus bus = (bus)ac.getbean("bus");  assert (bus.getsteering() != car.getsteering()); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -