赞
踩
server.servlet.context-path
这个属性去配置@Configuration public class WebConfig implements WebMvcConfigurer { @Override public void configurePathMatch(PathMatchConfigurer configurer) { AntPathMatcher antPathMatcher = new AntPathMatcher("."); configurer.addPathPrefix("/admin-api", clazz-> { try { MetadataReader mdr = new CachingMetadataReaderFactory().getMetadataReader(clazz.getName()); if (mdr.getAnnotationMetadata().isAnnotated(Controller.class.getName()) && antPathMatcher.match("**.controller.admin.**", clazz.getPackage().getName())) { return true; } } catch (IOException e) { } return false; }); configurer.addPathPrefix("/web-api", clazz-> { try { MetadataReader mdr = new CachingMetadataReaderFactory().getMetadataReader(clazz.getName()); if (mdr.getAnnotationMetadata().isAnnotated(Controller.class.getName()) && antPathMatcher.match("**.controller.web.**", clazz.getPackage().getName())) { return true; } } catch (IOException e) { } return false; }); } }
package com.zzhua.controller.web; // 包名,所在包
@RestController
@RequestMapping("test")
public class TestController {
@GetMapping("test01")
public String test01() {
return "ok";
}
}
如果要访问在 com.zzhua.controller.web
(满足设置的条件:**.controller.web.**
)这个包下的TestController#test01
这个接口,需要添加上/web-api
作为前缀,即:http://localhost:8085/web-api/test/test01
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。