AOP

(。◠ ◠。)·2022년 8월 9일

국비 개발 훈련 일기

목록 보기
17/35

root-context에 적어 놓으면 일일이 메소드를 부르지 않아도 불러줍니다.
이름을 잘 맞춰야하지만....

AspectJ Weaver을 넣고 ->루트컨텍스트가서 체크해야 쓸수있어요

@Component("log4j")
public class Log4jAdvice {
	public void printLogging() {
		System.out.println("[공통로그-log4j] 비즈니스 로직 수행 전 동작");
	}

}
@Service
public class BoardServiceImpl implements IBoardService{
	
//	private LogAdvice log;	
//	private Log4jAdvice log;	
	
	public BoardServiceImpl() {
//		log = new LogAdvice();
//		log = new Log4jAdvice();
	}

	@Override
	public void insertBoard(BoardDTO dto) {
//		log.printLog();
//		log.printLogging();
		System.out.println("board insert");
	}

	@Override
	public List<BoardDTO> getList() {
		List<BoardDTO> list = new ArrayList<>();
//		log.printLog();
//		log.printLogging();
		System.out.println("get boardList");
		return list;
	}

}
	<aop:config>
		<aop:pointcut expression="execution(* org.zerock.service..*Impl.*(..))" 
		id="allpointcut"/>
<!-- 		org.zerock.service..*Impl -->
<!-- service다음은 아무거나 근데 Imlp로 끝나야 함. -->
		
		<aop:pointcut expression="execution(* org.zerock.service..*Impl.get*(..))" 
		id="getpointcut"/>
<!-- 		get으로 시작하는 메소드에 한정 -->
		
<!-- 		@Component("log")라고 붙인 LogAdvice.java의 printLog라는 메소드이름-->
<!-- 		<aop:aspect ref="log"> -->
<!-- 		after나 before 있어요 -->
<!-- 			<aop:after pointcut-ref="allpointcut" method="printLog"/> -->
<!-- 		</aop:aspect> -->

		<aop:aspect ref="log4j">
			<aop:after pointcut-ref="allpointcut" method="printLogging"/>
		</aop:aspect>
		
		
	</aop:config>	
profile
화이탱!

0개의 댓글