열이 아빠님의 글을 보고 http://koko8829.tistory.com/575 삽질을 시작했습니다.
사실 Spring Bean을 BlazeDS에서 사용하는 것은 이미 다른 사람들이 많이 만들었죠^^ 근데 스프링소스에서 공식적으로 지원을 해주다니 대단합니다^^ 제가 한번 해봤습니다-_-; 스프링과 BlazeDS의 기본만 알고 있어서 하는데에는 무리가 없었습니다-_-;

환경 : JDK 6 U 10 + Tomcat 6.0.18 + BlazeDS 3.2.0.3978 + Spring BlazeDS Integration 1.0.0.M1 + Flex SDK 3.2 + Flex Builder 3.0.2 + SpringFramework 2.5.6

SpringFramework 2.5.6 Download
BlazeDS 3.2.3978 Download
Spring BlazeDS Integration Download

쉬운 개발환경을 위해 플렉스빌더에서.....
New Flex Project -> Project name은 SpringBlazeDS, Web application을 선택하고, Application server type은 J2EE로 합니다 ^^ Next를 하시면 Target runtime은 Tomcat 6.0, Flex WAR파일은 BlazeDS를 다운로드해서 blazeds.war파일을 선택합니다. Finish를 때려줍니다-_-;

프로젝트의 Properties에서 Flex Server에 보면 Context root부분이 /WebContent로 되어있는데, /SpringBlazeDS로 바꿔줍니다.

라이브러리는 Spring에서 spring.jar, spring-webmvc.jar, Spring BlazeDS Integration에서 org.springframework.flex-1.0.0.M1.jar를 WEB-INF/lib폴더에 복사하면 됩니다.

자바쪽 셋팅을 해봅시다.
Webcontent/WEB-INF/web.xml파일을 열어서 수정합니다.
기존에는 MessageBrokerServlet을 사용해서 하는데, Spring BlazeDS Integration에서는 Spring Servlet을 사용합니다. MessageBroker Servlet을 servlet-mapping과 함께 지워주고, Spring Servlet을 선언합니다.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>SpringBlazeDS</display-name>

<context-param>
<param-name>flex.class.path</param-name>
<param-value>/WEB-INF/flex/hotfixes,/WEB-INF/flex/jars</param-value>
</context-param>

<!-- Http Flex Session attribute and binding listener support -->
<listener>
<listener-class>flex.messaging.HttpFlexSession</listener-class>
</listener>

<!-- Spring Dispatcher Servlet -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

설정파일을 작성하기 전에 초간단 스프링 빈을 하나 만들어봅시다.
service패키지를 하나 만들고, HelloService라는 클래스를 만듭시다.
package service;

public class HelloService {
public String sayHello(String name) {
return name + "! 메리추석!";
}
}

이제 /WebContent/WEB-INF/applicationContext.xml파일을 생성합니다.
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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<bean id="mySpringManagedMessageBroker"
class="org.springframework.flex.messaging.MessageBrokerFactoryBean" />

<!-- Maps request paths at /messagebroker to the BlazeDS MessageBroker -->
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"
p:mappings="/*=mySpringManagedMessageBroker" />

<!-- Dispatches requests mapped to a MessageBroker -->
<bean class="org.springframework.flex.messaging.servlet.MessageBrokerHandlerAdapter"/>

<bean id="helloService" class="service.HelloService" />

<bean id="hello"
class="org.springframework.flex.messaging.remoting.FlexRemotingServiceExporter"
p:messageBroker-ref="mySpringManagedMessageBroker"
p:service-ref="helloService"/>

</beans>

기존 MessageBroker가 Spring에 의해 관리된 MesssageBroker로 들어있는 것 같습니다. 그래서 Remote요청이 들어오면 Spring MessageBroker가 해당 destination을 찾아서 해주는 것 같습니다. 그리고, Spring Bean인 helloService를 불러오는 방법은 FlexRemotingServiceExporter를 이용해서 하는 것 같습니다. 요청하고 싶은 Bean을 FlexRemotingServiceExporter에 DI를 해서 사용하는 것이군요.
이곳에서 FlexRemotingServiceExporter의 id가 destination입니다^^ 저기서 hello로 정의했으니 Flex에서는 destination을 hello로 맞춰주면 되겠죠? ^^
나중에 destination을 추가하는 것은 service-config.xml에서 하는 것이 아니라 이곳에서 해야겠죠.
제가 잘못 이해하고 있는 것이 좀 많은 것 같아서...원문을 참조하세요~ ^^

이제 service-config.xml에 추가해야할 부분이 있습니다.
<services>
<service-include file-path="remoting-config.xml" />
<service-include file-path="proxy-config.xml" />
<service-include file-path="messaging-config.xml" />
<default-channels>
<channel ref="my-amf"/>
</default-channels>
</services>

아....중요합니다. default-channels를 추가해야합니다!

이제 클라이언트로 가봅시다.
SpringBlazeDS.xml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:RemoteObject id="srv" destination="hello" />
<mx:TextInput id="inputName" />
<mx:Button label="전송" id="btnConfirm" click="srv.sayHello(inputName.text)" />
<mx:Label id="labelResult" text="{srv.sayHello.lastResult}" />
</mx:Application>

RemoteObject로 sayHello함수를 input에 입력해서 결과를 Label에 쓰는 간단한 프로그램입니다.
서버를 실행시키고 실행해봅시다.
사용자 삽입 이미지
로그도 자세히 남는군요.
2008. 12. 27 오전 2:31:42 org.springframework.flex.messaging.servlet.MessageBrokerHandlerAdapter handle
정보: Channel endpoint my-amf received request.

젠장......어느카테고리에 넣어야 하지-_-; Spring에 넣자-_-;
머드초보 이 작성.

당신의 의견을 작성해 주세요.

  1. Comment RSS : http://mudchobo.tomeii.com/tt/rss/comment/371
  2. 열이아빠 2008/12/27 10:20  편집/삭제  댓글 작성  댓글 주소

    저는 이제 막 스프링 공부를 다시 시작하고 있습니다.
    아무래도 무개념 상태라..ㅠㅠ
    내년 정식 릴리즈 전에는 좀 준비를 해야 할텐데요.
    카테고리는 'Spring/Flex' 를 따로 만드셔도 좋지 않을까요.^^

    • 머드초보 2008/12/28 11:15  편집/삭제  댓글 주소

      저도 스프링 공부를 안한지오래돼서 ㅠ
      간만에 스프링프레임워크 홈페이지에 가니 많이 바뀌었더라구요^^
      이것저것 제품도 많이 나왔구요. 저도 공부를 다시 해봐야겠습니다 ㅠ

  3. 용용 2009/01/09 10:18  편집/삭제  댓글 작성  댓글 주소

    좋은 글 감사합니다. ^^

  4. 아이 2009/01/09 23:30  편집/삭제  댓글 작성  댓글 주소

    대박인데! 이런게 조금만 더 빨리 나왔더라면~!ㅠㅠ
    트랜젝션이랑 라우팅소스 적용할려면 별의별 삽질한걸 생각하면...ㅠㅠ

    • 머드초보 2009/01/14 17:23  편집/삭제  댓글 주소

      오..그런건가...-_-;
      이거 아직 정식버전 나오려면 아직 멀은 듯-_-;

  5. 비밀방문자 2009/01/19 19:02  편집/삭제  댓글 작성  댓글 주소

    관리자만 볼 수 있는 댓글입니다.

    • 머드초보 2009/01/20 00:40  편집/삭제  댓글 주소

      destination은 지정합니다.
      <mx:RemoteObject id="srv" destination="hello" />
      이 destination명은 FlexRemotingServiceExporter의 명과 같아야합니다

  6. 비밀방문자 2009/01/20 10:43  편집/삭제  댓글 작성  댓글 주소

    관리자만 볼 수 있는 댓글입니다.

    • 머드초보 2009/01/22 00:29  편집/삭제  댓글 주소

      음.....뭔가 잘못된 것도 없어보이는데....
      service-config에 이부분도 추가했나요?
      <default-channels>
      <channel ref="my-amf"/>
      </default-channels>
      전 이것때문에 몇시간 날린 적이 있습니다만-_-;
      정 안되시면 mudchobo@nate.com으로 문의주세요.

  7. OpenID Logo 이버리 2009/01/29 09:58  편집/삭제  댓글 작성  댓글 주소

    안녕하세요^^ 어제 메일보냈던 사람입니다..
    답장 잘받았습니다.. 감사합니다..

    프로젝트 생성시 WEB으로 선택하고 하니 잘되네요
    감사합니다.

  8. 비밀방문자 2009/01/30 09:11  편집/삭제  댓글 작성  댓글 주소

    관리자만 볼 수 있는 댓글입니다.

    • 머드초보 2009/01/30 15:59  편집/삭제  댓글 주소

      아....혹시...언제보내신건가요?ㅠ
      윗분 메일은 온 것 같은데...죄송합니다.
      여기서 써주세요 ^^

  9. 23456 2009/03/19 15:59  편집/삭제  댓글 작성  댓글 주소

    12345

  10. 도니도니 2009/04/20 14:56  편집/삭제  댓글 작성  댓글 주소

    안녕하세요~ LCDS로도 해보셨는지 궁금하네요.
    BlaseDS를 사용했을 시에는 잘 작동하는데 LCDS로는 안되네요.
    버전은 2.5, 2.6 두개 테스트 해보았습니다.
    먼가 설정을 잘못 한것인지 원래 LCDS는 안되는것인지 ..값비싼 LCDS를 지원한해줄리가..-_ -

    • 머드초보 2009/04/23 23:49  편집/삭제  댓글 주소

      LCDS는 제가 안해봤네요.
      음 LCDS는 안되는군요-_-
      왜 안되는지 모르겠네요 ㅠ 분명 일부기능을 오픈소스한걸로 알고있는데 ㅠ

[로그인][오픈아이디란?]

우선 service-config.xml파일을 수정해야합니다.
<factories>
  <factory id="springfactory" class="flex.messaging.factory.SpringFactory" />
</factories>
를 추가합니다.

그 다음 remote-config.xml파일을 수정해야합니다.
<destination id="productmanager">
 <properties>
  <factory>springfactory</factory>
  <source>productManager</source>
 </properties>
</destination>
자세히 보시면 factory는 위에 service-config.xml파일에 정의한 놈이고, source는 bean이름입니다.
즉 applicationContext.xml파일에 정의한 그 bean이름을 저기에 적어 놓으면 됩니다.
그러면 그 bean을 flex로 가져와서 쓸 수 있습니다.

아 그리고 프로젝트에서 이상하게 contextroot가 WebContent로 되어있는데 프로젝트이름으로 고쳐줍시다-_-;
프로젝트 이름에 대고 마우스오른쪽버튼(alt+enter) properties를 선택, Flex Server부분 클릭.
context root를 프로젝트이름(SpringAndBlazeds)으로 바꿔줍시다.

자 그러면 flex_src에 있는 SpringAndBlazeds.mxml을 수정해봅시다.
SpringAndBlazeds.mxml


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
applicationComplete="init();">

<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;

private function init():void {
var remoteObject:RemoteObject = new RemoteObject();
remoteObject.destination = "productmanager";
remoteObject.addEventListener(ResultEvent.RESULT, resultHandler);
remoteObject.addEventListener(FaultEvent.FAULT, faultHandler);
remoteObject.getProducts();
}

private function resultHandler(event:ResultEvent):void{
dg.dataProvider = event.result;
}

private function faultHandler(event:FaultEvent):void{
Alert.show("실패 메세지 : " + event.fault.message);
}
]]>
</mx:Script>

<mx:DataGrid id="dg" width="100%" height="100%" />
</mx:Application>

간단하게 Manager에 있는 getProducts를 호출해서 DataGrid에 넣는 코드입니다.

자 이제 실행해봅시다-_-;
이클립스 오른쪽아래에 server에다가 SpringAndBlazeds프로젝트를 추가합니다.
서버에 대고, 오른쪽버튼누르면, Add and Remove Project클릭해서 추가하면 됩니다.
서버를 가동합니다.
Run Flex Application을 실행해봅시다!-_-;
사용자 삽입 이미지


아....잘되....는.....군.....요......-_-;
머드초보 이 작성.

당신의 의견을 작성해 주세요.

  1. Comment RSS : http://mudchobo.tomeii.com/tt/rss/comment/239
  2. 검쉰 2008/03/20 15:52  편집/삭제  댓글 작성  댓글 주소

    좋은 정보 감사합니다. ;)
    한번 시도해봐야겠습니다. ㅎ

    • 머드초보 2008/03/24 08:18  편집/삭제  댓글 주소

      아네 항상 방문해주셔서 감사합니다 ^^
      스프링과의 연동은 정말 강력해요!-_-;

  3. 비밀방문자 2009/01/19 17:11  편집/삭제  댓글 작성  댓글 주소

    관리자만 볼 수 있는 댓글입니다.

    • 머드초보 2009/01/20 00:39  편집/삭제  댓글 주소

      안녕하세요! 소스는 지금 보고 계시는 게 소스입니다 ^^
      잘 안되시나요? 연락주세요~ ^^

  4. 비밀방문자 2009/06/28 03:04  편집/삭제  댓글 작성  댓글 주소

    관리자만 볼 수 있는 댓글입니다.

    • 머드초보 2009/07/03 09:35  편집/삭제  댓글 주소

      안녕하세요~
      입력 수정 삭제 모듈이라 함은 어떤걸 말씀하시는건가요? ㅠ

[로그인][오픈아이디란?]

이제 Manager클래스를 만들어봅시다.
실제로 BlazeDS를 이용해서 가져오는 놈은 이 Manager클래스가 되겠죠^^

Java Resources: src에서 오른쪽버튼 클릭하고, New를 해서 interface를 구현합니다.


package springapp.service;

import java.util.List;
import springapp.domain.Product;

public interface ProductManager {
public List<Product> getProducts();
}

getProducts라는 메소드가 하나 있군요! 구현해봅시다!!!

package springapp.service;

import java.util.List;

import springapp.dao.ProductDao;
import springapp.domain.Product;

public class ProductManagerImpl implements ProductManager {

private ProductDao productDao;

@Override
public List<Product> getProducts() {
return productDao.getProductList();
}

public void setProductDao(ProductDao productDao) {
this.productDao = productDao;
}
}

getProducts라는 함수는 Dao에서 getProductList를 호출하는 놈이네요.
요 아래에는 setter가 있네요. 이건 spring에서 DI를 하기위해 존재하는 setter입니다^^
서비스도 완성이 되었네요! 이제 설정파일을 작성해봅시다.

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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<!-- Enable @Transactional support -->
<tx:annotation-driven />

<!-- Enable @AspectJ support -->
<aop:aspectj-autoproxy />

<aop:config>
<aop:advisor pointcut="execution(* *..ProductManager.*(..))"
advice-ref="txAdvice" />
</aop:config>

<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="save*" />
<tx:method name="get*" read-only="true" />
</tx:attributes>
</tx:advice>

<bean id="productManager"
class="springapp.service.ProductManagerImpl">
<property name="productDao" ref="productDao" />
</bean>

</beans>

Dao부분의 설정파일인 applicationContext-ibatis.xml파일을 봅시다.
applicationContext-ibatis.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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="classpath:properties/jdbc.properties" />

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
p:username="${jdbc.username}" p:password="${jdbc.password}" />

<!-- Transaction manager for iBATIS Daos -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>

<!-- SqlMap setup for iBATIS Database Layer -->
<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation"
value="classpath:springapp/dao/SqlMapConfig.xml" />
</bean>

<!-- Add additional Dao definitions here -->
<bean id="productDao"
class="springapp.dao.ProductDaoImpl">
<property name="sqlMapClient" ref="sqlMapClient" />
</bean>

</beans>

jdbc.properties파일은 properties라는 package를 만들고, jdbc.properties파일을 넣어버립시다.

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://DB주소
jdbc.username=DB아이디
jdbc.password=DB비밀번호

이 설정들의 bean들의 관계를 보고 싶다면-_-;
Spring Elements에서 오른쪽버튼 클릭하고 properties를 선택.
Bean Support를 선택, Add한 뒤 두개의 설정파일(applicationContext.xml, applicationContext-ibatis.xml)선택.
Config set에서 New하고 Name에 applicationContext라고 하고, 두개다 체크 오케이~
그럼 이제 스프링 설정파일에서 에러를 찾아낼 수 있어요!
bean들의 관계를 그래프로도 볼 수 있네요!
Config set에 추가한 applicationContext에다가 마우스오른쪽버튼을 클릭하면 open graph로 볼 수 있어요!

이제 클라이언트 구현으로....다음 시간에-_-;

머드초보 이 작성.

당신의 의견을 작성해 주세요.

  1. Comment RSS : http://mudchobo.tomeii.com/tt/rss/comment/238
  2. 가을우체국 2010/01/21 17:47  편집/삭제  댓글 작성  댓글 주소

    안녕하세요?? 위에 있는 내용으로 작성 실행을 해보려고 하니
    아래에 있는 코드가 오류가 나네요.ㅠㅠ

    <bean id="productDao"
    class="springapp.dao.ProductDaoImpl">
    <property name="sqlMapClient" ref="sqlMapClient" />
    </bean>

    Build path is incomplete. Cannot find class file for com/ibatis/sqlmap/client/SqlMapClient 이란
    오류가 왜 나는지 알수가 없어서 글을 남겨 봅니다..ㅠㅠ

    혹 가능하심 함 봐주세요.. (네이트 :maroon0@nate.com )

    • 머드초보 2010/01/21 18:22  편집/삭제  댓글 주소

      그 클래스를 못찾는 것 보니....
      iBATIS라이브러리파일이 없는 것 같은데요.
      ibatis~~~.jar파일을 혹시 넣으셨나요?

[로그인][오픈아이디란?]
« Prev : 1 : 2 : 3 : 4 : Next »