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

Spring Boot Autowired null

I have several classes in a Spring Boot project, some work with @Autowired, some do not. Here my code follows: Application.java (@Autowired works): package com.example.myproject; @ComponentScan(basePackages =…
dexBerlin
  • 437
  • 3
  • 9
  • 22
10
votes
1 answer

What is a reason of warning: Autowired annotation is not supported on static fields

As well as I know, it is not possible to use @Autowired annotation for static fields using Spring. When I run my JBoss server, everything works well but I can see few warnings: Autowired annotation is not supported on static fields: private static…
ruhungry
  • 4,506
  • 20
  • 54
  • 98
10
votes
1 answer

Spring Autowire Annotation on Abstract class: No unique bean is defined

I've got an abstract class: @Component public abstract class BaseReport { public void export() { ... } And a bunch of classes that extend it, and override the export() method (or not). @Component public final class Report1 extends…
Robert Bowen
  • 487
  • 2
  • 13
  • 24
10
votes
3 answers
10
votes
5 answers

@Autowired and @Service working from controller but not from a different package

I need help understanding the concept behind @Autowired and @Service. I have a DAO defined with @Service and controller with @Autowired and everything seems fine, however, I use the same @Autowired in a different class then it does not work.…
birdy
  • 9,286
  • 24
  • 107
  • 171
9
votes
3 answers

Autowire depending upon the subclass

I have a abstract class AbstractService which has a reference to AbstractDAO class AbstractService{ protected AbstractDAO abstractDAO; } AbstractService will be extended by actual service classes like ServiceClassA , ServiceClassB etc, and…
Jeenson Ephraim
  • 551
  • 2
  • 9
  • 24
9
votes
1 answer

Spring does not abort bootstrapping on bean initialization Error when component scanning is enabled?

I have a web application with a spring configuration file. I have the following entry: The "flyway" bean is used to initialize and migrate the database.Now I have another bean…
Marcel
  • 710
  • 8
  • 23
9
votes
2 answers

Ensure spring bean loaded from non spring context

I have spring application alongside (jersey 2.6 classes and ) servlets . I need to get Spring bean(s) from jersey/non spring context, Similar question suggested to get context in a static wrapper of context public static ApplicationContext…
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
9
votes
2 answers

Parameter 0 of method setUserService in required a bean of type that could not be found

I have been through this issue and couldn't find what is going on.... tried to @ComponentScan, tried to name my services, none seems to work. Error: 03:35:05,193 WARN …
Cléber Oliveira
  • 119
  • 1
  • 1
  • 8
9
votes
5 answers

Spring autowired bean causes null pointer

I have a logger class that makes use of a service. Each time a new logger is created, I expect to have access to the singleton scoped logging service. I autowire the logging service into the logger however, a null pointer exception is returned. I…
robinjohnobrien
  • 1,092
  • 2
  • 11
  • 19
9
votes
2 answers

Cannot get UserDetailsManager injected with Spring Boot and Java-based Configuration

I have spring boot webapp that uses the Java-based configuration to configure a JdbcUserDetailsManager: @Configuration @EnableWebMvcSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired protected DataSource…
Jannik Jochem
  • 1,516
  • 1
  • 14
  • 28
9
votes
4 answers

Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService

I'm new to Spring so I been mucking around with security side of things. Everytime I run my application I get: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfig': Injection of autowired…
Aeseir
  • 7,754
  • 10
  • 58
  • 107
9
votes
4 answers

Can I autowire named loggers?

I'm using non static loggers named according to class name: protected Logger logger = LoggerFactory.getLogger(getClass()); Can I configure spring in a way, that will set proper logger using @Autowired? @Autowired protected Logger logger; I can use…
Kojotak
  • 2,020
  • 2
  • 16
  • 29
9
votes
5 answers

How to get Spring WebContext in class annotated @controller

In Spring MVC with annotation, we mark any POJO with @Controller. In this controller we can get WebApplicationContext, using autowired property. @Controller public class HomePageController { @Autowired ApplicationContext act; …
Kaushik Lele
  • 6,439
  • 13
  • 50
  • 76
9
votes
2 answers

Autowired spring bean is not a proxy

I'm working on a very small application connecting to a MySQL database. I'm trying to create table record but getting 'no transaction in progress'. I have all the right stuff in place: a service interface MyService and its implementation…
jakstack
  • 2,143
  • 3
  • 20
  • 37