SSH整合
java.lang.NullPointerException 报出
空指针java.lang.
NullPointerException这么写没问题
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
Adminservice add = (Adminservice) ac.getBean("adminservice");
Admin ad=add.login(userid, password);
这么写就出错,报空指针java.lang.NullPointerException
Admin ad=adminservice.login(userid, password);
package com.pro.action;
public class Adminaction extends BaseAction {
private Adminservice adminservice;
private String userid;
private String password;
public String login()
{
// ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
// Adminservice add = (Adminservice) ac.getBean("adminservice");
//System.out.println(add.login(userid,password));
// Admin ad=adminservice.login(userid,password);
// adminservice=new Adminserviceimpl();
//Admin ad=adminservice.login(userid,password);
Admin ad=adminservice.login(userid, password);
System.out.print(ad.getCode());
return "xxx";
}
public Adminservice getAdminservice() {
return adminservice;
}
public void setAdminservice(Adminservice adminservice) {
this.adminservice = adminservice;
}
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
<!-- 用户登陆的 -->
<bean id="adminDao" class="com.pro.Daoimpl.AdminDAOimpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="adminservice" class="com.pro.serviceimpl.Adminserviceimpl">
<property name="admindao" ref="adminDao"></property>
</bean>
<bean id="Adminaction" class="com.pro.action.Adminaction">
<property name="adminservice" ref="adminservice"></property>
</bean>
百度了一个下午也没找出原因。。。受不了了。。
------解决方案--------------------
你struts的配置就应该这样写
<action name="Adminaction" class="Adminaction">spring中bean的id