Controller @Autowired comment inject value is null sudden problems

Code issue a record not easily be found: originally a normal operation of the project, the recent emergence of a strange question. In the method a Controller, certain @autowired bean injected into a value for use null. Strangely, the same bean in other Controller, even in the current Controller in other ways, are as usual.

After troubleshooting, analyze the causes and found that the method of adding the section aop do log analysis after a particular feature, then view the modifications related to the emergence of similar problems method modifiers are private modification method.

Explain why:

Spring mechanism using the aop jdk dynamic proxy mechanism or its proxy mechanism cglib implementation interfaces are implemented based on inheritance and subclasses.

To be more specific portions of source spring aop

Method [] methods = clazz.getMethods () ;
manner JAVA reflected only get acquired public / protected method, the method can not be private agent, eventually leading to failure bean injection.

To sum up, this is actually a very simple question, but the coding is not standardized, or old items reconstruction of these scenes will appear in the problem and not easy to find, developers often obsession to not have any changes to the original method of logic and ignore out. Use cut new entrants to confirm the target method modifier is not Private .

 

Guess you like

Origin www.cnblogs.com/bmwsl/p/11280613.html