【发布时间】:2017-12-19 08:07:46
【问题描述】:
我可以定义一个 Spring ControllerAdvice,它可以通过自定义注解被一部分控制器选择性地使用:
@RestController
@UseAdviceA
@RequestMapping("/myapi")
class ApiController {
...
}
@ControllerAdvice(annotations = UseAdviceA.class)
class AdviceA {
...
}
但是是否可以通过自定义注释传递属性,建议类可以从注释中获取?例如:
@RestController
@UseAdviceA("my.value")
@RequestMapping("/myapi")
class ApiController {
...
}
@ControllerAdvice(annotations = UseAdviceA.class)
class AdviceA {
// Some way to get the string "myvalue" from the instance of UseAdviceA
...
}
任何其他实现相同结果的方法,即能够在可以传递给 ControllerAdvice 的 Controller 方法中定义自定义配置也将不胜感激。
【问题讨论】:
标签: java spring spring-mvc spring-boot