flex eclipseを使ってspringを統合する方法を教えてあげます

9350 ワード

FlashBuilderを最初にダウンロード4_7_LS10_win64.exeはmyeclipse 8を含むいくつかのeclipseインストールプラグインを試しても成功しなかった.5、spring sts2.9.2、eclipse3.5、j 2 eeeclipseバージョン4.2.0、その後FlashBuilderを作りました.4_LS10.exeインストールが完了するとプラグインインストールファイルが見つかりません.これは単独版です.プラグイン版が必要です.最後にFlashBuilderをダウンロードします.4_Plugin_LS10.exeはやっと構成に成功しましたmyeclipse 8.5だめです.spring stsでいいです.
Spring sts導入アプリケーションはmyeclipseとは異なり、eclipseに似ています.
flexとjavaをstsで統合するには、いくつかのステップがあります.
1:動的webプロジェクトflexwebを新規作成し、webを作成する.xml
2: blazeds-turnkey-4.0.0.14931.zipは解凍して、blazedの2つのフォルダflexとlibをWEB-INFの下にコピーして、中はblazeのjarパッケージとflexプロファイルで、それからwebを修正します.xml blazeサポートへの参加


  flex.messaging.HttpFlexSession
 

 
 
 
  MessageBrokerServlet
  flex.messaging.MessageBrokerServlet
  
   services.configuration.file
   /WEB-INF/flex/services-config.xml
  
  1
 
 
  MessageBrokerServlet
  /messagebroker/*
 

3:プロジェクト右クリック、プロジェクトタイプの追加/変更>flexタイププロジェクトの追加、最初のステップ、アプリケーションタイプJ 2 EEを選択し、下にBlazeDSを選択し、2番目のルートフォルダにプロジェクトを記入workspaseのパスにWebContentを追加します.例えば、E:workspacesstsflexwebWebContent、ルートURLに記入します.http://localhost:8080/flexweb、コンテキストルートディレクトリ/flexweb、出力フォルダはデフォルトE:workspacesstsflexwebWebContentflexweb-debugを使用し、finish 4をクリックします.変換が完了すると、ディレクトリが少し変わります.右クリック項目>properties>flex構築パス、メインソースフォルダがflex_に変更されます.src、そして自動的に生成されたsrcディレクトリの下のflexweb.mxmlをflex_に移動srcでは環境構築が完了しました
HelloWorld
flexweb.mxml:


  
 
   
    
   
 
   
    
    
   
 

其中

指定了一个调用Java的类Hello,mytest对应到remoting-config.xml

在WEB-INFO/flex目录下remoting-config.xml加入



    
      com.hongbo.Hello
    
  

resultはjavaメソッド呼び出しのコールバック関数に対応して通常のjavaクラスを構築する

package com.hongbo;

public class Hello {

 public String sayHello(String name){
  System.out.println("------------------------------------");
  return "Hello First Demo " + name;
 }
}

これでOK
アクセスパスはhttp://localhost:8080/flexweb/flexweb-debug/flexweb.html
最初の会報404、problemsヒントhtmlパッケージを作成できないので、右クリックしてテンプレートを再作成します
Springサポートの追加
1:web.xml加入


  contextConfigLocation
  /WEB-INF/classes/applicationContext.xml 
 
 
  org.springframework.web.context.ContextLoaderListener
 

2:srcでアプリケーションContextを作成する.xml




 
  
   
  
 
 

3:WEB-INF/flex/service-config.xml加入


    
 

Javaクラスの追加

package com.hongbo;


import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import flex.messaging.FactoryInstance;
import flex.messaging.FlexFactory;
import flex.messaging.config.ConfigMap;
import flex.messaging.services.ServiceException;
public class SpringFactory implements FlexFactory {
 private static final String SOURCE = "source";

 public void initialize(String id, ConfigMap configMap) {
 }

 public FactoryInstance createFactoryInstance(String id, ConfigMap properties) {
  SpringFactoryInstance instance = new SpringFactoryInstance(this, id,
    properties);
  instance.setSource(properties.getPropertyAsString(SOURCE, instance
    .getId()));
  return instance;
 } // end method createFactoryInstance()  

 public Object lookup(FactoryInstance inst) {
  SpringFactoryInstance factoryInstance = (SpringFactoryInstance) inst;
  return factoryInstance.lookup();
 }

 static class SpringFactoryInstance extends FactoryInstance {
  SpringFactoryInstance(SpringFactory factory, String id,
    ConfigMap properties) {
   super(factory, id, properties);
  }

  public String toString() {
   return "SpringFactory instance for id=" + getId() + " source="
     + getSource() + " scope=" + getScope();
  }

  public Object lookup() {
   ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(flex.messaging.FlexContext.getServletConfig().getServletContext());
   String beanName = getSource();

   try {
    return appContext.getBean(beanName);
   } catch (NoSuchBeanDefinitionException nexc) {
    ServiceException e = new ServiceException();
    String msg = "Spring service named '" + beanName
      + "' does not exist.";
    e.setMessage(msg);
    e.setRootCause(nexc);
    e.setDetails(msg);
    e.setCode("Server.Processing");
    throw e;
   } catch (BeansException bexc) {
    ServiceException e = new ServiceException();
    String msg = "Unable to create Spring service named '"
      + beanName + "' ";
    e.setMessage(msg);
    e.setRootCause(bexc);
    e.setDetails(msg);
    e.setCode("Server.Processing");
    throw e;
   }
  }

 }

}

4:remoting-configを修正する.xml


    
     spring
      hello
    
  

5:対応するJavaクラスの変更

package com.hongbo;

import com.hongbo.test.TestSpring;

public class Hello {

 private TestSpring testSpring;
 
 public void setTestSpring(TestSpring testSpring) {
  this.testSpring = testSpring;
 }
 
 public String sayHello(String name){
  return testSpring.testSpring(name);
 }
}

package com.hongbo.test;

public interface TestSpring {

 String testSpring(String name);
}

package com.hongbo.test.impl;

import com.hongbo.test.TestSpring;

public class TestSpringImpl implements TestSpring{

 public String testSpring(String name){
  System.out.println("test spring-------------------------------------"+name);
  return "test spring "+name;
 }
}

最後に、flex印刷文traceはコンソールに印刷されません.flashplayerをアンインストールしてからdebuger版のflashplayerをインストールし、flashplayerをダウンロードします.uninstall.zip,アンインストール,flashplayer 10 r 12をダウンロードする36_winax_debug.exe、インストール、アンインストールインストールインストール後はGoogleブラウザが影響しないようで、eclipseはデフォルトブラウザをIEに変更し、window>preferences>General>Web browser、インターネットExplorerを選択し、最後にtomcatを起動した後、mxmlの上でdebugを右クリックして実行し、開いたIEでtraceを印刷し、直接ウェブサイトにアクセスすることはできません.漏れがあればご指摘ください