anyframe-lab3-container :: Any Frame - lab 3 2010.03.17

1. Bean 상속

<bean id="parent" abstract="true">
  <property name="userDAO" ref="userDAO" /> 
</bean>

<bean id="com.sds.emp.services.user.UserService"
  class="com.sds.emp.services.user.impl.UserServiceImpl"
  parent="parent">
</bean>

2. Bean의 상속 Lifecycle

<bean id="com.sds.emp.services.user.UserService"
  class="com.sds.emp.services.user.impl.UserServiceImpl"
  init-method="userInitialize" destroy-method="userDestroy" parent="parent">
</bean>

: UserServiceImpl 초기화시 userInitialize 메서드 실행, 소멸시 userDestroy 메서드 실행

3. Container활용테스트

<bean id="configurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
    <list>
      <value>userConfigurer.txt</value>
   </list>
  </property>
</bean>

: 속성파일 지정

<bean id="com.sds.emp.services.user.UserService"
  class="com.sds.emp.services.user.impl.UserServiceImpl" init-method="userInitialize" destroy-method="userDestroy">
        <property name="userDAO" ref="userDAO" />
        <!-- TODO : set userCompany value using key name in properties file -->
        <property name="userCompany" value="${user.company}"></property>
</bean>

: UserServiceImpl 에 userConfigurer.txt 파일의 user.company 값이 설정 됨.

4. MessageSource를 활용한 국제화 :: MessageResource 사용

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
         <property name="basenames">
          <list> 
           <value>
            userMessages
           </value>
          </list>
         </property>
</bean>

: userMessages.properties , userMessages_en.properties 메세지 파일 사용 지정.

UserServiceImpl.java 에 MessageSourceAware 을 implements 한다.

UserServiceImpl.java 에서
System.out.println(new String(messageSource.getMessage("argument.required", new Object[] {"userVO"}, Locale.KOREA).getBytes("8859_1"), "euc-kr"));

로 메세지를 사용.

5. Custom Event :: 사용자 이벤트 작성(요약 못함)

anyframe-lab4-annotation :: Any Frame - lab 4 2010.03.17

1. 속성 정의 xml 파일에 Annotation인식을 위한 태그 추가

<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"
       xsi:schemalLocation="
http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                            http://www.springframework.org/schema/context
                            http://www.springframework.org/schema/contxt/spring-context-2.5.xsd">      
<context:annotation-config/>
</beans>


: <context:annotation-config/> 대신 <context:component-scan base-package="com.sds.emp.services.user" /> 으로 대체 가능

2. Managed Components

-. @Service
서비스 레이어를 구성하는 대상 클래스를 정의하는데 사용한다. (ex:@Service("UserServiceA"))
-. @Controller
프리젠테이션 레이어를 구성하는 Controller 클래스를 정의하는데 사용하며, SpringMVC 기반인 경우에 활용 가능하다.
-. @Repository
데이터 접근 레이어를 구성하는 클래스를 정의하는데 사용하며, 퍼시스턴스 레이어에서 발생한 Exception에 대한 Translation이 지원된다
-. @Scope("prototype")


3. Dependency Injection
: 특정 Bean의 기능 수행을 위해 다른 Bean을 참조해야 하는 경우 사용하는 Annotation으로는 @Autowired 또는 @Resource가 있다.

-. @Autowired : 필드, 생성자, 입력파라미터가 여러개인 메소드(@Qualifier는 메소드의 파라미터)에 적용 가능
-. @Resource : 필드, 입력 파라미터가 한 개인 빈 프로퍼티 setter 메소드에 적용가능

anyframe-lab5-aop :: Any Frame - lab 5 2010.03.17

1. AOP 구성 요소

-. JoinPoint(시점) : Crosscutting Concerns 모듈이 삽입되어 동작할 수 있는 실행 가능한 특정 위치를 말한다. 예를 들어 메소드가 호출되는 부분 또는 리턴되는 시점이 하나의 JoinPoint가 될 수 있다. 또 필드를 액세스하는 부분, 인스턴스가 만들어지는 지점, 예외가 던져지는 시점, 등이 대표적인 JoinPoint가 될 수 있다. 각각의 JoinPoint들은 그 전후로 Crosscutting Concerns의 기능이 AOP에 의해 자동으로 추가되어져서 동작할 수 있는 후보지가 되는 것이다.

-. Pointcut(대상) : Pointcut은 어느 JoinPoint를 사용할 것인지를 결정하는 선택 기능을 말한다. AOP가 항상 모든 모듈의 모든 JoinPoint를 사용할 것이 아니기 때문에 필요에 따라 사용해야 할 모듈의 특정 JoinPoint를 지정할 필요가 있다. 일종의 JoinPoint 선정 룰과 같은 개념으로 다음과 같은 Pattern Matching 방법들을 이용하여 룰을 정의할 수 있다.

-. Pointcut Designators : 지시자, Pointcut 정의 방법

-. Advice : Advice는 각 JoinPoint에 삽입되어져 동작할 수 있는 코드로 동작 시점은 pointcut에 Matching되는 JoinPoint 실행 전후이며 before, after, after returning, after throwing, around 중에서 선택 가능하다.

-. Aspect : Aspect는 어디에서(Pointcut) 무엇을 할 것인지(Advice)를 합쳐놓은 것을 말한다

2. 설정

2.1 - 기본

<?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:aop="
http://www.springframework.org/schema/aop"
 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">  

<bean id="printStringAspect"
  class="integration.anyframe.services.aop.aspect.xml.PrintStringUsingXML" />  
<aop:config>
  <aop:aspect ref="printStringAspect">
   <aop:pointcut id="getMethods"
    expression="execution(public * integration.anyframe.services..*Impl.get*(..))" />
   <aop:pointcut id="updateMethods"
    expression="execution(public * integration.anyframe.services..*Impl.update*(..))" />
       
   <aop:before method="beforeExecuteGetMethod"
    pointcut-ref="getMethods" />
   <aop:after-returning method="afterReturningExecuteGetMethod"
    returning="retVal" pointcut-ref="getMethods" />
   <aop:after-throwing method="afterThrowingExecuteGetMethod"
    throwing="exception" pointcut-ref="getMethods" />
   <aop:after method="afterExecuteGetMethod"
    pointcut-ref="getMethods" />
   <aop:around method="aroundExecuteUpdateMethod"
    pointcut-ref="updateMethods" />
  </aop:aspect>
 </aop:config>
</beans>

 2.2 Annotation 사용

 


+ Recent posts