Home > Back-end >  Spring @autowired injection no problem and @ Resource injection to null
Spring @autowired injection no problem and @ Resource injection to null

Time:11-25

https://segmentfault.com/q/1010000015339613
This site is a problem that I send in other places details,

Project with @autowired can run it, but the use of the resource when always inject failure, not an error when starting, null pointer exception run times.

CodePudding user response:

Consult
https://stackoverflow.com/questions/39326542/spring-resource-injection-returns-a-nullpointerexception

CodePudding user response:

The @autowired is the default in accordance with the type of injection

@ the Resource according to the instance name is injected by default and make sure that your spring ioc bean is the name of the Resource annotate field name is the same with you

CodePudding user response:

@ the Resource injection, need with the specified name into class annotation (@ service (name='name'), @ Repository (name='name')) name attribute values are the same

CodePudding user response:

I also met the same problem today, because the tip before "Error: (8, 13) Java: package javax.mail. The annotation invisible" this Error message, after finding out information on the Internet will change the JDK version 8, in order to appear the Error,
The debug an afternoon feel this package should be an annotation problem, putting the JDK level 9 back, with the method of annotation in the pom with the

Javax.mail. Annotation
Javax.mail. The annotation - api
1.3.1 & lt;/version>


Now you can run normally!
  • Related