寫在前面:html
Flex是10年前的產物,基本也要退出歷史舞臺了,手裏有個Flex 項目,最近又在看SpringBoot方面的書,突發奇想,能不能整合一下。因爲Flex年代久遠,國內相關文獻實在是少的可憐。努力了幾天,終於成功了。寫這些就當記錄一下,萬一哪天有朋友也要配置,也不用走不少彎路。java
說幾個坑點:git
1:Spring Flex已經停用了大約3年以上。基本上它被拋棄了,而且和Spring 5不兼容。起初配置好後用SpringBoot 2.0啓動,提示Flex Bean _messageBroker初始化失敗,而且jar包中有一個JdkVersion方法報錯,由於這是Spring4.0方法。github
2:Blazdes 在spring-boot中只有4.7.3版本,Flex對象綁定java對象的時候,要添加白名單(4.7.3版本新功能)。web
下面上個人配置:spring
首先是pom.xml 添加相關依賴sql
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>pgfServer</groupId> <artifactId>pgfServer</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>pgfServer</name> <description>pgfServer project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <!--我是這個版本,切記不要用2.0以上.啓動報錯--> <version>1.5.10.RELEASE</version> <relativePath/> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <!--<exclusions>--> <!--<exclusion>--> <!--<artifactId>hibernate-entitymanager</artifactId>--> <!--<groupId>org.hibernate</groupId>--> <!--</exclusion>--> <!--</exclusions>--> </dependency> <dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>mssql-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> <version>1.5.13.RELEASE</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!--這裏添加blazeds依賴,版本4.7.3(也只有這個版本,估計之後也不會更新版本了.)--> <dependency> <groupId>org.apache.flex.blazeds</groupId> <artifactId>blazeds-spring-boot-starter</artifactId> <version>4.7.3</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> </build> </project>
配置文件:services-config.xml(路徑不能錯resouces/META-INF/flex)apache
(messaging-config.xml,proxy-config.xml,remoting-config.xml)這三個能夠不用配置tomcat
<?xml version="1.0" encoding="UTF-8"?>
<services-config>
<services>
<service id="remoting-service" class="flex.messaging.services.RemotingService">
<adapters>
<adapter-definition
id="java-object"
class="flex.messaging.services.remoting.adapters.JavaAdapter"
default="true"/>
</adapters>
<default-channels>
<channel ref="my-amf"/>
<!--<channel ref="my-secure-amf"/>
<channel ref="my-polling-amf"/>-->
</default-channels>
</service>
</services>
<!--添加白名單,blazdes 4.7.3版本新增功能-->
<validators>
<validator class="flex.messaging.validators.ClassDeserializationValidator">
<properties>
<allow-classes>
<class name="flex.messaging.io.amf.*"/>
<class name="com.pgfserver.common.flex.*"/>
<class name="flex.messaging.messages.*"/>
<class name="flex.messaging.io.*"/>
<class name="java.lang.*"/>
<class name="java.util.*"/>
</allow-classes>
</properties>
</validator>
</validators>
<channels>
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>false</polling-enabled>
<serialization>
<allow-xml>true</allow-xml>
</serialization>
</properties>
</channel-definition>
<channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
<endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
<properties>
<add-no-cache-headers>false</add-no-cache-headers>
</properties>
</channel-definition>
<channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
<endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>true</polling-enabled>
<polling-interval-seconds>4</polling-interval-seconds>
</properties>
</channel-definition>
</channels>
<flex-client>
<!-- Make sure clients are automatically expired -->
<timeout-minutes>720</timeout-minutes>
</flex-client>
<logging>
<!--
Logging inside BlazeDS is completely turned off.
The UniversalExceptionTranslator will handle logging
of exceptions inside Spring.
-->
<target class="flex.messaging.log.ConsoleTarget" level="None"/>
</logging>
</services-config>
服務端:app
@Controller //Created remoting destination with id 'userController' @RemotingDestination public class UserController extends BaseController{ @Autowired private UserRepository userRepository; //這個註解能夠省略,默認包含此方法 @RemotingInclude public String getUserAll(){ System.out.println("接收"); userRepository.findAll(); return "success"; } }
客戶端:
<s:RemoteObject id="userRemote"
destination="userController"
endpoint="http://localhost:8081/pgfServer/messagebroker/amf"
fault="error(event)"/>
調用java端:userRemote.getUserAll();
我到這裏發現失敗了,調試半天,結果發現是這個沒配置上去
applcation.properties裏面配置
server.context-path=/pgfServer
下面是我搜索的相關資料,文獻.
BlazeDS+Spring-Boot+Starter整合說明:
https://cwiki.apache.org/confluence/display/FLEX/BlazeDS+Spring-Boot+Starter
Apache Flex BlazeDS 4.7.3 更新相關說明:
https://github.com/apache/flex-blazeds/blob/master/RELEASE_NOTES
java遠程對象沒法綁定flex:
http://apache-flex-development.2333347.n4.nabble.com/DEFECT-BlazeDS-4-7-3-ISSUE-SerializationException-Creation-validation-for-class-quot-lt-myClass-gt-q-td63270.html