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
8
votes
2 answers

What's the difference between @Autowired and getting a bean from the application context?

I have a dao unit test that is declared as follows: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:spring/applicationContext.xml"}) @TransactionConfiguration(transactionManager = "transactionManager",…
Eric
  • 1,023
  • 1
  • 15
  • 27
8
votes
2 answers

Is Spring's @Autowired a huge performance issue?

I have a project that has... I dunno... 200-300 daos/services/controllers and I use @Autowired to wire everything together rather than specify everything in the applicationContext.xml. My question is, how much of a performance impact does this have…
egervari
  • 22,372
  • 32
  • 121
  • 175
8
votes
5 answers

Why does Autowiring not function in a thread?

I've made a maven project in Spring 3.0, I've made some DAO, services and controllers, in one of mine controller I call a service in which I start a thread, the problem is that in the thread I declare a "service variable" that should be initialized…
user942458
  • 141
  • 1
  • 1
  • 5
8
votes
2 answers

@Autowired says field injection not recommended

can anyone tell me why @autowired is saying field injection is not recommended and the TextWriter object 'text' also says it could not autowire because there is more than one bean of textwriter type. @RestController public class HelloWorld{ …
Wizard
  • 462
  • 1
  • 6
  • 14
8
votes
4 answers

Ignore a class in a autowired directory

I have an Exception somewhere in my service/ folder, and Symfony is trying to autowire it : Cannot autowire service "App\Service\Order\Exception\StripeRequiresActionException": argument "$secretKey" of method "__construct()" is type-hinted…
Raphaël Malié
  • 3,912
  • 21
  • 37
8
votes
3 answers

How can I make a symfony 4 command to be registered only in dev environment and disabled in prod?

In my App I have a helper class App\Command\GenerateFixturesCommand that provides a command named my-nice-project:generate-fixtures. This command consumes a service of my own project named App\Services\CatalogFixtureGenerator that generates 1000…
Xavi Montero
  • 9,239
  • 7
  • 57
  • 79
8
votes
3 answers

Hibernate entity autowire

Can you please advice me, how can I nicely enable Spring autowiring for Hibernate entities? Let's say I have an entity and would like to have mail-sender there: @Entity public class EmailActivity extends Activity { @Autowired @Transient …
Rosty Kerei
  • 1,014
  • 1
  • 9
  • 16
8
votes
2 answers

Get service via class name from iterable - injected tagged services

I am struggling to get a specific service via class name from group of injected tagged services. Here is an example: I tag all the services that implement DriverInterface as app.driver and bind it to the $drivers variable. In some other service I…
povs
  • 93
  • 2
  • 6
8
votes
2 answers

How to Autowire a Component which is having constructor with arguments in SpringBoot Application

I have a class having Autowired Constructor. now when i am autowiring this class object in my class. how do i pass arguments for constructor?? example code: Class having Autowired Constructor: @Component public class Transformer { private String…
Radhi
  • 6,289
  • 15
  • 47
  • 68
8
votes
3 answers

How to make an @WebService spring aware

I have a Web Service which I am trying to Autowire a variable into. Here is the class: package com.xetius.isales.pr7.service; import java.util.Arrays; import java.util.List; import javax.jws.WebService; import…
Xetius
  • 44,755
  • 24
  • 88
  • 123
8
votes
5 answers

Symfony 4 - how to use service tags when autowiring an entire path

I'm working on a bundle for Symfony 4 that is structured like this: \Acme \FooBundle \Article \Entity - Article.php - Comment.php \Form - ArticleType.php \Repository - ArticleRepository.php …
VMC
  • 1,378
  • 4
  • 16
  • 32
8
votes
6 answers

@Autowired objects getting null value

Trying to set up a project but fail at Autowiring objects through Spring. package se.hsr.web; public class TestRunner { public static void main(String[] args) { ContactDAO cd = new ContactDAOImpl(); Contact contact = new…
Soroush Hakami
  • 5,226
  • 15
  • 66
  • 99
8
votes
1 answer

Spring Boot Oauth2 Extending DefaultTokenServices

I have an OAuth2 implementation that is working fine for the grant type = password. Now I need to add a logic of restricting the same user/password combination to be allowed to login again if the user is logged in earlier. For that, I researched and…
i_raqz
  • 2,919
  • 10
  • 51
  • 87
8
votes
3 answers

Spring boot 2 @Transactional annotation makes Autowired fields null

I'm trying to use @Transactional annotation in a method on my service to lazily load a field. However using @Transactional on my Implementation class makes all autowired fields null. Here is my implementation : @Service public class UserServiceImpl…
Mohamed
  • 113
  • 1
  • 2
  • 7
8
votes
6 answers

Autowiring :expected at least 1 bean which qualifies as autowire candidate for this dependency

Okay, I know that there are many questions asked around the same topic. But I cant seem to make anything work. It also might be the case that I am yet to completely understand the auto wiring concept. My Problem: I am able to get to the required…
User-8017771
  • 1,512
  • 1
  • 11
  • 17