What happens when I build an object using new keyword in service using springboot framework?
Does the Object created using "new" keyword is built out of the container?
What happens when I build an object using new keyword in service using springboot framework?
Does the Object created using "new" keyword is built out of the container?
No, the object created out of a "new" keyword doesn't come out of the container. There are two disadvantages to this approach. The first being that it renders the Spring framework a bit useless. Secondly, if there are @Autowired or Spring managed beans inside your "new" bean, they won't get injected. Once you do a "new", spring leaves all the subsequent hierarchical dependency injection to you.
in Spring, objects that are created using new keyword, created outside of the container. So you wouldn't get benefits like life cycle management, Security etc
You should always use Spring dependency injection to create Beans (using the @Autowired annotation is the recommended way to do this) otherwise you're losing the benefits of using the Spring framework. I would suggest reading this documentation on Beans and Dependency Injection if you haven't already