spring注入失败,服务器启动成功了,配置文件也没有错
下面是spring配置文件<?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="loginDao" class="com.beach.login.dao.LoginDaoImpl">
<property name="hibernateTemplate" ref="hibernateTemplate"></property>
</bean>

<bean id="loginBiz" parent="txProxyTemplate">
<property name="target">
<bean class="com.beach.login.biz.LoginBizImpl">
<property name="loginDao" ref="loginDao"></property>
</bean>
</property>
</bean>

<bean name="/login" class="com.beach.login.action.LoginAction">
<property name="loginBiz" ref="loginBiz"></property>
</bean>
</beans>服务器启动时,setter方法也调用了,而且bean值也不是null
但是在方法中调用bean的时候却报了空异常
bean是null
下面是服务器启动时在setter方法中输出来的16:54:51,750  INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
com.beach.login.biz.LoginBizImpl@a6af6e
com.beach.login.biz.LoginBizImpl@a6af6e
16:54:52,328  INFO ContextLoader:197 - Root WebApplicationContext: initialization completed in 4047 ms这是方法中调用的代码if( null != loginName && !loginName.trim().equals("") && null != loginPwd && !loginPwd.trim().equals("") ) {

User user=this.loginBiz.login(loginName,loginPwd);
if(user!=null){
result = user.getUserId() + "-" + user.getUserName();
HttpSession session=request.getSession();
session.setAttribute("USER_OBJECT",user); }else
{
result = "0";
}
}else
{
JSonMessage jsm = new JSonMessage();
jsm.addProperty( "failure", false );
result = jsm.toJSonString();
}
response.setCharacterEncoding( "UTF-8" );
response.getWriter().print(result);请高手指点啊。

解决方案 »

  1.   


    可能是下面的bean的name有问题,你把前面的"/",去掉试一下!
     <bean name="/login" class="com.beach.login.action.LoginAction">
            <property name="loginBiz" ref="loginBiz"></property>
     </bean>
      

  2.   


    可能是下面的bean的name有问题,你把前面的"/",去掉试一下!
     <bean name="/login" class="com.beach.login.action.LoginAction">
            <property name="loginBiz" ref="loginBiz"></property>
     </bean>