普通类获取spring的bean对象
解决方法:
假如我想在普通类中获取CustomJdbcTemplate对象
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes == null) {
throw new RuntimeException("非web请求,非法调用!");
} else {
HttpServletRequest request = attributes.getRequest();
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(request.getServletContext());
CustomJdbcTemplate jdbcTemplate = ac.getBean(CustomJdbcTemplate.class);
}
向大家推荐《Activiti工作流实战教程》:https://xiaozhuanlan.com/activiti