๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Spring/Spring Quick Start

AOP ์„ค์ •ํ•˜๊ธฐ

1. pom.xml ์ค‘ AOP ๊ด€๋ จ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ถ”๊ฐ€

    <!-- AspectJ -->
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>${org.aspectj-version}</version>
    </dependency>
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjweaver</artifactId>
      <version>1.8.8</version>
    </dependency>

2. applicationContext.xml์— aop ๋„ค์ž„์ŠคํŽ˜์ด์Šค ์ถ”๊ฐ€

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

	<context:component-scan base-package="com.springbook.biz" />
	
	<bean id="log" class="com.springbook.biz.common.LogAdvice"></bean>
	<aop:config>
		<aop:pointcut id="allPointcut"
			expression="execution(* com.springbook.biz..*Impl.*(..))" />
		<aop:pointcut id="getPointcut"
			expression="execution(* com.springbook.biz..*Impl.get*(..))"/>
				
		<aop:aspect ref="log">		
			<aop:after pointcut-ref="getPointcut" method="printLog" />
		</aop:aspect>
	</aop:config>	
	 
</beans>