Questions tagged [spring-ioc]

The Spring IoC is a core component of the Spring Framework. It enforces the dependency injection pattern for beans, making them loosely coupled and allowing application developers to code with abstractions.

The Spring IoC (Inversion of Control) is a core component of the Spring Framework. It enforces the dependency injection pattern for beans, making them loosely coupled and allowing application developers to code with abstractions.

It is a process whereby objects define their dependencies only through constructor arguments, factory method arguments, and properties to be set on the object after it is constructed. The container then injects those dependencies when it creates the bean.

192 questions
1
vote
1 answer

BeanFactory Vs ApplicationContext in concern of BeanPostProcessor And BeanFactoryPostProcessor

I am now learning little bit detail about Spring IoC Containers with the difference between BeanFactory Vs Application Context. I was also referring the previous stack overflow discussion and tutorial point from the following links, BeanFactory vs…
Mr.DevEng
  • 2,651
  • 14
  • 57
  • 115
1
vote
1 answer

Spring boot - How to create spring beans for the objects created in static methods

I am trying to move old project to spring boot project. I created the spring project project and moved the code and now I am trying to springify the project by creating beans for the objects. @SpringBootApplication public class TestApplication…
user1298426
  • 3,467
  • 15
  • 50
  • 96
1
vote
0 answers

If Spring creates a DAG of beans it got to create. What is the additional benfit of using @DependOn?

Here, is a detailed post on how spring dependencies on one another can be resolved using @DependsOn --> Controlling Bean Creation Order with @DependsOn Annotation But some time in the past I have read that spring container creates a DAG of all the…
1
vote
0 answers

How does JVM and spring container work together during objs or beans creation?

Spring container creates Beans by creating a DAG first and then instantiates the non-dependent beans before creating any beans that are dependent on other beans. This is fine and understood. Any beans that is are dependent on regular java objects /…
samshers
  • 1
  • 6
  • 37
  • 84
1
vote
0 answers

Returning a @Bean through @Configuration on its own class

I have the following class: @Configuration @Component @Getter public class EndUserDisambiguator extends UserDisambiguator { private final Collection> endUserCredentialDisambiguators; @Autowired …
1
vote
2 answers

Spring Inject Generic Type

Say we have an interface like this one: public interface Validator { boolean isValid(T data); } And this is part of a core module. Multiple apps can use that same core module, with a different value for the generic T. An example implementation…
Will
  • 181
  • 1
  • 14
1
vote
1 answer

Spring application having AnnotationConfigApplicationContext: getting run time exception

This is a continuation to one of my SO questions. I extended the same example and I expected it to work, however I am getting NullPointerException. Here is the complete source code: FirstBean.java package com.example; import…
CuriousMind
  • 8,301
  • 22
  • 65
  • 134
1
vote
1 answer

About AnnotationConfigApplicationContext in Spring framework

I have written the following simple stand-alone spring app: package com.example; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import…
CuriousMind
  • 8,301
  • 22
  • 65
  • 134
1
vote
2 answers

How to create a factory-method with arguments?

Could you please help me to get rid of ApplicationContext? I have a factory so that all book instances are spring-beans. I think it's a good decision to make all beans spring-beans. @Component public class BookFactoryImpl implements BookFactory { …
Pasha
  • 1,768
  • 6
  • 22
  • 43
1
vote
0 answers

How can I find eagerly created beans in Application Context?

I'm studying Spring IoC and I would like to raise a question. How can I view in ApplicationContext all created singletons? Since they are creating eagerly does it mean that they must exist in the container before .getBean() method is invoked on…
Pasha
  • 1,768
  • 6
  • 22
  • 43
1
vote
1 answer

Why isn't @PostConstruct invoked on a bean implemented BeanFactoryPostProcessor & ApplicationContextAware?

I've tried to create a Spring bean and log all possible stages of his lifecycle. But I've noticed that in this case a method annotated with @PostConstruct isn't invoked. I suppose it happens because BeanFactoryPostProcessor and…
Pasha
  • 1,768
  • 6
  • 22
  • 43
1
vote
3 answers

Spring IoC: Reasons to have null checks with constructor autowiring

What are the reasons to use null checks in spring autowring? For instance, I often see code like this: @Component public class MyComponent { private final MyService myService; @Autowired public MyComponent(MyService myService) { …
Sasha Shpota
  • 9,436
  • 14
  • 75
  • 148
1
vote
3 answers

How do you create a prototype-scoped @Bean with runtime arguments? With getBean(String name, Object... args)?

How do you create a prototype-scoped @Bean with runtime arguments? With getBean(String name, Object... args)? My question is a consequence of this question. Why is this approach not used or mentioned in the Spring IoC documentation? Is this a normal…
1
vote
0 answers

Handling Exceptions from spring context

How can i handle exceptions from Spring context . Consider the context
nanpakal
  • 971
  • 3
  • 18
  • 37
1
vote
2 answers

Why isn't @Autowired working in my Spring MVC @Controller?

I have a Spring MVC project going. I have a WebController that has an @Autowired service. When I run the web app on the server, the WebController is created but it doesn't autowire the service. Been really banging my head against a wall trying to…
user550738