@RequestMapping("/addrExport.spr") public class AddrExportController @RequestMapping(params = "method=exportDynamicQueryData") public void exportDynamicQueryData(HttpServletRequest request, HttpServletResponse response, String downLoadData) { System.out.println("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"); ..... }
server { listen 8888; ...... location /portal/space-addr/ { proxy_pass http://localhost:8299/space-addr/; } ..... }
location /portal/space-addr/ {
proxy_pass http://localhost:8299/;
}
类全文如下:
1 @Configuration 2 public class CommonConfig { 3 4 @Value("${pub.commonservice.prefix}") 5 String prefix; 6 7 @Bean 8 public ResCommonServiceController registerCommonServiceController() { 9 return new ResCommonServiceController(); 10 } 11 12 @Autowired 13 public void registerCommonServerMapping(ResCommonServiceController registerCommonServiceController, RequestMappingHandlerMapping mapping) { 14 String uri = "/rescommon/service/"; 15 RequestMappingInfo requestMappingInfo = RequestMappingInfo.paths(uri).build(); 16 ResRequestMappingHandlerMapping resRequestMappingHandlerMapping = new ResRequestMappingHandlerMapping(mapping, requestMappingInfo); 17 resRequestMappingHandlerMapping.detectHandlerMethods(registerCommonServiceController); 18 if (!("".equals(prefix) || prefix == null || "${pub.commonservice.prefix}".equals(prefix))) { 19 String[] split = prefix.split(","); 20 for (String prefix1 : split) { 21 ResRequestMappingHandlerMapping resRequestMappingHandlerMapping1 = new ResRequestMappingHandlerMapping(mapping, RequestMappingInfo.paths(prefix1 + uri).build()); 22 resRequestMappingHandlerMapping1.detectHandlerMethods(registerCommonServiceController); 23 } 24 } 25 } 26 }
1 public class ResRequestMappingHandlerMapping extends RequestMappingHandlerMapping { 2 3 /** 4 * 代理对象 5 */ 6 private RequestMappingHandlerMapping requestMappingHandlerMapping; 7 8 /** 9 * 存放类的RequestMapping信息 10 */ 11 RequestMappingInfo typeMapping; 12 13 public ResRequestMappingHandlerMapping(RequestMappingHandlerMapping requestMappingHandlerMapping, RequestMappingInfo typeMapping) { 14 this.requestMappingHandlerMapping = requestMappingHandlerMapping; 15 this.typeMapping = typeMapping; 16 } 17 18 @Override 19 public void detectHandlerMethods(final Object handler) { 20 if(handler == null){ 21 return; 22 } 23 Class<?> handlerType = (handler instanceof String ? getApplicationContext().getType((String) handler) : handler.getClass()); 24 final Class<?> userType = ClassUtils.getUserClass(handlerType); 25 26 Map<Method, RequestMappingInfo> methods = MethodIntrospector.selectMethods(userType, new MethodIntrospector.MetadataLookup<RequestMappingInfo>() { 27 public RequestMappingInfo inspect(Method method) { 28 try { 29 return getMappingForMethod(method, userType); 30 } 31 catch (Exception ex) { 32 throw new IllegalStateException("Invalid mapping on handler class [" + userType.getName() + "]: " + method, ex); 33 } 34 } 35 }); 36 37 if (logger.isDebugEnabled()) { 38 logger.debug(methods.size() + " request handler methods found on " + userType + ": " + methods); 39 } 40 for (Map.Entry<Method, RequestMappingInfo> entry : methods.entrySet()) { 41 Method invocableMethod = AopUtils.selectInvocableMethod(entry.getKey(), userType); 42 RequestMappingInfo mapping = entry.getValue(); 43 if (typeMapping != null) { 44 mapping = typeMapping.combine(mapping); 45 } 46 requestMappingHandlerMapping.registerMapping(mapping, handler, invocableMethod); 47 } 48 }
至此,谜题解开了,因为公共侧对ResCommonServiceController类做了特殊定制,使其发布的@RequestMapping方法发布了两个http服务。。所以nginx的转发规则带不带前缀都不影响功能使用。。