springboot 跨域配置类及跨域请求配置
作者:m17054598469
这篇文章主要介绍了springboot 跨域配置类及跨域请求配置,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
下面通过代码看下springboot 跨域配置类,代码如下所示:
ackage org.fh.config; import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Component; /** * 说明:跨域访问处理 * 作者:FH Admin * from:fhadmin.cn */ @Component public class CORSFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; response.setContentType("textml;charset=UTF-8"); response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin")); response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Max-Age", "0"); response.setHeader("Access-Control-Allow-Headers","Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With,userId,token"); response.setHeader("Access-Control-Allow-Credentials", "true"); // 是否支持cookie跨域 response.setHeader("XDomainRequestAllowed", "1"); filterChain.doFilter(servletRequest, servletResponse); } @Override public void destroy() { } }
1.模型管理:web在线流程设计器、导入导出xml、复制流程、部署流程
2.流程管理:导入导出流程资源文件、查看流程图、根据流程实例反射出流程模型、激活挂起
3.运行中流程:查看流程信息、当前任务节点、当前流程图、作废暂停流程、指派待办人、自由跳转
4.历史的流程:查看流程信息、流程用时、流程状态、查看任务发起人信息
5.待办任务:查看本人个人任务以及本角色下的任务、办理、驳回、作废、指派一下代理人
6.已办任务:查看自己办理过的任务以及流程信息、流程图、流程状态(作废 驳回 正常完成)
补充:下面看下springboot跨域请求配置的两种方法
方式一:
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; @Configuration public class CorsConfig { private CorsConfiguration buildConfig() { CorsConfiguration corsConfiguration = new CorsConfiguration(); corsConfiguration.addAllowedOrigin("*"); // 允许任何域名使用 corsConfiguration.addAllowedHeader("*"); // 允许任何头 corsConfiguration.addAllowedMethod("*"); // 允许任何方法(post、get等) corsConfiguration.setAllowCredentials(true); return corsConfiguration; } @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", buildConfig()); // 对接口配置跨域设置 return new CorsFilter(source); } }
方式二:
import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration //加配置注解可以扫描到 public class WebConfig implements WebMvcConfigurer{ //跨域请求配置 @Override public void addCorsMappings(CorsRegistry registry) { WebMvcConfigurer.super.addCorsMappings(registry); registry.addMapping("/**")// 对接口配置跨域设置 .allowedHeaders("*")// 允许任何头 .allowedMethods("POST","GET")// 允许方法(post、get等) .allowedOrigins("*")// 允许任何域名使用 .allowCredentials(true); } }
到此这篇关于springboot 跨域配置类及跨域请求配置的文章就介绍到这了,更多相关springboot 跨域配置内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!