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

Spring @Autowired confusion (container or session)

In My app I am using a User bean that is Autowired to my service MyService and its used as the principle logged in user's info (So the user is not coming as a static bean from an xml but dynamically generated from a logged in user) If there are ten…
sarmahdi
  • 1,098
  • 4
  • 21
  • 61
13
votes
8 answers

How to use Spring Autowired (or manually wired) in Scala object?

I am trying to use Spring with Scala. I know Autowired works with Scala class, but I am using a web-framework that requires an object and I want to inject a dao into it. I wonder how to do this? Sorry, I am quite new to Scala, thanks in advance. …
bernardw
  • 1,370
  • 3
  • 15
  • 27
13
votes
1 answer

how to instantiate spring data jpa repository without autowired

I have my repository interface as import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository public interface MyRepository extends JpaRepository{ } and the service…
Navdeep Singh
  • 151
  • 1
  • 2
  • 7
13
votes
2 answers

Symfony 3.4 autowire service

Am developing a mini app in Symfony 3.4. Am putting together an authentication process using Guard. I have created a class called LoginFormAuthenticator which extends AbstractFormLoginAuthenticator. Receiving error: Cannot autowire service…
Behzad Lashkari
  • 177
  • 1
  • 9
13
votes
1 answer

How does the @Autowired interface, which extends CrudRepository, works? I would like to have some insights

Suppose my interface extends CrudRepository as follows @Repository public interface EmployeeRepository extends CrudRepository { } and I use the EmployeeRepository interface in my Service class as follows…
Pawan Patil
  • 1,067
  • 5
  • 20
  • 46
13
votes
2 answers

Spring BeanCreationException : Bean instantiation via factory method failed nested exception

I'm getting start with Spring and I'm trying to build an app using Security, Hibernate and Thymleaf. I have this error that stuck me for days. Here are the logs : org.springframework.beans.factory.BeanCreationException: Error creating bean with name…
ValentinD
  • 143
  • 2
  • 3
  • 11
13
votes
2 answers

Autowiring a service into a validator

This example is a bit contrived; I've simplified it to remove extraneous details and to focus on the problem I am having. I have a validator that looks like this: @Component public class UniqueUsernameValidator implements…
Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
13
votes
1 answer

difference between dependency injection and autowiring

Can I know what is the difference between dependency injection and autowiring? Whether autowiring is different from dependency injection? Which is the best way to autowiring(XML based or annotation based)?
bharathi
  • 6,019
  • 23
  • 90
  • 152
13
votes
2 answers

autowire boolean primitive from properties file

Hi I want to autowire boolean value from properties file have referred following link with maps url Spring properties (property-placeholder) autowiring but I want to auto wire a boolean property, also have referred question Spring Autowire primitive…
Aniruddha
  • 161
  • 1
  • 1
  • 7
13
votes
3 answers

How do I autowire a Spring TaskExecutor created thread?

According to Spring's documentation the way to use the TaskExecutor is as follows: import org.springframework.core.task.TaskExecutor; public class TaskExecutorExample { private class MessagePrinterTask implements Runnable { private String…
Jorge
  • 1,924
  • 2
  • 14
  • 11
12
votes
3 answers

How do I update the value of an @Autowired String bean in Spring?

I have a String that I'm autowiring as a bean. The value for the String is set via a properties file, and is loaded at runtime. That much I can verify. Here's my XML:
Pat
  • 2,228
  • 3
  • 24
  • 33
12
votes
2 answers

Symfony 4 argument has no type-hint, you should configure its value explicitly

Symfony 4.2.3 Recently upgraded from version 3.4 to 4.2.3 and got my project working, but when setting autoconfigure in services.yaml to true, I will receive this error message: Cannot autowire service…
RoyRobsen
  • 457
  • 1
  • 9
  • 20
12
votes
7 answers

Spring: create LocalDate or LocalDateTime from @Value parameter

In a spring project, I'd like to create a LocalDate from an @Autowired constructor parameter whose value is in a .properties file. Two things I'd like to do: 1. If the property file contains the property my.date, the parameter should be created by…
Josh
  • 4,726
  • 2
  • 20
  • 32
12
votes
3 answers

required a bean of type 'org.springframework.security.core.userdetails.UserDetailsService' that could not be found

When launching with mvn spring-boot:run or even with gradle returns that issue. *************************** APPLICATION FAILED TO START *************************** Description: Field userDetailsService in…
b.lopes
  • 435
  • 1
  • 7
  • 17
12
votes
1 answer

How to inject RestTemplate

I am not using xml configurations to define beans. Instead using component scanning and autowire to define and inject dependencies. RestTemplate is part of springframework. How can I inject this class ?
Ravi
  • 323
  • 2
  • 6
  • 18