아키텍처와 함께

블로그 이미지
by gregorio
  • Total hit
  • Today hit
  • Yesterday hit

Spring Framwork의 Controller에 정의되어 있는 모든 RequestMapping의 정보를 추출이 필요할 때가 있다.

 

이 경우 간단한 Controller를 생성하여 정보를 추출할 수 있다.

 

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

import com.lgcns.spring.base.BaseController;
import com.lgcns.spring.base.BaseMap;



@Controller
public class RequestController extends BaseController{

@Autowired
private RequestMappingHandlerMapping handlerMapping;


@RequestMapping(value = "/endPoint.do", method=RequestMethod.POST)
@ResponseBody
public List getEndPoints(Model model) throws Exception {
List result = new ArrayList();
for (RequestMappingInfo key : handlerMapping.getHandlerMethods().keySet()) {
BaseMap map = new BaseMap();
map.put("name", key.getName());
map.put("path", key.getPatternsCondition());
map.put("methods", key.getMethodsCondition());
map.put("consumes", key.getConsumesCondition());
map.put("produces", key.getProducesCondition());
map.put("params", key.getParamsCondition());
map.put("headers", key.getHeadersCondition());
map.put("custom", key.getCustomCondition());
result.add(map);
}

return result;
}

}

RequestMappingHandlerMapping를 이용하여 Mapping 정보를 추출한 후 Json형식으로 화면에 보여주고 있다.

AND

ARTICLE CATEGORY

분류 전체보기 (56)
Spring Framrwork (33)
Linux (1)
APM (1)
Java (8)
python (0)
ant (1)
chart (1)
OS (1)
tomcat (1)
apache (1)
database (0)

RECENT ARTICLE

RECENT COMMENT

CALENDAR

«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

ARCHIVE

LINK