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

How to ignore EI_EXPOSE_REP2 in case of spring autowired components

In my Spring Boot application, I use com.github.spotbugs:spotbugs-maven-plugin plugin. The spotbugs check reports no issues on following class: @Service public class FooService { @Autowired CocoComponent cocoComponent; @PostConstruct …
Ari Manninen
  • 306
  • 2
  • 7
10
votes
2 answers

How to inject(autowired) beans to map with enum as map key in spring?

I've learned that in spring, i can autowire/inject into Map by configured name like below: public interface DummyInterface{ } @Component("impl1") public class Impl1 implement DummyInterface{ } @Component("impl2") public…
user8510613
  • 1,242
  • 9
  • 27
10
votes
4 answers

Singleton and @Autowired returning NULL

I have a repository manager that manages my repositories. I have the @Autowired to instantiate my properties, but they are always null. The beans are correctly configured in my xml. Any reason why? public class RepositoryManager { …
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341
10
votes
3 answers

Spring @Autowiring with generic factory-built beans

I have a set of classes with a complex initialization scheme. Basically, I start with the interface I need to get a hold of, and then make a bunch of calls, and I end up with an object that implements that interface. In order to handle this, I made…
Brandon Yarbrough
  • 37,021
  • 23
  • 116
  • 145
10
votes
2 answers

How to refactor a codebase that uses spring autowiring

I've inherited two fairly non-trivial codebases that uses spring for configuring the applications. Now I need to reconfigure the applications. But lots of the configuration is provided through autowiring so it is almost impossible to find out what…
eirikma
  • 657
  • 5
  • 13
10
votes
2 answers

How to use autowired (@Autowired) references from main(String[] args) method?

I am trying to use an autowired reference from main class and am facing : Cannot make a static reference to the non-static field zipCodeLookupService. This is obvious. But I want to know how to handle this situation. What is the correct way of…
10
votes
5 answers

How to @Autowire services in SpringBoot

Good day, guys. I have a question about autowiring services into my classes when using Springboot. All of the examples I have seen on the Internet as well as in the Springboot specification do something of the like (taking an excerpt from the…
Greg
  • 403
  • 2
  • 6
  • 16
10
votes
1 answer

Rabbitmq camel spring boot auto config

I have camel and rabbitmq configured like the following and it is working. I am looking to improve the config setup. pom.xml org.apache.camel camel-rabbitmq-starter
Robbo_UK
  • 11,351
  • 25
  • 81
  • 117
10
votes
1 answer

Partial auto-wire Spring prototype bean with runtime determined constructor arguments

The javadoc to ConstructorResolver.autowireConstructor(...) says Also applied if explicit constructor argument values are specified, matching all remaining arguments with beans from the bean factory. but I can't get it to work. I get a…
whistling_marmot
  • 3,561
  • 3
  • 25
  • 39
10
votes
7 answers

Spring @Autowired not working

I have some problems wth autowire annotation. My app looks like this: Here is controller: @Controller public class MyController { @Autowired @Qualifier("someService") private SomeService someService; .... } It's a service…
Ilnur
  • 666
  • 1
  • 9
  • 18
10
votes
1 answer

Can't Autowire JpaRepository in Junit test - Spring boot application

Hi All I’m trying to execute a Junit test in a Spring boot application, the Junit should test some CRUD operations, I’m using Spring Repositories specifically JpaRepository. The Repository calss: package au.com.bla.bla.bla.repository; import…
Greg
  • 411
  • 2
  • 6
  • 15
10
votes
1 answer

How to choose what implementation get's injected in to an autowired constructor

Say I have an interface interface IPerson {...} I have two implementations of this interface @Component class Programmer implements IPerson {...} @Component class LionTamer implements IPerson {...} Say I have a class that uses Autowire…
Stewart
  • 3,023
  • 2
  • 24
  • 40
10
votes
4 answers

@Autowired not working inside a runnable

I have a runnable task where i am trying to Autowire field but when i do it the task doesn't run . When i Autowire the field outside the runnable it works fine . Why is this happening ? Also is there any other cleaner way to get new instances of a…
Evan Root
  • 279
  • 1
  • 5
  • 19
10
votes
2 answers

Spring autowire interface

I have an Interface IMenuItem public interface IMenuItem { String getIconClass(); void setIconClass(String iconClass); String getLink(); void setLink(String link); String getText(); void setText(String text); } Then I…
adi.neag
  • 633
  • 2
  • 12
  • 27
10
votes
1 answer

Spring - how to inject concrete interface implementation?

I need to inject by @Autowired concrete implementation of a service class. Service interface: public interface PostService { ... } Implementation: @Service("postServiceImpl") public class PostServiceImpl implements PostService { ... } Methods in…
tomdavies
  • 1,896
  • 5
  • 22
  • 32