首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

spring如何注入失败呢?求解

2012-03-24 
spring怎么注入失败呢?求解web.xml文件:context-paramparam-namecontextConfigLocation/param-name

spring怎么注入失败呢?求解
web.xml文件:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/*.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

配置:

XML code
<bean id="userDao" class="cc.user.dao.UserDAO">    </bean>        <bean id="userBo" class="cc.user.bo.UserBo"></bean>        <bean id="userService" class="cc.user.service.impl.UserServiceImpl">        <property name="userDao" ref="userDao"></property>    </bean>        <bean id="userAction" class="cc.user.action.UserAction">        <property name="userService" ref="userService"></property>        <property name="userBo" ref="userBo"></property>    </bean>

java文件:
Java code
public class UserAction extends ActionSupport{    UserBo userBo;     UserService userService;    String result="";    /**     * 验证用户登录     * @return     */    public String checkUser(){        String i=userService.checkUser(userBo);        result=i;        return SUCCESS;    }    @JSON(serialize=false)    public UserBo getUserBo() {        return userBo;    }    public void setUserBo(UserBo userBo) {        this.userBo = userBo;    }    @JSON(serialize=false)    public UserService getUserService() {        return userService;    }    public void setUserService(UserService userService) {        this.userService = userService;    }    public String getResult() {        return result;    }    public void setResult(String result) {        this.result = result;    }    }

谢谢大家帮忙,看看小弟那里配错了,只有User userservice =new UserService 才能用,也不报错,控制台打印:[color=#FF0000][/color]
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.config.ConfigurationManager - Checking ConfigurationProviders for reload.
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler - Entering nullPropertyValue [target=[com.opensymphony.xwork2.DefaultTextProvider@12a73d9], property=struts]
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.config.ConfigurationManager - Checking ConfigurationProviders for reload.
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler - Entering nullPropertyValue [target=[com.opensymphony.xwork2.DefaultTextProvider@12a73d9], property=struts]
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.config.ConfigurationManager - Checking ConfigurationProviders for reload.
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.DefaultActionProxy - Creating an DefaultActionProxy for namespace /user and action name check
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.interceptor.I18nInterceptor - intercept '/user/check' { 
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.interceptor.I18nInterceptor - applied invocation context locale=zh_CN
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.interceptor.I18nInterceptor - before Locale=zh_CN
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler - Entering nullPropertyValue [target=[cc.user.action.UserAction@ec898a, com.opensymphony.xwork2.DefaultTextProvider@12a73d9], property=struts]
69047 [http-8080-1] DEBUG org.apache.struts2.interceptor.FileUploadInterceptor - Bypassing /user/check
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.interceptor.StaticParametersInterceptor - Setting static parameters {}


69047 [http-8080-1] DEBUG com.opensymphony.xwork2.interceptor.ParametersInterceptor - Setting params NONE
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.interceptor.ParametersInterceptor - Setting params userBo.id => [ 1234 ] userBo.pass => [ 1234 ] 
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler - Entering nullPropertyValue [target=[cc.user.action.UserAction@ec898a, com.opensymphony.xwork2.DefaultTextProvider@12a73d9], property=userBo]
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.XWorkConverter - Property: id
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.XWorkConverter - Class: cc.user.bo.UserBo
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.XWorkConverter - field-level type converter for property [id] = none found
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.XWorkConverter - Property: userBo.id
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.XWorkConverter - Class: cc.user.action.UserAction
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.XWorkConverter - global-level type converter for property [id] = none found
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.XWorkConverter - falling back to default type converter [com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter@182c132]
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.XWorkConverter - Property: pass
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.XWorkConverter - Class: cc.user.bo.UserBo
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.XWorkConverter - field-level type converter for property [pass] = none found
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.XWorkConverter - Property: userBo.pass
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.XWorkConverter - Class: cc.user.action.UserAction
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.XWorkConverter - global-level type converter for property [pass] = none found
69047 [http-8080-1] DEBUG com.opensymphony.xwork2.conversion.impl.XWorkConverter - falling back to default type converter [com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter@182c132]
69047 [http-8080-1] DEBUG org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor - Validating /user/check with method checkUser.
69063 [http-8080-1] DEBUG com.opensymphony.xwork2.validator.ValidationInterceptor - Invoking validate() on action cc.user.action.UserAction@ec898a
69063 [http-8080-1] DEBUG com.opensymphony.xwork2.interceptor.PrefixMethodInvocationUtil - cannot find method [validateCheckUser] in action [cc.user.action.UserAction@ec898a]
69063 [http-8080-1] DEBUG com.opensymphony.xwork2.interceptor.PrefixMethodInvocationUtil - cannot find method [validateDoCheckUser] in action [cc.user.action.UserAction@ec898a]
69063 [http-8080-1] DEBUG com.opensymphony.xwork2.DefaultActionInvocation - Executing action method = null
69063 [http-8080-1] DEBUG com.opensymphony.xwork2.config.ConfigurationManager - Checking ConfigurationProviders for reload.
69078 [http-8080-1] DEBUG freemarker.cache - org/apache/struts2/dispatcher/error.ftl[zh_CN,UTF-8,parsed] using cached since jar:file:/D:/Work/Tomcat%206.0/webapps/cweb/WEB-INF/lib/struts2-core-2.1.8.1.jar!/org/apache/struts2/dispatcher/error.ftl didn't change.
69078 [http-8080-1] DEBUG freemarker.beans - Key 'location' was not found on instance of java.lang.NullPointerException. Introspection information for the class is: {getClass=public final native java.lang.Class java.lang.Object.getClass(), localizedMessage=java.beans.PropertyDescriptor@1ecb84b5, cause=java.beans.PropertyDescriptor@78a21497, getMessage=public java.lang.String java.lang.Throwable.getMessage(), getCause=public java.lang.Throwable java.lang.Throwable.getCause(), equals=public boolean java.lang.Object.equals(java.lang.Object), hashCode=public native int java.lang.Object.hashCode(), class=java.beans.PropertyDescriptor@3c588ba8, fillInStackTrace=public synchronized native java.lang.Throwable java.lang.Throwable.fillInStackTrace(), stackTrace=java.beans.PropertyDescriptor@b9249eb2, message=java.beans.PropertyDescriptor@85e125ae, java.lang.Object@b9b8d0=freemarker.ext.beans.MethodMap@1762fc7, getStackTrace=public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace(), setStackTrace=public void java.lang.Throwable.setStackTrace(java.lang.StackTraceElement[]), java.lang.Object@1478a2d={public void java.lang.Throwable.setStackTrace(java.lang.StackTraceElement[])=[Ljava.lang.Class;@3aef16, public boolean java.lang.Object.equals(java.lang.Object)=[Ljava.lang.Class;@126c6ea, public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()=[Ljava.lang.Class;@cd43ce, public java.lang.Throwable java.lang.Throwable.getCause()=[Ljava.lang.Class;@1eb0c6, public java.lang.String java.lang.Throwable.getMessage()=[Ljava.lang.Class;@e7b3f2, public final native java.lang.Class java.lang.Object.getClass()=[Ljava.lang.Class;@1d709a5, public java.lang.String java.lang.Throwable.getLocalizedMessage()=[Ljava.lang.Class;@ba6c13, public synchronized native java.lang.Throwable java.lang.Throwable.fillInStackTrace()=[Ljava.lang.Class;@10d9151, public synchronized java.lang.Throwable java.lang.Throwable.initCause(java.lang.Throwable)=[Ljava.lang.Class;@1bf68a9, public native int java.lang.Object.hashCode()=[Ljava.lang.Class;@1706eb7, public java.lang.String java.lang.Throwable.toString()=[Ljava.lang.Class;@74db2c}, toString=public java.lang.String java.lang.Throwable.toString(), initCause=public synchronized java.lang.Throwable java.lang.Throwable.initCause(java.lang.Throwable), printStackTrace=freemarker.ext.beans.MethodMap@1e16483, getLocalizedMessage=public java.lang.String java.lang.Throwable.getLocalizedMessage()}





[解决办法]
你看看 UserAction 中的 userservice是否为空 ?

这个信息看着好难受
[解决办法]
你的业务层有没配置好?
[解决办法]
你的dao层貌似就注入失败了。你注入的还是接口么!
[解决办法]
UserBo userBo; 
UserService userService;
是两个接口类吗
[解决办法]

探讨
引用:

你的业务层有没配置好?
这样配不对吗

[解决办法]
探讨
引用:
引用:

你的业务层有没配置好?
这样配不对吗


业务层的时候是配置DAO的

[解决办法]
探讨
引用:


然后配置文件里面还要配置事务

这些要等到spring好使了再弄,现在主要是每一层的注入都是失败的

热点排行