스프링

반응형
Spring AOP 메서드 추적 Flow

 

Spring AOP를 활용한 메소드 흐름을 로깅한 로직을 정리합니다.

Server.xml
<!-- spring aspect --> 
<bean id="loggingAspect" class="com.zz.framework.support.aspect.LoggingAspect" /> 
	<aop:config proxy-target-class="true"> 	
    <aop:aspect id="aspectLoggging" ref="loggingAspect"> 		
    	<aop:pointcut id="servicePointcut" expression="execution(* *..*.service.*Service*.*(..))" /> 		
    	<aop:around method="logAround" pointcut-ref="servicePointcut"  /> 	
    </aop:aspect> 
</aop:config>
 
LoggingAspect.java
public class LoggingAspect { 	
	private static final Logger logger = LoggerFactory.getLogger(LoggingAspect.class);
    
    public void logBefore(JoinPoint joinPoint) { 		
    	logger.debug("logBefore()"); 	
    }  	
    
    public void logAfter(JoinPoint joinPoint) { 		
    	logger.debug("logAfter()"); 	
    }  	
    
    /** 	 
    * 메소드 별 로그 앞뒤로 남기기 	 
    * @param joinPoint 	 
    * @return 	 
    * @throws Throwable 	 
    * @auther jp1020 2014. 1. 15. 	 
    */  	
    public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { 		
    	Object thisObj = joinPoint.getTarget(); 		
        String className = thisObj.getClass().getName(); 		
        Object[] args = joinPoint.getArgs(); 		
        long currentTime = System.currentTimeMillis();  		
      
        if(logger.isDebugEnabled()) { 			
        	logger.debug("================================================="); 			
        	logger.debug(">>>>>>>>> LOGGING START >>>>>>>>>>"); 			
            logger.debug("[class]:" + className); 			
            logger.debug("[method]:" + joinPoint.getSignature().getName() + "()"); 	
        }  		
        
        Object returnObj = joinPoint.proceed(); 		
        
        if(logger.isDebugEnabled()) { 			
        	logger.debug("[class]:" + className); 			
            logger.debug("[method]:" + joinPoint.getSignature().getName() + "()"); 	
            logger.debug("[소요시간]: {}ms", new Object[]{(System.currentTimeMillis()-currentTime)}); 
            logger.debug(">>>>>>>>>> LOGGING END >>>>>>>>>>"); 			
            logger.debug("================================================="); 		
        } 		
        
        return returnObj; 	
    } 
            
}

 

페이지 호출시 Console창에 출력된 로그를 확인 합니다.
[2014-02-13 17:52:23] DEBUG [LoggingAspect.logAround():46]:================================================= 
[2014-02-13 17:52:23] DEBUG [LoggingAspect.logAround():47]:>>>>>>>> LOGGING START >>>>>>> 
[2014-02-13 17:52:23] DEBUG [LoggingAspect.logAround():48]:[class]:com.zz.board.business.board.service.impl.BoardServiceImpl 
[2014-02-13 17:52:23] DEBUG [LoggingAspect.logAround():49]:[method]:listBoard() 
[2014-02-13 17:52:23] DEBUG [AbstractBeanFactory.doGetBean():246]:Returning cached instance of singleton bean 'loggingAspect'  

내용생략......... 

[2014-02-13 17:52:23] DEBUG [LoggingAspect.logAround():55]:[class]:com.zz.board.business.board.service.impl.BoardServiceImpl 
[2014-02-13 17:52:23] DEBUG [LoggingAspect.logAround():56]:[method]:listBoard() 
[2014-02-13 17:52:23] DEBUG [LoggingAspect.logAround():57]:[소요시간]: 281ms 
[2014-02-13 17:52:23] DEBUG [LoggingAspect.logAround():58]:>>>>>>>> LOGGING END >>>>>>>> 
[2014-02-13 17:52:23] DEBUG [LoggingAspect.logAround():59]:=================================================

 

 

반응형
반응형
Spring Ajax 설정

 

JsonView 설정을 이용하여 AJAX를 사용할 수 있게 설정하는 과정을 포스트 합니다.

pom.xml과 dispatcher에는 기본적으로 등록 

pom.xml
             net.sf.json-lib             json-lib             2.4             jdk15              org.codehaus.jackson      jackson-mapper-asl      1.6.4   

 

DispatcherServlet XML 설정파일
        
-web.xml
     action     *.do       action     *.ajax  
-TestController.java
@RequestMapping("/test.do") 
public String test(@ModelAttribute("searchVO") CommentVO commentVO, ModelMap model) throws Exception {     
	return "test/test"; 
}   

@RequestMapping("/test.ajax") 
public ModelAndView testAjax(@ModelAttribute("searchVO") CommentVO commentVO, ModelMap model) throws Exception {
	Map resultMap = new HashMap();     
    resultMap.put("result1", "test1");     
    resultMap.put("result2", "test222");       
    
    ModelAndView modelAndView = new ModelAndView("jsonView",resultMap);     
    return modelAndView; 
}
 
Test.jsp
  

 

 

반응형

+ Recent posts

반응형