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
3
votes
1 answer

Spring Unsatisfied dependency Errors

EDIT I am updating this with new information that is more relevant to finding an answer. The problem is that Spring is failing to contruct my beans given that there isn't a qualifying bean. The thing is, I don't know why it would need a bean for the…
moonboy
  • 1,296
  • 4
  • 16
  • 29
3
votes
1 answer

Circular dependency in Spring injection - Is this bad design?

I am stuck with following issue : I am trying to create beans as follows: @Bean public abc createABC() { return new ABC(--, def(),--); } ` @Bean public DEF def() { return new DEF(--, createABC(),-- } Any suggestions to get around this…
user3681970
  • 1,201
  • 4
  • 19
  • 37
3
votes
1 answer

Update bean property at runtime

I have a bean that holds some configuration: public class CustomerService{ private Config config; @Required public void setConfig(Config config){ this.config = config; } } public Config { private String login; private String…
romanvintonyak
  • 351
  • 1
  • 3
  • 17
3
votes
2 answers

Error creating bean with name 'application', No default constructor found; nested exception is java.lang.NoSuchMethodException

I don't quite understand why this code gives me 'no default constructor found' error. The constructor is @Autowired. Everything seems to be injected correctly. Can anybody please help? Thanks @SpringBootApplication public class Application { …
Deniss M.
  • 3,617
  • 17
  • 52
  • 100
3
votes
4 answers

Autowire doesn't work for custom UserDetailsService in Spring Boot

The spring boot apps starts up, tomcat runs, and then it throws an error before finally dying. Error Running my app gives me this Autowired error: 2016-07-29 02:18:24.737 ERROR 44715 --- [ restartedMain] o.s.boot.SpringApplication :…
Amin Shah Gilani
  • 8,675
  • 5
  • 37
  • 79
3
votes
3 answers

How long does an spring initialized bean live?

When i run the first petittion of a bean's method (let's say method A) on the server everything seems ok, but when running for the second time any petition on this carrierRESTWS bean (let's say method B), the dao being used is the same carrierDAO…
LuGaNO
  • 99
  • 1
  • 2
  • 11
3
votes
2 answers

Spring MVC Test failing

I am trying to run a Spring MVC Test but keep getting this exception. org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException The exception is occuring because the autowired…
kellzerIrl
  • 103
  • 1
  • 10
3
votes
2 answers

Spring recursively loading application context

I want to invoke a method after the application context is loaded. I used ApplicationListener interface and implemented onApplicationEvent. applicationContext.xml
Lolly
  • 34,250
  • 42
  • 115
  • 150
3
votes
0 answers

How to use a Builder Pattern with Spring Injection?

TL;DR: How can I use composition a Builder Pattern with Spring IoC? I am creating a Spring project that populates a table based on distribution parameters for some fields (i.e. 50% of records must be of type A, 40% of type B, 10% of type C; For each…
Tarek
  • 3,080
  • 5
  • 38
  • 54
2
votes
1 answer

Why self-inject is required for class calling own @Transactional method, but is not required for @Bean methods to ensure single instance creation?

It' well-known that @Transactional or any other AOP around the method won't work if it was called from inside of the same class. And explanation is clear and always made sense to me: the proxy wraps a real basic Java object. All the other clients of…
Kirill
  • 6,762
  • 4
  • 51
  • 81
2
votes
0 answers

Is there a way to wire up Spring IoC to use a method reference as a service to inject as a functional interface?

I'm trying to find the most direct way to satisfy a dependency of type Function. There happens to already exist a class with a static method that conforms to this exact signature. I'd like to wire the two directly together without…
jpierson
  • 16,435
  • 14
  • 105
  • 149
2
votes
1 answer

Magic behind @ComponentScan and @Component

I'm still learning spring dependency injection in depth. My first class is a configuration class, where i declare to the container to load and manage the beans declared in the annotated methods. package ioc.question_004; import…
xmen-5
  • 1,806
  • 1
  • 23
  • 44
2
votes
1 answer

@ComponentScan annotation works for non @Configuration classes

Spring reference documentation says the following: Spring can automatically detect stereotyped classes and register corresponding BeanDefinition instances with the ApplicationContext ... To autodetect these classes and register the corresponding…
Laplas
  • 687
  • 1
  • 7
  • 10
2
votes
1 answer

Spring factory bean for implementations with different dependencies

Imagine I have a Storage bean, which incapsulates logic, related to storing my entities. public interface Storage { Object get(String id); String save(Object obj); } And I have 3 implementations: public FileStorage implements Storage { ... }…
Rahul
  • 1,727
  • 3
  • 18
  • 33
2
votes
0 answers

Spring instance is not starting if one of the route-builder instance is failed

We are initializing the 2 different camel routes via spring context xml,
Raghavan
  • 401
  • 6
  • 21
1 2
3
12 13