file-> Settings – & gt; Editor-> Inspections click on the search bar to enter Spring Core
Spring Core -> Code -> The Autowring for Bean Class changes the Severity level from the previous error to warning, so that the idea will not report an error
2. If you can’t compile it, check to see if the package is not imported, or if it is injected as static type
In the Spring Framework, we cannot @Autowired static variable, create Spring beans, for example, without that:
@Autowired
private static YourClass yourClass;
Can have a try, yourClass in such a state can not be dependency injection, throws an exception during execution. Java lang. NullPointerException, why?Static variables/class variables are not properties of an object, but properties of a class. Spring is based on dependency injection at the object level.
The use of static variables/class variables extends the use of static methods. Static methods are not recommended in Spring. The main purpose of Dependency Injection is to allow the container to generate instances of an object and then use them throughout the life cycle, while also making testing easier.
Once you use static methods, you no longer need to generate instances of the class, which makes testing more difficult, and you can’t generate multiple instances with different dependencies for a given class using injection methods. This static field is an implicit shared static field. It is a global state. Spring also does not recommend this.
Read More:
- The solution of using Autowired annotation to report errors in IntelliJ idea
- The @ Autowired annotation in springboot is invalid in ordinary classes. How to solve and use the null pointer exception java.lang.nullpointerexception
- Using jgit to report errors: the solution of algorithm negotiation failure
- Solution to the flash back, error report and unexpected exit of idea MAC windows
- Error pathvariable annotation was empty on param 0 when migrating idea to eclipse
- Clion configuration MingGW report error test cmake run with errors solution
- Solution of spring auto injection always report error in IntelliJ idea
- Solution of redisconnection factory in springboot2 not Autowired
- IntelliJ idea / eclipse automatically generate author annotation signature
- Because the computer is stuck, force to restart the computer and open idea idea to report an error on line 1: no content is allowed in the foreword.
- Using Lombok to compile and report errors
- Solution to the error of @ resource annotation in eclipse spring
- Using JSON to report errors
- Under idea2020.3 struts.xml The solution of “red report” based on extensions = “struts default” in
- @Solution to get / set error in eclipse after using data annotation
- Elememt UI introduces components on demand to report errors
- CentOS uses Yum install to report errors
- Idea community version starts Tomcat to report error running ‘XXXXXX’: java.lang.NullPointerException
- Node.js Using port 80 to report errors in Linux
- Using jsoup to parse web pages and report null errors