When creating the bean using the XML file, Spring creates the bean and applies the injection of configured fields, via XML configuration or decorated by annotations e.g. @Autowired
, @Value
, etc...
When creating the bean using new YourClass
, then you're manually creating an instance of the class, thus not being handled by Spring.
If you want Spring to handle new beans created on demand i.e. using new
keyword, you can refer to Spring injecting or autowiring datasource bean to class, point 3 and the explanation at the bottom using @Configurable
.