A null pointer exception is often prompted when the action is a dependency injection

Source: Internet
Author: User

Sometimes, when we inject a dependency into the DAO layer, service layer, and action, we often prompt for null pointer exceptions, that is, injection failures. ..


This is every bit abnormal, normal use ~ ~ What is going on ... The reasons are as follows:

In the case of dependency injection, the injection of the DAO layer class is not the same as the action. A little bit different.

Our example explains the subtle differences between the two injections:

Example of a DAO layer injection:

<bean id= "Loginregistserviceimpl" class= "Com.serviceImpl.LoginRegistServiceImpl" >  
   <constructor-arg Name= "Udao" ><ref bean= "Userdaoimpl"/></constructor-arg>  
   </bean>  
     
   <bean id= " ServiceManager "class=" Com.serviceImpl.ServiceManager ">  
   <property name=" LRS "><ref bean=" Loginregistserviceimpl "/></property>  
   </bean>  

Take a look at the injection of action:

    <bean id= "loginregistaction" class= "com.action.LoginRegistAction" >  
       <property name= "ServiceManager" ><ref bean= "ServiceManager"/></property>  
    </bean>  

The focus is on: [HTML] view plain copy <property name= "ServiceManager" ><ref bean= "ServiceManager"/></ Property>


In action injection, you must require that the name of the variable defined by the action be consistent with the ID name of the injected bean, and no injection fails ~ ~ ~


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.