2016-06-28 9 views
0

私の要件は、異なるJVM内の2つの異なるアプリケーション間のリダイレクトです。また、2つの間でデータを転送します。私はFlash Attributesを使ってみましたが、コントローラでは属性はnullです。私はインターセプタも作成しようとしましたが、Flash属性もnullです。誰かが2つの異なるアプリケーション間で属性を渡す方法について助けてくれますか?spring mvcが別のjvm上の別のアプリケーションにリダイレクト

ディスパッチャ-servlet.xml

<context:component-scan base-package="controller" /> 
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="viewClass" 
      value="org.springframework.web.servlet.view.JstlView" /> 
     <property name="prefix"> 
      <value>/WEB-INF/views/</value> 
     </property> 
     <property name="suffix"> 
      <value>.jsp</value> 
     </property> 
    </bean> 
    <bean name="flashMapManager" class="org.springframework.web.servlet.support.SessionFlashMapManager" /> 
    <mvc:annotation-driven /> 
</beans> 

Controller.java

@RequestMapping(value = "add", method = RequestMethod.POST) 
    public String add(@ModelAttribute("customer") Customer customer, 
      final RedirectAttributes redirectAttributes) { 

     redirectAttributes.addFlashAttribute("customer", customer); 
     redirectAttributes.addFlashAttribute("message", "Added successfully."); 
     return "redirect:http://localhost:8080/poc2"; 
    } 

poc2呼び出すアプリケーション - - と呼ばれるアプリケーション

dispatcher- POC1:ここ

は私のコードですservlet.xml

<context:component-scan base-package="controller" /> 
    <bean 
class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="viewClass" 
      value="org.springframework.web.servlet.view.JstlView" /> 
     <property name="prefix"> 
      <value>/WEB-INF/views/</value> 
     </property> 
     <property name="suffix"> 
      <value>.jsp</value> 
     </property> 
    </bean> 
    <bean name="flashMapManager" 
    class="org.springframework.web.servlet.support.SessionFlashMapManager" /> 
    <!-- <bean id="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"> 
     <property name="interceptors"> <list> <ref bean="requestInterceptor" /> </list> 
     </property> </bean> --> 
    <bean id="requestInterceptor" class="RequestInterceptor" /> 
    <mvc:annotation-driven /> 
    <mvc:interceptors> 
     <ref bean="requestInterceptor" /> 
    </mvc:interceptors> 
</beans> 

Controller.java

@RequestMapping(value = "/", method = RequestMethod.GET) 
public ModelAndView index(Model model, HttpServletRequest request, 
     HttpSession session) { 
    Map<String, ?> inputFlashMap = RequestContextUtils 
      .getInputFlashMap(request); 
    Customer cust1 = (Customer) model.asMap().get("customer"); 
    Customer cust = (Customer) inputFlashMap.get("customer"); 
    ModelAndView modelMap = new ModelAndView("showCustomer"); 
    System.out.println("Calling controller"); 
    return modelMap; 
} 
+0

回避方法をお伝えください。 –

+0

これは主な骨格のない質問です。 Docがそれを見ることができるように仕事ディレクトリを共有しなさい。 –

+0

回避策は、バネリダイレクトと休憩サービスを使用してデータを転送することでした。 – ggelect

答えて

0

あなたはこれを使用することができ、ちょうどredirectAttributes.addFlashAttribute(...) -> "redirect:..."を使用して は、モデル属性を "再挿入" する必要はありませんでした、としても働きました。

+0

同じアプリケーション内の別のコントローラにリダイレクトするときに機能します。しかし、別のアプリケーションに移動する場合、フラッシュ属性は常にnullです。 – ggelect

+0

@RequestMapping(値= "addcustomer"、メソッド= RequestMethod.POST) \t公共ストリングaddCustomer(@ModelAttribute( "顧客")ユーザー顧客、 \t \t \t最終RedirectAttributesのredirectAttributes){ \t \t redirectAttributes.addFlashAttribute(」顧客 "、顧客); \t \t redirectAttributes.addFlashAttribute( "message"、 "正常に追加されました。"); \t \t return "redirect:showcustomer.html"; \t \t} – Rajesh

+0

私はそれを試して、それは動作しますが、それは同じアプリケーションのためです。しかし、別のアプリケーションの場合、これはうまくいきません。リダイレクトを返すと、http:// localhost:8080/zpoc2 "; 「poc1」から別のアプリケーション「poc2」にリダイレクトすると、データは失われます。 – ggelect

関連する問題