Using Spring-Flex / Mysql / BlazeDS 4
In lib need 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
Create Employee VO Actionscript
[Bindable]
[RemoteClass (alias="com.model.employee.Employee")]
public class Employee
Java side package com.model.employee;
Employee.java
EmployeeService.java (interface)..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;
}
Places complied classes in 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&zeroDateTimeBehavior=convertToNull"/>
<property name="username" value="XXX" />
<property name="password" value="YYY" />
<property name="validationQuery" value="SELECT 1"/>
</bean>
Do not require remote-config.xml
Fire up tomcat, should see
INFO: Remoting destination 'employeeService' has been started started
successfully.
IN MMXL
[Bindable]
private var empl:Employee;
define RemoteObject roEmp with resultHandler
call roEmp.getEmployeeById(id)
empl= event.result as Employee;