自己制作的 Spring-Boot Starter,如何实现 当使用方集成了这个 Starter(假定使用方应用存在 Web 环境),根据使用方法在其应用的 properties 文件设置的路径,在其应用中生成一个对应路径的 HTTP 请求处理器。比如希望使用方集成了这个 Starter 后,他的应用就具备了类似于如下 Controller 的功能:
@RestController
public class NoticeController {
@GetMapping("/notice")
public Map<String, Object> notice(@RequestParam String groupId,
@RequestParam String dataId) {
logger.info("get notice, groupId={}, dataId={}", groupId, dataId);
JSONObject notice = new JSONObject(4);
notice.put("groupId", groupId);
notice.put("dataId", dataId);
// 根据 groupId 和 dataId 去查询数据
String detail = getDetailData(groupId, dataId);
notice.put("detail", detail);
return notice;
}
private String getDetailData(String groupId, String dataId) {
return "Hello World!";
}
}
然后假定使用方的应用的域名是 localhost,那么访问 localhost/notice?groupId=testGroup&dataId=testData
其中,"/notice"
这个路径是个示例,这个路径希望是支持自定义的(比如在 application.properties 文件里面,使用方设置属性 notice.path=somePath
)。
所以最终请教大家的问题:在 Spring-Boot Starter 中,如何根据用户指定的路径,生成对应的 HTTP 请求处理器?
自动配置+扫描你的controller包,不就搞定了