3
回答
ssh框架出现No bean named '/loginAction' is defined的错误
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

[framework]2012-08-14 10:28:15,281 - org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/TEST_BOOK].[action] -47   [http-8080-1] ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/TEST_BOOK].[action]  - Servlet.service() for servlet action threw exception
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '/loginAction' is defined
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:353)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:916)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:243)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
 at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:737)
 at org.springframework.web.struts.DelegatingActionProxy.getDelegateAction(DelegatingActionProxy.java:122)
 at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:105)
 at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
 at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
 at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
 at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
 at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:843)
 at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:679)
 at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1303)
 at java.lang.Thread.run(Thread.java:595)

用的是struts1.2+spring2+hibernate3,然后前台用了jquery的ajax 。各部分代码如下:

login.jsp页面代码:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>用户登录</title>
 <script type="text/javascript" src="<%=basePath%>/style/js/jquery.js"></script>
 
 <script type="text/javascript">
  function submitForm(){
   var username=document.all.username.value;
   var password=document.all.password.value;
   $.ajax({
    type:"POST",
    /loginAction.do?action=checkUser'">url:"<%=basePath%>/loginAction.do?action=checkUser",
    data:"username="+username+"&password="+password,
    success:function(data){
     if(data == 1){
      alert("用户名不存在!");
     }else if(data == 2){
      alert("密码错误!");
     }else{
      alert("输入正确!");
     }
    }
   });
  }
 
 </script>
  </head>
 
  <body>
 <form>
  <table>
   <tr>
    <td>
     用户名
    </td>
    <td>
     <input type="text" value="" name="username">
    </td>
   </tr>
   <tr>
    <td>
     密&nbsp;&nbsp;&nbsp;&nbsp;码
    </td>
    <td>
     <input type="password" value="" name="password">
    </td>
   </tr>
  </table>
  <table>
   <tr>
    <td>
     <input type="button" name="login" value="登录" onclick="submitForm();">
     <input type="button" name="reset" value="重置" onclick="resetForm();">
    </td>
   </tr>
  </table>
 </form>
  </body>
</html>

struts-config.xm代码:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>
  <data-sources />
  <form-beans />
  <global-exceptions />
  <global-forwards />
  <action-mappings />
  <message-resources parameter="com.ssh.struts.ApplicationResources" />
 
  <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
  <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext*.xml"/>
  </plug-in>
 
</struts-config>

struts-config-login.xml代码:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>

 <!-- Data Sources -->
 <data-sources>
 </data-sources>

 <!-- Form Beans -->   
 <form-beans>       
  
 </form-beans>           
   
 <!-- Global Exceptions -->
 <global-exceptions> 
 </global-exceptions>
    
 <!-- Global Forwards -->
 <global-forwards>
  
 </global-forwards>
 
 <!-- Action Mappings --> 
 <action-mappings>
  <action path="/loginAction"  parameter="action" type="org.springframework.web.struts.DelegatingActionProxy" scope="request">
         
        </action>   
 </action-mappings>
 
</struts-config>

applicatonContext.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"></property>
    <property name="url" value="jdbc:oracle:thin:@localhost :1521:orcl"></property>
    <property name="username" value="book_cms"></property>
    <property name="password" value="book"></property>
 </bean>
 <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
        <props>
           <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
           <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
    
    <property name="mappingDirectoryLocations">
        <list>
            <value>classpath:/com/cms/login/model</value>
            <value>classpath:/com/cms/person/model</value>
            <value>classpath:/com/cms/bookinfo/model</value>
            <value>classpath:/com/cms/booktype/model</value>
        </list>
    </property>
 </bean>
 
 <!-- 事务处理器 TransactionManager -->
 <bean id="transactionManager"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory">
   <ref bean="sessionFactory" />
  </property>
 </bean>

 <!-- 事务拦截器 Transaction Interceptor-->
 <bean id="transactionInterceptor"
  class="org.springframework.transaction.interceptor.TransactionInterceptor">
  <property name="transactionManager">
   <ref bean="transactionManager" />
  </property>

  <property name="transactionAttributes">
   <props>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
   </props>
  </property>
 </bean>
 
 <bean name="/loginAction" class="com.cms.login.action.LoginDispatchAction"  singleton="false">
  <property name="loginservice" ref="loginService"></property>
 </bean>
 
 <bean id="loginService" parent="baseTxService">
  <property name="target">
   <bean id="loginServiceTarger" class="com.cms.login.service.LoginServiceImpl">
    <property name="logindao" ref="loginDAO"></property>
   </bean>
  </property>
 </bean>
 
 <bean id="loginDAO" class="com.cms.login.dao.hibernate.LoginDAOImpl">
  <property name="hibernateTemplate" ref="hibernateTemplate"></property>
 </bean>
 
 <bean name="/personAction" class="com.cms.person.action.PersonDispatchAction" singleton="false">
  <property name="personservice" ref="personService"></property>
 </bean>
 
 <bean id="personService" parent="baseTxService">
  <property name="target">
   <bean id="personServiceTarger" class="com.cms.person.service.PersonServiceImpl">
    <property name="persondao" ref="personDAO"></property>
   </bean>
  </property>
 </bean>
 
 <bean id="personDAO" class="com.cms.person.dao.hibernate.PersonDAOImpl">
  <property name="hibernateTemplate" ref="hibernateTemplate"></property>
 </bean>
</beans>

web.xml代码:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml,/WEB-INF/struts-config-login.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>3</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>3</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
 
</web-app>


点击登录页面的“登录”按钮时就出现上面的错误。经调试没有进action里面的方法。

小弟新手,求各位大虾们指点指点,不胜感激!!

举报
兵兵阿Q
发帖于5年前 3回/3K+阅
顶部