为什么我的spring依赖注入不成功?
action里执行到这句
List reptAgilityConfigList = reptAgilityConfigDAO.findByProperty "localNetId ", "351 ");
就报
严重: Servlet.service() for servlet action threw exception
java.lang.NullPointerException 错误。
就好象spring的配置文件没写一样。
我的action:
private ReptAgilityConfigDAO reptAgilityConfigDAO;
public ReptAgilityConfigDAO getReptAgilityConfigDAO() {
return reptAgilityConfigDAO;
}
public void setReptAgilityConfigDAO(
ReptAgilityConfigDAO reptAgilityConfigDAO) {
this.reptAgilityConfigDAO = reptAgilityConfigDAO;
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UserSelectForm userSelectForm = (UserSelectForm) form;// TODO
// Auto-generated
// method stub
log.debug( "select ");
if (userSelectForm.getUserName().equals( "abc ")
&& userSelectForm.getPassword().equals( "123 ")) {
// reptAgilityConfigDAO = new ReptAgilityConfigDAO();
List reptAgilityConfigList = reptAgilityConfigDAO.findByProperty(
"localNetId ", "351 ");
request
.setAttribute( "reptAgilityConfigList ",
reptAgilityConfigList);
return mapping.findForward( "initIframe ");
}
return mapping.findForward( "input ");
}
}
applicationContext.xml:
<?xml version= "1.0 " encoding= "UTF-8 "?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN " "http://www.springframework.org/dtd/spring-beans.dtd ">
<beans>
<bean id= "dataSource "
class= "org.apache.commons.dbcp.BasicDataSource ">
<property name= "driverClassName ">
<value> oracle.jdbc.driver.OracleDriver </value>
</property>
<property name= "url ">
<value> jdbc:oracle:thin:@133.128.9.23:1521:test </value>
</property>
<property name= "username ">
<value> test </value>
</property>
<property name= "password ">
<value> test* </value>
</property>
</bean>
<bean id= "sessionFactory "
class= "org.springframework.orm.hibernate3.LocalSessionFactoryBean ">
<property name= "configLocation ">
<value> com/hibernate.cfg.xml </value>
</property>
<property name= "dataSource ">
<ref bean= "dataSource " />
</property>
</bean>
<bean id= "ReptAgilityConfigDAO "
class= "com.yourcompany.ReptAgilityConfigDAO ">
<property name= "sessionFactory ">
<ref bean= "sessionFactory " />
</property>
</bean>