I'm having some issues with Autowiring in Spring Boot. Some of these issues are related to IntelliJ https://youtrack.jetbrains.com/issue/IDEA-139669. But I noticed something now.
In one class I'm trying to Autowire UserDetailsService
like this.
@Autowired
UserDetailsService userDetailsService;
public void someMethod() {
userDetailsService.getUserDetails();
}
If the getUserDetials
method is static
in UserDetailsService
like below. Then the Autowiring works.
@Service
public class UserDetailsService {
public static void getUserDetails() {
System.out.println("Output from UserDetailsService");
}
But if the getUserDetials
method is non-static
in UserDetailsService
like below. Then I get the following error java.lang.NullPointerException: null
for userDetailsService.getUserDetails()
when I try to use the Autowiring.
@Service
public class UserDetailsService {
public void getUserDetails() {
System.out.println("Output from UserDetailsService");
}
Is it expected behaviour that Autowiring is dependent on the method being static
or is it just an issue with the IntelliJ, or am I missing something else here?