获取当前controller bean

@Autowired
private RequestMappingHandlerMapping requestMappingHandlerMapping;

@Autowired
private ApplicationContext applicationContext;
@Autowired
private HttpServletRequest request;


Map<RequestMappingInfo, HandlerMethod> handlerMethods = requestMappingHandlerMapping.getHandlerMethods();
try {
HandlerExecutionChain handler = requestMappingHandlerMapping.getHandler(request);
org.springframework.web.method.HandlerMethod.HandlerMethod method = (org.springframework.web.method.HandlerMethod.HandlerMethod)handler.getHandler();

Object bean = method.getBean();
    Class<?> beanType = method.getBeanType();
System.out.println(
"11"
);
}catch (Exception e){

}
posted @ 2022-12-16 11:10  蟑螂恶霸的开发笔记  阅读(94)  评论(0编辑  收藏  举报