Questions tagged [autowired]
Autowiring is a DI container feature where the dependencies are automatically looked for according to some criteria.
autowired
2,811
questions
-1
votes
0
answers
32
views
Is it possible to use Reflection along with @Autowired annotation to access to fields of a private class?
I am writing tests for a project and I want to access to private field of a class that otherwise should not be accessed. The reason behind this is that I don't want to fill the database with ...
1
vote
1
answer
33
views
Consider defining a bean of type service in your configuration
I have been learning Spring Boot for a week now yesterday I faced an error
`
Field db in com.example.test.tutorial.TutorialApplication required a bean of type 'com.example.test.tutorial.DB' that could ...
-1
votes
0
answers
20
views
why string1 is null when getting it from ApplicationContext and manually setting it into String1 type of variable, in springBoot project
I'm trying to understand why this code is throwing Nullpointer
exception.
This is callback1 class, has String1 as setter dependency. I'm setting this manually by taking it from ApplicationContext and
...
0
votes
0
answers
43
views
Using @Autowired in abstract class with generics: 'No beans of Generic type found' warning in IntelliJ but autowiring still works
Edit: One detail I missed out. The warning that I'm seeing is reported by IntelliJ. I have also seen others mention using the Spring Data plugin but I already have that.
Let's say I have ten ...
0
votes
2
answers
59
views
Java spring bean is getting created and added to the context but not @Autowired
I have a JavaFX application with Spring. I have a bean in a Configuration class which is being correctly added to the SpringContext, and can be retrieved manually, but it is not getting autowired into ...
0
votes
2
answers
48
views
Spring Boot @PrePersist Listener: "this.partido" is null
I'm a beginner in Spring and I'm trying to use a @PrePersist listener to validate a Partido entity before it is saved to the database. However, I keep encountering the error: java.lang....
0
votes
0
answers
29
views
Spring refresh an autowired bean during runtime
I have a property that i need to change on the fly.
As beans are created and autowired on startup, even if i change the bean during runtime is not taking into effect.
Ex:
Class serviceA {
Instant ...
-1
votes
1
answer
38
views
@Autowired component Null [duplicate]
I don't know why, but my @Autowired component (jwtService) returns a NullPointerException.
Here is my code:
This is my JwtTokenValidator class:
@Component
@AllArgsConstructor
@NoArgsConstructor
public ...
2
votes
0
answers
46
views
How to autowire a Spring Boot bean depending on a request attribute?
I'm working on a Spring Boot application where I have two implementations of a particular service, a real one and a proxy one. The interface looks like this:
@Service
public interface RefundService {
...
1
vote
1
answer
33
views
@Autowire on singleton bean in class field and method parameter gives different instances
Please take a look at code below:
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org....
-1
votes
1
answer
64
views
Why in Spring @Autowired annotation on a constructor is no longer necessary if the target bean only defines one constructor? [duplicate]
I am in the beginning of study of Spring framework and I read this in Spring official docs.
"As of Spring Framework 4.3, an @Autowired annotation on such a constructor is no longer necessary if ...
0
votes
1
answer
35
views
Spring JPA failing to find repository
Spring JPA application is failing to find the repository. I have tried annotating it with @repository, putting the controller, service and repository in component scan etc but I'm not having any luck. ...
0
votes
0
answers
22
views
defined in @EnableJpaRepositories declared on LostandfoundApplication: Not a managed type: class com.lostandfound.lostandfound.model.Item
LostandfoundApplication.java
package com.lostandfound.lostandfound;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org....
0
votes
0
answers
22
views
Ignore Self-Certificate with RestTemplate in a Simple and Standard Way
Is there a simple way to allow uncertifiable REST responses with RestTemplate without throwing an error?
The solution is and won't be able to use any ISPs, Certificate Authorities (CAs), or many ...
0
votes
0
answers
30
views
How does autowiring by parameter name works in Spring?
I have the following working example where beans are autowired by parameter name. Note that it is working and no qualifiers used.
How this can be done? I can't reproduce it in my project.
@Component
...