【问题标题】:Flex mySQL db connection with BlazedsFlex mySQL db 与 Blazeds 的连接
【发布时间】:2011-08-08 14:19:46
【问题描述】:

我目前正在编写一个小程序,并希望将 Blazeds 与 Flex 结合使用。 Blazeds 和我的 MySQL 数据库之间的连接工作正常,但是当我尝试通过正在运行的 catalina 服务器上的 RemoteObject 连接时,我总是收到一条错误消息:

[RPC Fault faultString="ID 为 'employeeService' 的目的地未向任何服务注册。" faultCode="Server.Processing" faultDetail="null"] 在 mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\ rpc\AbstractInvoker.as:216] 在 mx.rpc::Responder/fault()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\Responder.as:49] 在 mx.rpc::AsyncRequest/fault()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:103] 在 NetConnectionMessageResponder/statusHandler()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:523] 在 mx.messaging::MessageResponder/status()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\messaging\MessageResponder.as:222]

我检查了远程配置文件并且目标 ID 在那里。是否需要配置catalina?

【问题讨论】:

  • 修改配置文件后是否重启了服务器?

标签: apache-flex blazeds


【解决方案1】:

使用 Spring-Flex / Mysql / BlazeDS 4

在 lib 中需要 jars

sping-flex-core-1.5
mysql-connector-java-5.1.10
org.springframework.beans-3.0.5.RELEASE
org.springframework.context-3.0.5.RELEASE
org.springframework.jdbc-3.0.5.RELEASE..etc

创建员工 VO 动作脚本

[Bindable]
[RemoteClass (alias="com.model.employee.Employee")]
public class Employee

Java端包com.model.employee;

Employee.java

EmployeeService.java(接口)..getEmployeeById(int id)

EmployeeServiceImpl.java

@Service("employeeService")
@RemotingDestination(channels = { "my-amf", "my-secure-amf" })
public class EmployeeServiceImpl implements EmployeeService {

private final DataSource dataSource;

public UserServiceImpl(DataSource dataSource) {
    this.dataSource = dataSource;
}

@RemotingInclude
public Employee getEmployeeById(int id) {
    Employee employee= new Employee ();
    Connection c = null;
    try {
        c = this.dataSource.getConnection();
        PreparedStatement ps = c.prepareStatement("SELECT * FROM employee WHERE employee_id=?");
        ps.setInt(1, id);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            employee= new Employee();
            employee.setEmployeeId(rs.getInt("employee_id"));
            employee.setEmployeeName(rs.getString("employee_name"));
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    return employee;
}

将编译好的类放在 WEB-INF/classes 中

WEB-INF/appicationContext.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:flex="http://www.springframework.org/schema/flex"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/flex 
    http://www.springframework.org/schema/flex/spring-flex-1.5.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/jdbc
    http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">

<flex:message-broker>
  <flex:remoting-service default-channels="my-amf" />  
  </flex:message-broker>

<context:annotation-config />
<context:component-scan base-package="com.model" />

<tx:annotation-driven />

<bean id="employeeService" class="com.model.employee.EmployeeServiceImpl">
    <constructor-arg ref="dataSource" />        
</bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">

    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" 
    value="jdbc:mysql://dxfcmm:3306/eunice? autoReconnect=true&amp;zeroDateTimeBehavior=convertToNull"/>
    <property name="username" value="XXX" />
    <property name="password" value="YYY" />
  <property name="validationQuery" value="SELECT 1"/>
</bean>

不需要 remote-config.xml

启动tomcat,应该会看到 信息:远程目标“employeeService”已启动 成功。

在 MMXL [可绑定] 私有变量 empl:Employee;

用 resultHandler 定义 RemoteObject roEmp 调用 roEmp.getEmployeeById(id) empl= event.result as Employee;

【讨论】:

    【解决方案2】:

    我能想到的只是一些事情......

    • 确保您的 flex 项目设置正确以引用您的服务器。项目->属性->Flex 服务器。
    • 在配置服务器方面,您是否已将 flex-messaging 和 blazeds jar 添加到您的项目或服务器库中?
    • 虽然听起来很傻,但它实际上已经为我解决了这些问题,请确保在这些类型的更改后重新启动服务器,并清理您的项目、服务器和服务器工作目录(我'正在通过 Eclipse 在我的 Tomcat 服务器上执行此操作)
    • 如果您一直遇到问题并确信可能是配置问题,请使用turnkey

    【讨论】:

    • 我检查了我的 flex 应用程序的服务器配置,清理了 blazeds java 应用程序并启动并重新启动了我的 apache 服务器。顺便说一句,我已经使用了交钥匙。这有点好奇,但如果我尝试连接到提供的 hsqldb,我会将所有数据都发送到我想要的 flex 应用程序中。还是谢谢。
    猜你喜欢
    • 2011-07-05
    • 1970-01-01
    • 2011-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多