2016-12-05 72 views
0

它不識別initFlow()方法FlowController獲得項目錯誤......這裏是我的代碼

這裏是我的FlowController

FlowController.java :- 
----------------------------------- 

    package com.niit.shoppingcart; 

import java.util.List; 


import javax.servlet.http.HttpSession; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.security.core.Authentication; 
import org.springframework.security.core.context.SecurityContextHolder; 
import org.springframework.stereotype.Component; 

import com.niit.shoppingcart.dao.BillingAddressDAO; 
import com.niit.shoppingcart.dao.CardDetailDAO; 
import com.niit.shoppingcart.dao.CartDAO; 
import com.niit.shoppingcart.dao.OrderDetailDAO; 
import com.niit.shoppingcart.dao.OrderedItemsDAO; 
import com.niit.shoppingcart.dao.ProductDAO; 
import com.niit.shoppingcart.dao.ShippingAddressDAO; 
import com.niit.shoppingcart.dao.UserDetailsDAO; 
import com.niit.shoppingcart.model.BillingAddress; 
import com.niit.shoppingcart.model.CardDetail; 
import com.niit.shoppingcart.model.Cart; 
import com.niit.shoppingcart.model.CheckoutDetails; 
import com.niit.shoppingcart.model.OrderDetail; 
import com.niit.shoppingcart.model.OrderedItems; 
import com.niit.shoppingcart.model.Product; 
import com.niit.shoppingcart.model.ShippingAddress; 
import com.niit.shoppingcart.model.UserDetails; 



@Component(value="flowController") 
public class FlowController { 
    @Autowired 
    private ProductDAO productDAO; 

    @Autowired 
    private ShippingAddress shippingAddress; 

    @Autowired 
    private BillingAddress billingAddress; 

    @Autowired 
    private OrderDetail orderDetail; 

    @Autowired 
    private OrderedItems orderedItems; 

    @Autowired 
    private CardDetail cardDetail; 

    @Autowired 
    private ShippingAddressDAO shippingAddressDAO; 

    @Autowired 
    private BillingAddressDAO billingAddressDAO; 

    @Autowired 
    private OrderedItemsDAO orderedItemsDAO; 

    @Autowired 
    private OrderDetailDAO orderDetailDAO; 

    @Autowired 
    private CardDetailDAO cardDetailDAO; 
    @Autowired 
    UserDetails userDetails; 

    @Autowired 
    UserDetailsDAO userDetailsDAO ; 

    @Autowired 
    CartDAO cartDAO; 

    @Autowired 
    List<Cart> cart; 


    @Autowired 
    HttpSession httpSession; 
    @Autowired 
    Product product; 


    public ShippingAddress initFlow() { 

     return new ShippingAddress(); 
    } 

    public String saveDetails(ShippingAddress shippingAddress){ 

     /*Authentication auth = SecurityContextHolder.getContext().getAuthentication(); 
      String name = auth.getName(); 
      UserDetails userDetails=userDetailsDAO.getCustomerByUserName(name); 
      String loggedInUser = userDetails.getId(); 
      shippingAddress.setUserId(loggedInUser);*/ 
     shippingAddressDAO.saveOrUpdate(shippingAddress); 

     return "success"; 
    } 
    public String saveDetails(BillingAddress billingAddress){ 

     /*Authentication auth = SecurityContextHolder.getContext().getAuthentication(); 
      String name = auth.getName(); 
      UserDetails userDetails=userDetailsDAO.getCustomerByUserName(name); 
      String loggedInUser = userDetails.getId(); 
      billingAddress.setUserId(loggedInUser);*/ 
     billingAddressDAO.saveOrUpdate(billingAddress); 
     return "success"; 
    } 
    public String saveDetails(CardDetail cardDetail){ 
     /*Authentication auth = SecurityContextHolder.getContext().getAuthentication(); 
      String name = auth.getName(); 
      UserDetails userDetails=userDetailsDAO.getCustomerByUserName(name); 
      String loggedInUser = userDetails.getId(); 
      cardDetail.setUserId(loggedInUser);*/ 
     cardDetailDAO.saveOrUpdate(cardDetail); 
     return "success"; 
    } 


    /*public String remove(){ 
     Authentication auth = SecurityContextHolder.getContext().getAuthentication(); 
      String name = auth.getName(); 
      UserDetails userDetails=userDetailsDAO.getCustomerByUserName(name); 
      String loggedInUser = userDetails.getId(); 
      List<Cart> cartList = cartDAO.getByUser(loggedInUser); 
      if (cartList != null) { 
       for (int i = 0; i < cartList.size(); i++) { 
       cartList.get(i).setQuantity(0); 
       cartDAO.update(cartList.get(i)); 
       } 

      } 
      return "success"; 

}*/ 
} 



    =============================================================================== 

這裏是我的結帳flow.xml

結帳flow.xml: - ----------------------------

<?xml version="1.0" encoding="UTF-8"?> 
<flow xmlns="http://www.springframework.org/schema/webflow" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.4.xsd"> 

    <var name="shippingAddress" class="com.niit.shoppingcart.model.ShippingAddress" /> 
    <var name="billingAddress" class="com.niit.shoppingcart.model.BillingAddress" /> 
    <var name="orderedItems" class="com.niit.shoppingcart.model.OrderedItems" /> 
    <var name="orderDetail" class="com.niit.shoppingcart.model.OrderDetail" /> 
     <var name="CardDetail" class="com.niit.shoppingcart.model.CardDetail" /> 
    <var name="cart" class="com.niit.shoppingcart.model.Cart" /> 
     <var name="UserDetails" class="com.niit.shoppingcart.model.UserDetails" /> 
    <var name="checkoutDetails" class="com.niit.shoppingcart.model.CheckoutDetails"></var> 

    <on-start> 
     <evaluate expression="flowController.initFlow()" result="flowScope.shippingAddress" /> 
    </on-start> 

    <view-state id="start" view="shippingAddress" model="flowScope.shippingAddress"> 
     <transition on="submitShippingAddress" to="saveShipping" /> 
     <transition on="back" to="toHome" /> 
    </view-state> 
     <action-state id="saveShipping"> 
     <evaluate expression="flowController.saveDetails(shippingAddress)"></evaluate> 
     <transition on="success" to="viewBillingDetails" /> 
    </action-state> 

<!-- <action-state id="shippingDetails"> 
     <evaluate 
      expression="flowController.addShippingAddress(flowScope.checkoutDetails,flowScope.shippingAddress)"></evaluate> 
     <transition on="success" to="viewBillingDetails" /> 
      <transition on="failure" to="start" /> 
    </action-state> --> 

    <view-state id="viewBillingDetails" view="billingAddress" model="flowScope.billingAddress"> 
     <transition on="submitBillingAddress" to="saveBilling" /> 
     <transition on="cancel" to="start" /> 
    </view-state> 

     <action-state id="saveBilling"> 
     <evaluate expression="flowController.saveDetails(billingAddress)"></evaluate> 
     <transition on="success" to="viewCardDetail" /> 
    </action-state> 

    <!-- <action-state id="billingDetails"> 
     <evaluate 
      expression="flowController.addBillingAddress(flowScope.checkoutDetails,billingAddress)"></evaluate> 
     <transition on="success" to="viewCardDetail" />`` 
    </action-state> --> 

    <view-state id="viewCardDetail" view="cardDetail" 
     model="cardDetail"> 
     <transition on="confirmCheckout" to="save" /> 
      <transition on="cancel" to="viewBillingDetails" /> 
    </view-state> 

    <!-- <action-state id="cardDetail"> 
     <evaluate 
      expression="flowController.addCardDetails(flowScope.checkoutDetails,cardDetail)"></evaluate> 
     <transition on="success" to="orderConfirm" /> 
    </action-state> --> 

    <action-state id="save"> 
     <evaluate expression="flowController.saveDetails(cardDetail)"></evaluate> 
     <transition on="success" to="orderConfirm" /> 

    </action-state> 


    <view-state id="orderConfirm" view="orderConfirmed"> 
     <!-- <transition on="finalHome" to="remove" /> --> 
     <transition on="finalHome" to="toHome" /> 
    </view-state> 

<!-- <action-state id="remove"> 
     <evaluate expression="FlowController.remove()"></evaluate> 
     <transition on="success" to="toHome" /> 
    </action-state> --> 


    <!-- <end-state id="orderConfirmed" view="orderConfirmed"/> 
    <end-state id="toCartView" view="externalRedirect:contextRelative:/user/cart/" /> --> 
    <end-state id="toHome" view="Home" /> 

<global-transitions> 
     <transition on="back" to="Home" /> 
    </global-transitions> 

</flow> 

這裏是我的調度員servlet.xml中,我已經給checkoutDetails的條目....

dispatcher-servlet.xml:- 

------------------------------------------------------ 

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:flow="http://www.springframework.org/schema/webflow-config" 
    xsi:schemaLocation=" 
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-4.0.xsd 
http://www.springframework.org/schema/webflow-config 
http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.4.xsd"> 


    <context:component-scan base-package="com.niit.shoppingcart" /> 

    <bean id="multipartResolver" 
     class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 
     <property name="maxUploadSize" value="200000" /> 
    </bean> 
    <bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix"> 
      <value>/view/</value> 
     </property> 
     <property name="suffix"> 
      <value>.jsp</value> 
     </property> 
    </bean> 



    <mvc:resources mapping="/resources/**" location="/resources/" /> 
    <mvc:annotation-driven/> 


    <!-- Using FlowController instead of FlowHandlers; see SWF Reference Guide, section 9.5. --> 

    <context:component-scan base-package="com.niit.shoppingcart.*" /> 

    <bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController"> 
     <property name="flowExecutor" ref="flowExecutor"/> 
    </bean> 

    <flow:flow-executor id="flowExecutor" flow-registry="flowRegistry"/> 

    <!-- This creates an XmlFlowRegistryFactory bean --> 
    <flow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF"> 
    <flow:flow-location id="memberShip" path="/memberShipFlow.xml"/> 
     <flow:flow-location id="checkoutDetails" path="/checkout-flow.xml"/> 
    </flow:flow-registry> 

    <flow:flow-builder-services id="flowBuilderServices" view-factory-creator="viewFactoryCreator"/> 

     <bean id="viewFactoryCreator" 
     class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator"> 
     <property name="viewResolvers"> 
      <list> 
       <ref bean="viewResolver" /> 
      </list> 
     </property> 
    </bean> 

    <bean id="viewResolver" 
     class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
     <property name="viewClass" 
      value="org.springframework.web.servlet.view.JstlView" /> 
     <property name="prefix"> 
      <value>/view/</value> 
     </property> 
     <property name="suffix"> 
      <value>.jsp</value> 
     </property> 
    </bean> 


    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"> 
     <property name="flowExecutor" ref="flowExecutor" /> 
    </bean> 

    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping"> 
     <property name="flowRegistry" ref="flowRegistry" /> 
     <property name="order" value="0" /> 
    </bean> 




</beans> 


=============================================================================== 

這是我的錯誤報告: -

Error Report :- 
-------------------------------------------------- 


SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/ShoppingCartFrontEnd] threw exception [Request processing failed; nested exception is org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [[email protected] targetAction = [[email protected] expression = flowController.initFlow(), resultExpression = flowScope.shippingAddress], attributes = map[[empty]]] in state 'null' of flow 'checkoutDetails' -- action execution attributes were 'map[[empty]]'] with root cause 
org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 15): Method call: Method initFlow() cannot be found on org.springframework.webflow.mvc.servlet.FlowController type 
    at org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod(MethodReference.java:211) 
    at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:125) 
    at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:49) 
    at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:347) 
    at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88) 
    at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:131) 
    at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:299) 
    at org.springframework.binding.expression.spel.SpringELExpression.getValue(SpringELExpression.java:84) 
    at org.springframework.webflow.action.EvaluateAction.doExecute(EvaluateAction.java:75) 
    at org.springframework.webflow.action.AbstractAction.execute(AbstractAction.java:188) 
    at org.springframework.webflow.execution.AnnotatedAction.execute(AnnotatedAction.java:145) 
    at org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:51) 
    at org.springframework.webflow.engine.ActionList.execute(ActionList.java:154) 
    at org.springframework.webflow.engine.Flow.start(Flow.java:526) 
    at org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:368) 
    at org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:223) 
    at org.springframework.webflow.executor.FlowExecutorImpl.launchExecution(FlowExecutorImpl.java:140) 
    at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:263) 
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) 
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) 
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) 
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) 
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) 
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) 
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) 
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110) 
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) 
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785) 
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425) 
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 
    at java.lang.Thread.run(Unknown Source) 

回答

0

的問題可能是在您dispatcher-servlet.xml

<bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController"> 
    <property name="flowExecutor" ref="flowExecutor"/> 
</bean> 

FlowController.java文件有:

package com.niit.shoppingcart; 

在頭部,所以這將意味着你的bean的全稱應該是:

<bean id="flowController" class="com.niit.shoppingcart.FlowController"> 
    <property name="flowExecutor" ref="flowExecutor"/> 
</bean> 

是否幫助你嗎?

0

您有2個名爲flowController的bean。其中一個是你的配置的spring bean,另一個是你在這個命令流中使用的bean。

我建議你改變:

@Component(value="flowController") 

喜歡的東西:

@Component(value="checkoutFlowController") 

,然後在結賬流對它的所有引用,以及:

<evaluate expression="checkoutFlowController.initFlow()" result="flowScope.shippingAddress" /> 

等。