Questions tagged [autowired]

Autowiring is a DI container feature where the dependencies are automatically looked for according to some criteria.

In a like , the beans to be injected can be explicitely configured or they can be searched for automatically in what is called "autowiring".

Although the concept is not exclusive to Spring, the bulk of questions in Stack Overflow and Google seem to be directed towards this framework.

Spring

In the particular case of Spring, when "autowiring" is enabled, the container will look in the current ApplicationContext for a bean that matches the type/name of the corresponding setter method.

Autowiring can be configured globally or on each bean to be disabled; or enabled by type, by name, by constructor type. It can also be configured using the Autowired annotation.

2781 questions
16
votes
6 answers

Spring Autowiring only works with Interface

I am quite new to spring framework and came across the following issue. I have an interface ClassA, which is implemented by classed ClassA1 and ClassA2. I have the following bean definition added to applicationContext.xml
Chaitanya
  • 2,396
  • 4
  • 29
  • 45
16
votes
5 answers

@Autowired object gets a null value in one class, while successfully wired in another

I am working on a project using Spring 3, and Spring Security. My problem is with IoC container. Problem started when I wrote my own implementation of UserDetailsService for Spring Security-3. I checked the other questions but still could not solve…
Ugur Adigüzel
  • 203
  • 1
  • 2
  • 13
16
votes
3 answers

Symfony AutoWire multiple services same class

i am in the process of upgrading a large application to 4.2 and the $this->get(".....") from inside the controller is deprecated and one should use AutoWire instead. i am running into the problem that i have 2 services, which are in fact from the…
Helmut Januschka
  • 1,578
  • 3
  • 16
  • 34
16
votes
1 answer

symfony: autowiring an interface

What do I need to in order to make this work? interface BaseServiceInterface { public function getRecords(); } class BaseService implements BaseServiceInterface{ public function getRecords(){ return "bla"; } } class…
Adam Novakovi
  • 759
  • 1
  • 9
  • 18
16
votes
1 answer

spring boot autoconfiguration with jdbc template autowiring dataSource issue

I'm new to Spring and to J2EE in general. I'm having trouble using JDBC template with Spring Boot autoconfiguration. What I did was I took the example of RESTful web service provided here and decided to extend it to use JDBC template relational…
Marek
  • 1,413
  • 2
  • 20
  • 36
16
votes
4 answers

Spring creating multiple instances of a singleton?

I have a graph of Spring beans which autowire each other. Heavily simplified illustration: ... public class Foo { @Autowired Bar bar; @Autowired Baz…
mindas
  • 26,463
  • 15
  • 97
  • 154
15
votes
4 answers

Spring autowiring setter/constructor PROs and CONs

When using @Autowired (not xml configuration), could someone compare the set/constructor binding advantages and disadvantages? See the following examples: public class Example{ private Logger log; // constructor wiring @Autowired …
user689842
15
votes
3 answers

Spring boot Autowired annotation equivalent for .net core mvc

Question mentions it all. In spring boot I am able to use the AutoWired annotation to automagically inject a dependency into my controller. class SomeController extends Controller { @AutoWired private SomeDependency someDependency; } For…
BossmanT
  • 559
  • 1
  • 6
  • 17
15
votes
2 answers

How to autowire @ConfigurationProperties into @Configuration?

I have a properties class defined like this: @Validated @ConfigurationProperties(prefix = "plugin.httpclient") public class HttpClientProperties { ... } And a configuration class like this: @Configuration @EnableScheduling public class…
Daniel
  • 2,050
  • 7
  • 31
  • 55
15
votes
5 answers

How to autowire an object in spring in an object created with new

all I want to do is autowire the field backgroundGray in the NotesPanel class, but all I get is the exception below. So, question is, how to autowire it correctly ? It really drives me crazy because it's probably something very stupid I'm doing…
user1119859
  • 669
  • 2
  • 9
  • 20
15
votes
3 answers

@Autowired(required=false) on constructor giving NoSuchBeanDefinitionException

In a Spring application, I have used @Autowired(required=false) on constructor. This means that if the bean that will be autowired is not available in the xml file, no NoSuchBeanDefinitionException should be thrown as (required=false) is mentioned.…
user1501192
  • 151
  • 1
  • 1
  • 4
14
votes
1 answer

Autowiring of beans generated by EasyMock factory-method?

I have a problem that seems really strange to me. I have the following setup: An interface: package com.example; public interface SomeDependency { } A spring component: package com.example; @Component public class SomeClass { } A spring test…
matsev
  • 32,104
  • 16
  • 121
  • 156
14
votes
3 answers

How to implement OR logic for spring qualifiers?

I have following configuration: @Qualifier1 @Qualifier2 @Bean public MyBean bean1(){...} @Qualifier2 @Qualifier3 @Bean public MyBean bean2(){...} @Qualifier1 @Qualifier2 @Qualifier3 @Bean public MyBean bean3(){...} @Qualifier3 @Bean public MyBean…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
14
votes
4 answers

Spring+Hibernate, Autowire sessionFactory into hibernate DAO

i have an Hibernate DAO, in according with Hibernate API 3 and Spring 3.x, I use simply a sessionFactory and NOT an HibernateDaoSupport+getHibernateTemplate() - i hope this is a good choice... - Now my goal is to autowire sessionFactory into my DAO…
blow
  • 12,811
  • 24
  • 75
  • 112
13
votes
1 answer

Spring Data Repository autowiring fails

I'm working on this problem for quite some time, and can't get it to work. Hope some of you could spare your time to help me. The scenario I'm building a web application which uses Spring MVC. This webapp ist supposed to use another Maven project,…
Makenshi
  • 511
  • 1
  • 6
  • 12