As per spring documentation it has been mentioned
it is by design
I want to understand the possible thinking behind this design.
As per spring documentation it has been mentioned
it is by design
I want to understand the possible thinking behind this design.
It's because Autowiring
is just an alternative for referencing your existing beans in ApplicationContext. It expects a bean or a class, primitive is not a class and it differs from Object. Which is why you can't Autowire
primitive types. You can use wrapper classes of the primitive types such as Integer, Double etc... to be able to use Autowiring for such types because you are now referring to a class.
Autowiring can't be used to inject primitive and string values. It works with reference only. Injected referance need to have a class which is object. you can use wrapper for same. i.e. Interger, Boolean.
For primitive you can do like spring-bean-primitive-properties-when-using-component-and-autowired
Instead of autowiring a primitive type, you can autowire the wrapper class
for the int
type --> use Integer
.
Autowiring is just an alternative for referencing your existing beans in ApplicationContext.
primitives are not as bean which are existing in the application context
it expects an instance/bean not a primitive.