Questions tagged [autowired]
Autowiring is a DI container feature where the dependencies are automatically looked for according to some criteria.
2,691
questions
1
vote
2
answers
38
views
How to mock behaviour of a bean used in @PostConstruct in @SpringBootTest
I have been searching for a while and I can't find a solution for this. I need to mock a class that is used in the @PostConstruct of another class. My classes are like this:
@Component
class A {
...
0
votes
1
answer
64
views
failed to run springboot. getting dependency injection error
in service layer when I inject DAO, it fails to run the server. tried clean cache and .gradle and clean build. jpa repository and kotlin reflect are also added as a gradle dependencies.
error log
...
0
votes
0
answers
34
views
Spring Autowiring on service got always problems
We have a really strange issue in our application and exhausted all options for troubleshooting, including checking for similar issues here on Stackoverflow. I simplyfied the code.
I have an Entity:
...
0
votes
0
answers
20
views
Bean named 'documentProcessorApiService' is expected to be of type 'DocumentProcessorApiService' but was actually of type 'com.sun.proxy.$Proxy146'
I have been battling this problem for a few days, using other suggestions I've found to no avail. I've tried using @EnableAspectJAutoProxy(proxyTargetClass = true) on the SpringApplication entry and ...
0
votes
1
answer
34
views
Is it possible to access a Symfony service's class name dynamically in yaml definitions (services.yaml)?
The Problem
I have a lot of classes that are children of a parent class.
The factory that I'm using to instantiate these children takes one parameter, a string that's the class name of the child so ...
0
votes
0
answers
15
views
Karate is not loading spring boot class with Autowired annotation
I have a requirement to automate apache kafka test where my development team is using @Autowired annotaion to load the beans.
@Component
public class getAccountsBuilder {
@Autowired
...
0
votes
0
answers
54
views
Passing Interface In Constructor Symfony PHP
I'm new to interfaces, could someone please advise when an interface is autowired in a method, since the interface has no functionality, where does the functionality come from in the method $logger-&...
2
votes
1
answer
39
views
How to inject dependencies in a class implementing Jobrunr ApplyStateFilter interface?
I am trying to implement a project using jobrunr. I have a use case where a service I have written should be triggered once the maximum retries are done for a job. I tried achieving the same using ...
0
votes
0
answers
35
views
Gradle Multi-module project : Beans are not getting scanned from other modules
Parent module
-- module 1
-- module2 (SpringBootApplication class resides here)
-- common module (Declared an interface ABC.java)
All my packages starts with com.xxx (in all modules) which I ...
1
vote
1
answer
106
views
Autowiring a javax.inject.provider in a unit-test with spring context
While playing around with the javax provider, I have created a spring configuration file with the following two Beans:
@Bean
Provider<Map<Integer, JsonNode>> worldMapDataProvider() {
//...
0
votes
1
answer
40
views
Spring, configure preferred bean to autowire when multiple instances are present
I've an interface being injected as bean into multiple components.
Three classes implement this interface which leads to ambiguity for spring to autowire the beans.
I would like a flexible way (...
1
vote
2
answers
49
views
Autowiring configuration class spring
I'm wondering whether it's possible to autowire a class annotated with @Configuration into any annotated class (@Component, @SpringBootTest, etc)? I know it's possible between @Configuration classes, ...
0
votes
1
answer
74
views
Can we use @Autowired annotation as a constructor argument? [duplicate]
In my case I am trying to use Environment class to read properties. I tried two options.
Option 1 - I tried to use @Autowired the Enviornment class as shown in the following example.
@Service("...
0
votes
1
answer
44
views
Debugging with Java/Spring's @Autowired on Eclipse
I have picked up a project that uses @Autowired and dependency injection a lot. People have been saying all the nice things about them. It seems kind of like a magic.
I am new to Spring injection and @...
1
vote
0
answers
18
views
why @Autowired has higher precedence than Aware callback methods in spring bean lifecycle?
since bean creation phases are as below:
Instantiation
Populating Properties(Spring scans the beans that implement Aware interfaces and starts setting relevant properties)
Pre-Initialization (Spring’...
0
votes
0
answers
48
views
Advice to track down cause of @Autowired being null
Looking through this question why-is-my-spring-autowired-field-null, it seems the most common reason why an @Autowired member object is null is because the containing class was created with "new&...
0
votes
0
answers
36
views
Symfony, API Platform custom operation Action, get Notice: Undefined property RequestStack
I'm using symfony 5 with API Platform to create Rest API.
I have an IIG entity and i'm trying to add a custom operation :
/**
* @ApiResource(
* shortName="iig",
* ...
0
votes
0
answers
25
views
Make Springboot @service class method access by only one thread at a time
I need to make my @service class a method can be access only one thread at a time. I can't add static synchronized keywords to the method due to that method call @Autowired another instances.
Please ...
0
votes
0
answers
35
views
@Transactional on class and getters/setters in @Autowired
when my code went through a code review, an error was pointed out.
code for example:
@Component
@Transactional
public class ClassA {
private NamedParameterJdbcTemplate jdbcTemplate;
@...
-2
votes
1
answer
56
views
Is there a way to pass down a variable in an Autowired Constructor?
To keep it as simple as Possible I have a class which I want to open threw another class. It needs some Services to be Autowired plus, because it is a Review view, it also needs a Variable of the ...
1
vote
2
answers
57
views
Api Platform/Symfony and PHPUnit - How to inject a Service into an ApiTestCase (multiple constructor arguments)
I have a BaseClass that extends the ApiTestCase of PHPUnit.
Now in order to generate the Endpoint-URLs, I would like to be able to get the IRI of a given Entity, so, naive as I am, I tried to autowire ...
0
votes
1
answer
124
views
Spring AuthenticationManager StackOverflowError with Kotlin
I have SecurityConfig for my application on Kotlin with Spring. So when I try to authenticate I get java.lang.StackOverflowError: null. I found it returns when runs this:
authenticationManager....
0
votes
1
answer
49
views
Springboot posgresql reposity bean can't be autowired
I have simple Sprinngboot app where actual database is PostgreSQL.
My model:-
@Table("carrier")
@Entity
public class MyCarrier {
@Id
@Column("id")
private UUID id;
@Size(
...
0
votes
0
answers
28
views
How to ignore or not to load up a class that is inside ContextConfiguration?
Spring Boot related issue:
My application MyApp was based on MQ so I also wrote my tests to fit it.
Now, I have changed the application to work with Kafka instead of MQ.
My tests load up classes as ...
0
votes
1
answer
37
views
Autowire the configuration class into another configuration class field
I have a configuration class RetryConfig , which uses configuration properties of class RetryConfiguration.
In class RetryConfig , I am creating one object SimpleRetryPolicy field, which needs one ...
0
votes
0
answers
36
views
SpringBoot console application doesn't work correctly [duplicate]
I've chcecked many tasks about that topic and there are two ways: my knowledge about SpringBoot is too poor or the first option + my problem is a little bit different than another.
My problem is :
...
0
votes
0
answers
24
views
Autowiring an implementation to a class vs interface
@Autowired
ObjectMapper mapper;
Spring Dependency Injection - since this field (mapper) is a class itself, why should it be autowired? It can help in testing, as we could inject a mock. Does it ...
0
votes
1
answer
120
views
Lombok SuperBuilder Spring Autowire Issue With Child Class
I have a parent class:
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@SuperBuilder
@Service
public class Parent {}
And a child class:
@Profile("integration")
@SuperBuilder
@...
2
votes
0
answers
162
views
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
...
1
vote
0
answers
51
views
Symfony calls unwanted constructor of my class when running command
Symfony 4.4, I want to keep some of my classes as "simple/pure" PHP class = no service and use just "new MyClass(..)" to initialize it inside my code.
What's more important, I want ...
0
votes
2
answers
48
views
Spring dependency inection or default value?
I have a class Car which has a dependency : Motor
My class Car is like this :
@Component
public class Car {
private Motor motor;
@Autowired
public Car(Motor motor) {
this.motor = ...
0
votes
2
answers
60
views
Springboot: Compilation error while autowiring the parent class
All,
I am trying to autowire a parent class which has a child class with additional methods. As far as I know, Spring will inject an instance of a child class to a parent class reference. To be sure, ...
1
vote
1
answer
38
views
DependencyInjection in AbstractEntity
i started working on a new Symfony 6.0 project.
I created a new Entity called Project. In this entity I want to set the created_by property automaticlly on PrePersist (hook) call...
Therefore I ...
0
votes
0
answers
32
views
Cannot Autowiring Spring MQTT
Spring 2.5.3 and Java 1.8
I want to send a json data to a mqtt topic but i cannot autowiring my Interface and i'm getting null pointer exception when i try with no autowiring.
When i try it this ...
0
votes
1
answer
32
views
Symfony5: Recommended pattern for using DataTransformers within Entities
I am currently trying to make our Symfony project type-safe and thereby refactoring it a bit, because it uses some anti-patterns here and there. My problem is that I cannot come up with a good pattern ...
0
votes
1
answer
430
views
Spring Boot - nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type '' available
I'm trying to add the following statement to a Spring Boot service:
@Autowired
private ApELDatabasePublisherService eventPublisher;
The dependency for eventPublisher is contained in maven, in this ...
0
votes
1
answer
57
views
Spring boot autowired service all variable fields are null
Currently I have many spring boot services annotated with @Service.
Every service works fine and there are no problems. There is a problem only with LogsService. LogsService is implemented the same ...
0
votes
0
answers
15
views
What implementation is used when Autowiring the scheduler interface in Quartz Scheduler?
@Autowired
private Scheduler scheduler;
I found multiple implementations implementing the Scheduler interface (like RemoteScheduler, stdScheduler). So which one is actually being used in Spring?
When ...
0
votes
0
answers
69
views
Property of class with @Component annotation can't be injected without @Autowired annotation
I have a seemingly basic question of Spring, and I googled a couple of hours but found no clear explanation.
There is a bean with id being transactionTemplate declared in one XML file and there is a ...
1
vote
2
answers
393
views
Mocking autowired dependencies with Mockito
I'm writing unit tests for a Spring project with Junit 5 and Mockito 4.
I have to test a class that takes 2 objects via constructor and other 2 via @Autowired. I need to mock those 4 objects, so I ...
0
votes
0
answers
51
views
Excluding @bean from ComponentScan
I have lot of beans declared in a single class
package com.example;
@Configuration
public class MainBeanClass{
@Override
@Bean("cachingSession")
@Lazy
public CqlSessionFactoryBean ...
0
votes
1
answer
73
views
Use Bean in Static Method
I have a Utility class and I need to inject a bean in Utility class and use it in a static method of the Utility class.
I found a couple of solutions, but they are not working in our project. However, ...
0
votes
1
answer
186
views
How to pass parameter to a @Component class which can't be autowired in Spring Boot
I am building a desktop application using JavaFx and Spring Boot and I am stuck at some problem
I have @Component class Translator which extends Task<String> and makes an api call to google ...
0
votes
1
answer
201
views
How to autowire a bean with condition
I have a service. I want to autowire a policy bean in my service.
@Service
class MyService {
@Autowired
Policy myPolicy;
}
The policy is an interface. It has 3 subclass.
interface Policy {
...
0
votes
0
answers
23
views
How to use class generic in autowiring interface generic?
im trying to realize simple database save logic using java generics in springboot. I create an utility interface with generic which I extend in another interface and implement in class. in classes ...
1
vote
0
answers
60
views
Spring boot @Autowired vs Dynamic Polymorphism in case of loose coupling?
Hi I guess this question is quite basic but please help out!!!
Let say I have one interface Write and 2 implementing classes Pen and Pencil
public interface Write {
public void writeSomething(...
0
votes
1
answer
257
views
Can't find KafkaTemplate bean, even though I've defined one
My environment context looks like this:
- Spring Boot v2.5.12
- Maven Multi Module project (this is a module, it imports its Spring Boot dependencies from the parent pom)
- JDK 11
And the error that ...
0
votes
1
answer
133
views
problem with using autowired annotation in spring
In the following code, my problem is that although the field in the BaseBallCoach has @Autowired and @Qualifiere, it still gives an error and says expected single matching bean but found 2. What is ...
0
votes
1
answer
749
views
Spring core/beans 5.3.18 upgraded project won't start - Autowired and Bean annotations crashing
here's the error:
SEVERE [main] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [com.mycompany.chassis.engine.core.web....
1
vote
1
answer
436
views
Feign Client being ignored during component scan
I am creating a feign client to hit an external service. I added the following dependencies to my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http:/...