整合Springboot+BlazeDS+Spring+Flex

写在前面:

    Flex是10年前的产物,基本也要退出历史舞台了,手里有个Flex 项目,最近又在看SpringBoot方面的书,突发奇想,能不能整合一下。由于Flex年代久远,国内相关文献实在是少的可怜。努力了几天,终于成功了。写这些就当记录一下,万一哪天有朋友也要配置,也不用走很多弯路。

    说几个坑点:

   1:Spring Flex已经停用了大约3年以上。基本上它被抛弃了,并且和Spring 5不兼容。起初配置好后用SpringBoot 2.0启动,提示Flex Bean _messageBroker初始化失败,并且jar包中有一个JdkVersion方法报错,因为这是Spring4.0方法。

  2:Blazdes 在spring-boot中只有4.7.3版本,Flex对象绑定java对象的时候,要添加白名单(4.7.3版本新功能)。

    下面上我的配置:

首先是pom.xml 添加相关依赖

<?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

(messaging-config.xml,proxy-config.xml,remoting-config.xml)这三个可以不用配置

<?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>

 

 服务端:

@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

 

 

转载于:https://my.oschina.net/return/blog/1830919

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值