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

How to use Session Scoped Component in Controller

Count.java: @Component @Scope(value = "session",proxyMode = ScopedProxyMode.TARGET_CLASS) public class Count { Integer i; public Count() { this.i = 0; } Controller: @Controller public class GreetingController { @Autowired…
cdxf
  • 5,501
  • 11
  • 50
  • 65
5
votes
1 answer

How can I inject an instance of List in Spring?

What works Suppose I have a spring bean definition of an ArrayList:
yankee
  • 38,872
  • 15
  • 103
  • 162
5
votes
4 answers

Proper way to inject parent class dependencies with Spring annotations

I have following code - Dao.java @Component public class Dao extends NamedParameterJdbcDaoSupport { } dbContext.xml
Kshitiz Sharma
  • 17,947
  • 26
  • 98
  • 169
5
votes
3 answers

Spring bean map with dynamic keys and values

Right now i've application related data in spring bean map and passed this map to other classes as ref. Map is defined as below
Javee
  • 71
  • 1
  • 1
  • 8
4
votes
3 answers

Is a spring bean created with NEW really a singleton

I created a spring bean in a configuration class like this: @Bean MyClass getMyClass() { MyClass mc = new MyClass() return mc; } Whenever MyClass is autowired in another class that needs it injected, will it always create a new object by…
Hary
  • 1,127
  • 4
  • 24
  • 51
4
votes
1 answer

How to implement a bean-post processor that call destroy methods on prototypes?

I'm reading Spring documentation and found this One possible way to get the Spring container to release resources used by prototype-scoped beans is through the use of a custom bean post-processor which would hold a reference to the beans that…
Pasha
  • 1,768
  • 6
  • 22
  • 43
4
votes
1 answer

Inject all beans with a specific annotation

I've been using Spring for decades, but never ran into this use-case before. Is there a way to inject all the beans annotated with a specific annotation, e.g. all beans with @Service or all with @CustomAnnotation? The only idea I have is to inject…
kaqqao
  • 12,984
  • 10
  • 64
  • 118
4
votes
2 answers

AppConfig.java return bean with private constructor?

Having a AppConfig.java without annotation-scanning because of security and and without configuration via an app-config.xml because of harder-binding, I create instances of spring-beans like this: @Configuration public class AppConfig { @Bean …
Grim
  • 1,938
  • 10
  • 56
  • 123
4
votes
1 answer

ServiceLocatorFactoryBean Default instance

How do we tell Spring ServiceLocatorFactoryBean to provide the default instance of a service? I have a scenario like this. package strategy; import model.Document; public interface IPrintStrategy { public void print(Document document); } and 2…
Anand PN
  • 81
  • 3
4
votes
1 answer

Scope of and in hierarchical contexts

I have read: Multiple component-scan What is the difference between ApplicationContext and WebApplicationContext in Spring MVC? @RequestMapping annotation not working if is in application context instead of dispatcher…
Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
4
votes
2 answers

Annotating WebSecurityConfigurerAdapter with @Configuration causes config to be invoked twice

When I create a WebSecurityConfigurerAdapter it is getting registered twice. I've created a configuration exactly the same as the Hello Web Security Java Configuration example from the reference docs. The configuration is working as expected, though…
Brett Ryan
  • 26,937
  • 30
  • 128
  • 163
4
votes
1 answer

Two beans with the same name results in ConflictingBeanDefinitionException despite using @Primary

I have an application initializer class that is used to insert application specific data to database. @Component("applicationInitializer") public class ApplicationInitializer { @PostConstruct public void init(){ // some clever code…
fracz
  • 20,536
  • 18
  • 103
  • 149
4
votes
1 answer

How to share instances between Prototypes (Spring LoC)

To run a Job in a TaskExecutor I need to instantiate new Jobs implementing the Runnable Interface. To solve this, i will create a new Spring Prototype Bean named Job "on Demand". But in my application a Job has two fields LocationChanger and…
d0x
  • 11,040
  • 17
  • 69
  • 104
4
votes
2 answers

BeanPostProcessor with @Bean annotation not working

I'm trying to create a BeanPostProcessor for registering some values to a Map. The BeanPostProcessor works fine if I'm create the bean instance via xml definition, but if I change the bean definition to @Configuration it is not…
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
3
votes
4 answers

Spring can't find Autowired interface implementation

I have a main SpringBootApplication class here: package com.example.springproj; @SpringBootApplication public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); } } @RestController class…
1
2
3
12 13