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
12
votes
3 answers

Autowire Spring bean implementing two interfaces

Is it possible to have a Spring Bean implement 2 interfaces and be able to autowire that bean using either interface? I have the following two interfaces: public interface ServiceA {} public interface ServiceB {} Two controllers which use…
scarba05
  • 2,943
  • 1
  • 27
  • 29
12
votes
1 answer

How do I autowire 3rd party classes with annotations in Spring?

The majority of examples on Spring Boot I've found focus on building simple web applications. That is, web applications where you are in complete and utterly control of everything. On the other side, I have not had much luck in finding examples on…
sbrattla
  • 5,274
  • 3
  • 39
  • 63
12
votes
2 answers

Spring 3 Annotations - HibernateDaoSupport - Repository Requires Session Factory

I am getting an exception saying : java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required When trying to use the @Repository annotation on a HibernateDaoSupport class. The error message is straightforward, in…
walnutmon
  • 5,873
  • 7
  • 42
  • 57
12
votes
1 answer

Spring fallback bean implementation

I'm currently trying to configure Spring Boot (using Java Annotations and ComponentScan) for the following scenario: Scenario There's an interface MyService. I want to provide a default implementation for MyService, let's call it…
Martin Häusler
  • 6,544
  • 8
  • 39
  • 66
12
votes
2 answers

Spring 3.2 annotation autowiring with multiple constructors

Spring docs: Only one annotated constructor per-class can be marked as required, but multiple non-required constructors can be annotated. If I have one autowired constructor, all is fine. If I have two or more autowired, but required=false…
dsplynm
  • 593
  • 1
  • 8
  • 16
12
votes
3 answers

Spring @Autowired fails in case of Cobertura instrumented class

Question Cobertura instrumentation is breaking springs autowiring in a specific case. Does anyone know how to resolve this? Scenario I am running MVN 3.0.4 with the cobertura-maven-plugin version 2.5.1. mvn test runs without issues mvn compile,…
elyzion
  • 133
  • 2
  • 8
11
votes
2 answers

Spring and @Autowired on a DelegatingFilterProxy

I'm trying to inject a spring bean into a filter, but can't make it work. The bean injected is always "null". I succeed autowiring this same bean in Controllers and HandlerInterceptors so it's correctly annotated. The filter class is under the same…
metacortechs
  • 141
  • 1
  • 1
  • 6
11
votes
7 answers

@Autowire is not working in Spring security Custom Authentication provider

We have Spring MVC application. We are trying to integrate the Spring security in it. We have written our custom authentication provider which will do the work of authentication. Below is the code for my custom authentication provider. public…
ajm
  • 12,863
  • 58
  • 163
  • 234
11
votes
4 answers

benefit of @Autowired annotation in Java

Maybe, because of my wrong English, I couldn't understand the benefit of using @Autowired annotation. According to the tutorial we can simplify the first(I.) case to second case(II.) by means of @Autowired. My question is, what is the meaning of the…
cscsaba
  • 1,279
  • 3
  • 20
  • 31
11
votes
2 answers

Is it possible to exclude multiple directories when using Symfony autowire?

When using autowire in Symfony 4 I used this working code: App\: resource: '../src/*' exclude: '../src/{Domain,Entity,Migrations,Tests}' That code excludes from the autowiring all this folders: - src/Domain - src/Entity - src/Migrations -…
Diguin
  • 835
  • 8
  • 17
11
votes
1 answer

JMeter, JUnit and Spring Java configuration

Is it possible to run JMeter with the JUnit plugin/sampler and Spring Java configuration? When I try to do this, the Spring autowired beans are not being created and although the test case runs, because the beans have not been created, I get null…
Joe
  • 121
  • 1
  • 8
11
votes
2 answers

Spring Boot multi module Maven project @Autowired does not work

This is really strange. I started my Spring Boot project as a single maven project and all worked perfectly. Basically it is a Spring MVC app with security and mail. Then when I saw that some components like service, repository, model will be reused…
ACV
  • 9,964
  • 5
  • 76
  • 81
11
votes
2 answers

How does spring autowire generic converters?

Occasionally I've noticed interesting thing: I've implemented spring Converter interface: @Component public class MyConverter implements Converter { @Override public MyClass2 convert(MyClass1 source) { // doesn't…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
11
votes
2 answers

How to @Autowire objects in Validator classes?

Is it possible to Autowire an object in a Validation class? I keep getting null for the object that is supposed to be Autowired...
wuntee
  • 12,170
  • 26
  • 77
  • 106
11
votes
2 answers

Using @Autowired with AspectJ and Springboot

I want to use @Autowired annotation into an "Aspect". I want to inject a repository in my aspect but when I try to call a method of my autowired class a NullPointException occurs. @Aspect public class AspectSecurity { @Autowired private…
maxiplay
  • 427
  • 1
  • 5
  • 13