손잡이가 flex eclipse 통합spring을 가르쳐 줍니다.
springsts 배치 응용 프로그램은 myeclipse와 달리 eclipse와 유사합니다.
sts로 flex와java를 통합하는 몇 가지 절차가 있습니다.
1: 새 동적 웹 프로젝트flexweb, 웹 만들기.xml
2: blazeds-turnkey-4.0.0.14931.zip 압축을 풀고blazed 두 폴더 flex와lib를 WEB-INF로 복사합니다. 그 안에 blaze의jar 패키지와flex 프로필이 있습니다. 그리고 웹을 수정합니다.xmlblaze 지원 추가
<listener>
<listener-class>flex.messaging.HttpFlexSession</listener-class>
</listener>
<!-- MessageBroker Servlet -->
<servlet>
<servlet-name>MessageBrokerServlet</servlet-name>
<servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
<init-param>
<param-name>services.configuration.file</param-name>
<param-value>/WEB-INF/flex/services-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MessageBrokerServlet</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
3: 프로젝트 오른쪽 단추, 프로젝트 형식 추가/변경 > flex 형식 항목 추가, 첫 번째 단계, 프로그램 형식 선택 J2EE, 아래 선택 BlazedS, 두 번째 루트 폴더 입력 프로젝트는 workspase 경로에 WebContent를 추가합니다. 예를 들어 E:\workspaces\sts\flexweb\WebContent, 루트 URL 작성http://localhost:8080/flexweb, 상하문 루트 디렉터리/flexweb, 출력 폴더는 기본 E:\workspaces\sts\flexweb\flexweb-debug를 사용하고finish를 클릭하십시오.4: 변환이 완료되면 디렉터리가 변경됩니다. 오른쪽 단추 항목>properties>flex 구축 경로, 메인 소스 폴더는flex_로 변경됩니다.src, 그리고 자동으로 생성된 src 디렉터리의flexweb.mxml에서 flex_로 이동src하, 환경 구축은 완성된 셈
HelloWorld
flexweb.mxml:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
protected function myFlex_resultHandler(event:ResultEvent):void{
var name:String=event.result as String;
Alert.show(name);
}
protected function button1_clickHandler(event:MouseEvent):void
{
myFlex.sayHello(txtName.text);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- ( 、 ) -->
<s:RemoteObject id="myFlex" destination="mytest" result="myFlex_resultHandler(event)"/>
</fx:Declarations>
<s:Button x="209" y="135" label=" " click="button1_clickHandler(event)"/>
<s:TextInput x="166" y="81" id="txtName"/>
<s:Label x="10" y="81" text=" :" fontSize="15" fontWeight="bold" fontFamily=" "/>
</s:Application>
그 가운데자바를 호출하는 클래스 Hello를 지정했습니다. mytest는remoting-config에 대응합니다.xml
WEB-INFO/flex 디렉토리에서 remoting-config.xml 가입
<destination id="mytest">
<properties>
<source>com.hongbo.Hello</source>
</properties>
</destination>
result에 대응하는 것은 자바 방법이 호출한 리셋 함수입니다.일반 자바 클래스 만들기
package com.hongbo;
public class Hello {
public String sayHello(String name){
System.out.println("------------------------------------");
return "Hello First Demo " + name;
}
}
이렇게 하면 오케이.액세스 경로는 http://localhost:8080/flexweb/flexweb-debug/flexweb.html
첫 번째 회보 404,problems 알림 html 패키지를 만들 수 없음, 오른쪽 단추를 누르면 템플릿 다시 만들기
Spring 지원 추가
1:web.xml 가입
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml </param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
2:src에서 응용 프로그램 컨텍스트를 만듭니다.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="hello" class="com.hongbo.Hello">
<property name="testSpring">
<ref bean="testSpring"/>
</property>
</bean>
<bean id="testSpring" class="com.hongbo.test.impl.TestSpringImpl"/>
</beans>
3:WEB-INF/flex/service-config.xml 가입
<factories>
<factory id="spring" class="com.hongbo.SpringFactory" />
</factories>
자바 클래스 추가
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
<destination id="mytest">
<properties>
<factory>spring</factory>
<source>hello</source>
</properties>
</destination>
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, 마운트 해제, flashplayer10r12_ 다운로드36_winax_debug.exe, 설치, 마운트 해제 후 구글 브라우저가 영향을 미치지 않는 것 같습니다. 그리고 eclipse는 기본 브라우저를 IE, 윈도우>preferences>General>Webbrowser로 수정하고 Internet Explorer를 선택하십시오. 마지막으로tomcat을 시작한 후 mxml에서 debug를 오른쪽 단추로 눌러야 실행됩니다. 열려 있는 IE가trace를 출력하고 사이트에 직접 접근하면 안 됩니다.누락이 있으면 지적해 주십시오
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
flex는 웹 서비스를 이용하여 사진을 업로드하여 코드를 실현한다WebService 엔드 코드 Flex 클라이언트 코드...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.