spring
-
[Spring] Spring AOP를 이용한 메서드 추적2014.02.13
[오류] java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
Spring + Maven 프로젝트 실행 시 다음과 같은 예외에 직면할 수 있습니다.
[오류]
심각: Servlet /Mybatis threw load() exception
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
Maven Dependency를 이용하여 추가한 Library들이 위의 Web Deployment Assembly에 등록되지 않은채 배포되기 때문에 java.lang.ClassNotFoundException 이 발생하게 된다.
Properties -> Deployment Assembly -> Add Click -> Java Build Path Entries -> Next -> Maven Dependencies -> Finish
실행하면 Console 창에 정상적인 로그가 출력됩니다.
'Programming > Spring' 카테고리의 다른 글
[Spring] org.xml.sax.SAXParseException: Document root element "configuration", must match DOCTYPE root "mapper" (0) | 2014.05.13 |
---|---|
[오류] org.springframework.jdbc.datasource.DataSourceTransactionManager 빈 생성 에러 (0) | 2014.05.13 |
spring mvc @ResponseBody, @RequestBody json + ajax (2) | 2014.03.12 |
[Spring] Spring AOP를 이용한 메서드 추적 (0) | 2014.02.13 |
spring social (0) | 2014.02.12 |
spring mvc @ResponseBody, @RequestBody json + ajax
spring기반 json + ajax 처리
mappingJacksonHttpMessageConverter는 @ResponseBody, @RequestBody 어노테이션 사용시 JSON String을 javaClass(get, set)에 자동으로 맵핑이 되도록 변환을 해주는 스프링 애너테이션입니다.
우선 MappingJacksonHttpMessageConverter 관련 bean 설정이 필요합니다.
-board-servlet.xml
<bean id=jacksonMessageConverter class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter ">
</bean>
<bean class=org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter>
<property name="messageConverters">
<list>
<ref bean="jacksonMessageConverter" />
</list>
</property>
</bean>
@RequestBody는 클라이언트에서 jsonObject로 전송되는 파라미터를 자동으로 javaClass 형식으로 변환한다. (UserBean Class 는 클라이언트에서 받을 파라미터를 get, set 으로 작성하면, bean에 등록된 massageConverters에서 자동으로 javaClass 형식에 맞게 컨버팅이 이뤄진다.)
@ResponseBody는 클라이언요청을 서버에서 처리 후 메소드가 리턴하는 오브젝트를 messageConverters를 통해 json 형태로 변환하여 리턴해주는 역활을 한다.
-UserController.java
@RequestMapping(value="getLoginCheck.ajax", method=RequestMethod.POST)
public @ResponseBody UserBean loginCheck(@RequestBody UserBean userBean){
logger.info("userBeanD.getJ_username(){}", userBean.getJ_username());
userBean = userService.getUsers(userBean.getJ_username());
return userBean;
}
ajax 통신을 위해 jquery ajax method 설정을 아래와 같이 jQuery로 선언해준다.
var _param = {j_username:$("#j_username").val(), j_password:$("#j_password").val()};
_data = JSON2.stringify(_param); //jsonString으로 변환
_url = "localhost:8080/login/getLoginCheck.ajax";
-common.js
$.ajax({
type : 'POST',
url : _url,
cache: false,
dataType: "json",
data: _data,
processData: false,
contentType: "application/json;
charset=utf-8",
success : function(data, status){
console.log("status:"+status+","+"data:"+data);
alert(data.nm);
},
error: function(request, status, error){
//alert("loading error:" + request.status);
console.log("code : " + request.statusText + "\r\nmessage : " + request.responseText);
}
});
'Programming > Spring' 카테고리의 다른 글
[오류] org.springframework.jdbc.datasource.DataSourceTransactionManager 빈 생성 에러 (0) | 2014.05.13 |
---|---|
[오류] java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet (0) | 2014.04.28 |
[Spring] Spring AOP를 이용한 메서드 추적 (0) | 2014.02.13 |
spring social (0) | 2014.02.12 |
spring mvc 모델 생성 (0) | 2014.02.11 |
[Spring] Spring AOP를 이용한 메서드 추적
Spring AOP 메서드 추적 Flow
Spring AOP를 활용한 메소드 흐름을 로깅한 로직을 정리합니다.
<!-- 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>
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]:=================================================
'Programming > Spring' 카테고리의 다른 글
[오류] java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet (0) | 2014.04.28 |
---|---|
spring mvc @ResponseBody, @RequestBody json + ajax (2) | 2014.03.12 |
spring social (0) | 2014.02.12 |
spring mvc 모델 생성 (0) | 2014.02.11 |
[Spring] Environment와 @PropertySource (0) | 2014.02.05 |