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

Spring/Spring Quick Start

AOP ์—˜๋ฆฌ๋จผํŠธ

<aop:config>: AOP ์„ค์ •์˜ ๋ฃจํŠธ ์—˜๋ฆฌ๋จผํŠธ. ํ•˜์œ„ ์—˜๋ฆฌ๋จผํŠธ๋กœ <aop:pointcut>, <aop:aspect>๊ฐ€ ์žˆ๋‹ค.

<aop:pointcut>: ํฌ์ธํŠธ์ปท์„ ์ง€์ •ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•œ๋‹ค. ์—ฌ๋Ÿฌ ๊ฐœ ์ •์˜ํ•  ์ˆ˜ ์žˆ์œผ๋‚˜, ๊ฐ๊ฐ ์œ ์ผํ•œ ์•„์ด๋””๋ฅผ ํ• ๋‹นํ•ด์•ผ ํ•œ๋‹ค.

<aop:aspect>: ํ•ต์‹ฌ ๊ด€์‹ฌ์— ํ•ด๋‹นํ•˜๋Š” ํฌ์ธํŠธ์ปท ๋ฉ”์†Œ๋“œ์™€ ํšก๋‹จ ๊ด€์‹ฌ์— ํ•ด๋‹นํ•˜๋Š” ์–ด๋“œ๋ฐ”์ด์Šค ๋ฉ”์†Œ๋“œ๋ฅผ ๊ฒฐํ•ฉํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•œ๋‹ค.

public class LogAdvice{
		public void printLog(){
        		System.out.println("[๊ณตํ†ต ๋กœ๊ทธ] ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง ์ˆ˜ํ–‰ ์ „ ๋™์ž‘");
        }
}
<bean id="log" class="com.heidi.biz.board.common.LogAdvice"></bean>
    
<aop:config>
    <aop:pointcut expression="execution(* com.heidi.biz..*Impl.*(..))" id="allPointcut"/>
    <aop:pointcut expression="execution(* com.heidi.biz..*Impl.get*(..))" id="getPointcut"/>
    
    <aop:aspect ref="log">
    	<aop:before pointcut-ref="getPointcut" method="printLog" />
    </aop:aspect>
</aop:config>

์œ„์˜ ์ฝ”๋“œ๋ฅผ ํ•ด์„ํ•˜๋ฉด, getPointcut์œผ๋กœ ์„ค์ •ํ•œ ํฌ์ธํŠธ์ปท ๋ฉ”์†Œ๋“œ๊ฐ€ ํ˜ธ์ถœ๋  ๋•Œ

log๋ผ๋Š” ์–ด๋“œ๋ฐ”์ด์Šค ๊ฐ์ฒด์˜ printLog()๊ฐ€ ์‹คํ–‰๋˜๊ณ 

์ด๋•Œ printLog() ๋ฉ”์†Œ๋“œ ๋™์ž‘ ์‹œ์ ์ด <aop:before>๋ผ๋Š” ๋‚ด์šฉ์˜ ์„ค์ •์ด๋‹ค.

 

<aop:advisor>: aspect์™€ ๊ฐ™์€ ๊ธฐ๋Šฅ์„ ํ•˜๋‚˜, Advice ๊ฐ์ฒด์˜ ์•„์ด๋”” ๋˜๋Š” ๋ฉ”์†Œ๋“œ ์ด๋ฆ„์„ ํ™•์ธํ•  ์ˆ˜ ์—†์„ ๋•Œ, ์ฆ‰ ํŠธ๋žœ์žญ์…˜ ์„ค์ • ๊ฐ™์€ ํŠน์ˆ˜ํ•œ ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•œ๋‹ค. ์ด ์—˜๋ฆฌ๋จผํŠธ์— ๊ด€ํ•ด์„œ๋Š” ํŠธ๋žœ์žญ์…˜์—์„œ ๋‹ค๋ฃฐ ๊ฒƒ์ด๋‹ค.

 

 

'Spring > Spring Quick Start' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

JointPoint ๋ฉ”์†Œ๋“œ  (0) 2021.01.07
Advice ๋™์ž‘ ์‹œ์   (0) 2021.01.07
ํฌ์ธํŠธ์ปท ํ‘œํ˜„์‹  (0) 2021.01.07
AOP ์šฉ์–ด  (0) 2021.01.07
AOP ์„ค์ •ํ•˜๊ธฐ  (0) 2021.01.07
AOP๋ž€?  (0) 2021.01.07