zoukankan      html  css  js  c++  java
  • Mini test with Springstruts2

    1. http://forum.springsource.org/showthread.php?120752-Mini-test-with-Spring-struts2

       Mini test with Spring-struts2

      Hi everyone!
      I'm a newbie. I get this issue:
      I'm starting with a simple webapp for login.
      I got a NPE while my struts action attempts run its execute method from my LoginAction extended from ActionSupport. userLogin is null and action always fail!
      Code:
      	public String execute() {
      		if (userLogin==null) {
      			logger.debug("No Way! userLogin is null now!");	
      		} else {
      			logger.debug("OK!!!! userLogin is initialized");
      			Utente utenteLogin = userLogin.CheckUser(this.username, this.password);
      			if (utenteLogin.validaName()) {
      				return Action.SUCCESS;	
      			} else {
      				return Action.INPUT;
      			}
      		}
      		return Action.INPUT;
      	}
      That's seems to me strange because spring works fine injecting the right bean in the same LoginAction:
      Code:
      	public void setUserLogin(JdbcUserDao userLogin) {
      		logger.debug("Dao setting");
      		this.userLogin = userLogin;
      		logger.debug(this.userLogin.getTesto());
      	}
      this is my simple Spring appContext:

      Code:
      	  <bean id="dbcpDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" lazy-init="true">
      	    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
      	    <property name="url" value="jdbc:mysql://localhost:3306/dbRemo" />
      	    <property name="username" value="test" />
      	    <property name="password" value="test" />
      	  </bean>
      
        	  <bean id="jdbcTemplate" class="org.remo.struts2.JdbcUserDaoImpl">
      		  <property name="dataSource" ref="dbcpDataSource"/>
      		  <property name="testo" value="OK!"/>
      	  </bean>
      
        	  <bean id="Login" class="org.remo.struts2.LoginAction">
      		  <property name="UserLogin" ref="jdbcTemplate" />
      	  </bean>
      Rememeber this is a simple testing app just to learn these frameworks.
      would you please help me.

      Thanx
      Remo

    2. #2
      Join Date
      Sep 2011
      Posts
      2

      Default

      Answer to myself because I found out the issues:

      1) I haven't added the struts2-spring-plugin-xxx.jar.

      2) I haven't put in struts.xml the spring objectFactory with this statement:
      Code:
      <constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
      3) I haven't assigned to the action of the class attribute the same name of the bean identified in spring:
      Code:
      <action name="doLogin" class="loginAction">
      instead of
      Code:
      <action name="doLogin" class="org.xxx.yyy.loginAction">
      for the bean of spring
      Code:
      <bean id="loginAction" scope="prototype" class="org.remo.struts2.LoginAction">
      After that my webapp worked out fine.

      bye
      Remo  
  • 相关阅读:
    Android获取两条线之间的夹角度数
    Android字体度量(FontMetrics)
    Android下如何计算要显示的字符串所占的宽度和高度
    Android 颜色渲染PorterDuff及Xfermode详解
    从输入URL到页面加载的全过程
    滚动优化
    常用的前端相关chrome插件
    DNS预解析prefetch
    资源预加载preload和资源预读取prefetch简明学习
    使用chrome开发者工具中的performance面板解决性能瓶颈
  • 原文地址:https://www.cnblogs.com/lexus/p/2340698.html
Copyright © 2011-2022 走看看