2. flex-spring 연동

tendencyrheumaticInternet and Web Development

Nov 12, 2013 (3 years and 7 months ago)

642 views

1.

Flex


Spring
프로젝트

생성

-

Maven


이용하려했지만
, Maven
으로

Build


플렉스

프로젝트가

깨져버려
,

-

Flex Project
생성



Spring Library


추가해

사용하겠습니다
.

-


A.

Flex Project


생성합니다
.

i.

빨간색

칸을

보면

WTP
와의

연동으로

Flex


Java
소스를

같은

프로젝트에서

관리할



있습니다
.


ii.

J2EE
셋팅을

해줍니다
.






iii.

Finish


클릭합니다
.









2.

Server
윈도우에서
,
추가한

서버

선택



우클릭



Add and Remove Projects
선택합니다
.


A.

생성한

Flex
-
Spring
프로젝트를

선택

Add
버튼

클릭후

Finish



B.

Server Start
하고
, index.mxml


Run
합니다
.

다음과

같이

나오면

Flex
셋팅끝









3.

Spring
셋팅

A.

Java Perspective


이동후
,
프로젝트

선택후

우클릭으로

Preferences
창을

엽니다
.

i.

Java Build Path
에서

다음과

같이

기본

Source
폴더

구조를

만듭니다
.

src/main/java

src/main/resources

src/test/java



B.

프로젝트

우클릭

-
> Spring Tools
-
> Add Spring Project Nature
선택




Build


s


바뀌면

됩니다
.



C.

이제

Spring Library


추가해야합니다
.

i.

Spring


다운로드

받습니다
.

1.

http://www.springframework.org/download

2.

Spring Framework
2.5.4

is the current production release (requires Java 1.4+)



다운로드

(
spring
-
framework
-
2.5.4
-
with
-
dependencies.zip

)

3.

압축을

풀고
, dist
폴더안에

있는

2
개의

파일

A.

spring.jar
,
spring
-
sources.jar



contents ROOT


fle
x_spring/WEB
-
INF/lib


복사합니다
.


** Flex


Spring
연동의

핵심에는

flex
-
spring
-
factory.jar



있습니다
.



파일

역시

같은

곳에

복사합니다
.


이제

연동하는

부분을

보겠습니다
.


4.

소스

코딩

A.

I
ndex.mxml

<mx:RemoteObject id="remoteObject"



destination="workplan"



showBusyCursor="true"



fault="remoteObject_fs
(event)"



>



<mx:method name="getWorkPlanData" result="getWorkPlanData_rs(event)"/>


</mx:RemoteObject>


B.

WEB
-
INF/web.xml


추가

<listener>


<listener
-
class>org.springframework.web.context.ContextLoaderListener</listener
-
class>


</listener>


C.

WEB
-
INF/flex/se
rvice
-
config.xml
추가

<factories>



<factory id="spring" class="flex.samples.factories.SpringFactory"/>

</factories>


D.

WEB
-
INF/flex/remote
-
config.xml
추가

<destination id="workplan">


<properties>



<factory>spring</factory>



<source>workPlanService</source
>


</properties>

</destination>


E.

WEB
-
INF/applicationContext.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"


xsi:schemaLocation="http://www.spri
ngframework.org/schema/beans
http://www.springframework.org/schema/beans/spring
-
beans.xsd">




<import resource="classpath:applicationContext.xml"/>

</beans>


F.

src/main/resources
/applicationContext.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:context="http://www.springframework.org/schema/context"


xmlns:p="http://www.springframework.org/schema/p"


xmlns:tx="http://www.springframework.org
/schema/tx"


xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring
-
beans.xsd



http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring
-
context.xsd



htt
p://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring
-
tx.xsd">




<context:property
-
placeholder location="classpath:jdbc.properties"/>




<bean id="dataSource"



class="org.springframework.jdbc.datasource.DriverManagerDataS
ource"



p:driverClassName="${ jdbc.driverClassName}"



p:url="${ jdbc.url}"



p:username="${ jdbc.username}"



p:password="${ jdbc.password}"



/>





<bean id="workPlanService"



class="workplan.WorkPlanService"



p:workplanDao
-
ref="workPlanDao"



/>





<be
an id="workPlanDao"



class="workplan.WorkPlanDao"



p:dataSource
-
ref="dataSource"



/>

</beans>




G.

src/main/java/workplan/WorkPlan.java

package

workplan;


import

java.io.Serializable;


public

class

WorkPlan
implements

Serializable{


static

final

long

seri
alVersionUID

= 42L;




public

String
userId
;


public

String
workDate
;


public

String
workDescr
;




public

String getUserId() {



return

userId
;


}


public

void

setUserId(String userId) {



this
.
userId

= userId;


}


public

String getWorkDate() {



return

workDate
;


}


public

void

setWorkDate(String workDate) {



this
.
workDate

= workDate;


}


public

String getWorkDescr() {



return

workDescr
;


}


public

void

setWorkDescr(String workDescr) {



this
.
workDescr

= workDescr;


}

}






H.

src/main/java/workplan/Work
PlanService.java

package

workplan;


import

java.util.List;


public

class

WorkPlanService {


private

WorkPlanDao
workplanDao
;




public

void

setWorkplanDao(WorkPlanDao workplanDao) {



this
.
workplanDao

= workplanDao;


}




public

WorkPlanDao getWorkplanDao(
) {



return

workplanDao
;


}




public

List<WorkPlan>getWorkPlanData()


{



System.
out
.println(
"getWorkPlanData"
);



return

workplanDao
.getWorkPlanData();


}

}



I.

src/main/java/workplan/WorkPlanDao.java

package

workplan;


import

java.sql.ResultSet;

import

j
ava.sql.SQLException;

import

java.util.List;


import

org.springframework.jdbc.core.simple.ParameterizedRowMapper;

import

org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;


public

class

WorkPlanDao
extends

SimpleJdbcDaoSupport {




public

List<Work
Plan> getWorkPlanData()


{



String query =
"select user_id, work_date, work_descr from
tbt_work_history"
;






ParameterizedRowMapper<WorkPlan> rowMapper =




new

ParameterizedRowMapper<WorkPlan>(){








public

WorkPlan mapRow(ResultSet rs,
int

rowNum)





throws

SQLException




{





WorkPlan wp =
new

WorkPlan();





wp.setUserId(rs.getString(
"user_id"
));





wp.setWorkDate(rs.getString(
"work_date"
));





wp.setWorkDescr(rs.getString(
"work_descr"
));










return

wp;




}



};



return

getSimpleJdbcT
emplate().query(query, rowMapper);


}

}








J.

src/main/resources/jdbc.properties
추가

# Oracle Settings


jdbc.driverClassName=
oracle.jdbc.driver.OracleDriver

jdbc.url=
jdbc
:
oracle:thin:
@XX
.
XX
.
XXX
.
XXX
:1521:
SID

jdbc.username=
username

jdbc.password=
password



K.


렇게

하고
,
서버를

Restart
합니다
.

이러면

100%
에러가

-
_
-

dataSource


생성못한다고

나옵니다
.

C
ommon/lib


오라클

드라이버를

넣어주고

다시

시작하시면

문제는

해결됩니다
.