springboot 跨域配置類(lèi)及跨域請(qǐng)求配置
下面通過(guò)代碼看下springboot 跨域配置類(lèi),代碼如下所示:
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; /** * 說(shuō)明:跨域訪問(wèn)處理 * 作者: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在線流程設(shè)計(jì)器、導(dǎo)入導(dǎo)出xml、復(fù)制流程、部署流程
2.流程管理:導(dǎo)入導(dǎo)出流程資源文件、查看流程圖、根據(jù)流程實(shí)例反射出流程模型、激活掛起
3.運(yùn)行中流程:查看流程信息、當(dāng)前任務(wù)節(jié)點(diǎn)、當(dāng)前流程圖、作廢暫停流程、指派待辦人、自由跳轉(zhuǎn)
4.歷史的流程:查看流程信息、流程用時(shí)、流程狀態(tài)、查看任務(wù)發(fā)起人信息
5.待辦任務(wù):查看本人個(gè)人任務(wù)以及本角色下的任務(wù)、辦理、駁回、作廢、指派一下代理人
6.已辦任務(wù):查看自己辦理過(guò)的任務(wù)以及流程信息、流程圖、流程狀態(tài)(作廢 駁回 正常完成)
補(bǔ)充:下面看下springboot跨域請(qǐng)求配置的兩種方法
方式一:
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()); // 對(duì)接口配置跨域設(shè)置 ? ? ? ? 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{ ? ?? ? ? //跨域請(qǐng)求配置 ? ? @Override ? ? public void addCorsMappings(CorsRegistry registry) { ? ? ? ? WebMvcConfigurer.super.addCorsMappings(registry); ? ? ? ? registry.addMapping("/**")// 對(duì)接口配置跨域設(shè)置 ? ? ? ? ? ? ? ? .allowedHeaders("*")// 允許任何頭 ? ? ? ? ? ? ? ? .allowedMethods("POST","GET")// 允許方法(post、get等) ? ? ? ? ? ? ? ? .allowedOrigins("*")// 允許任何域名使用 ? ? ? ? ? ? ? ? .allowCredentials(true); ? ? } ? ?? }
到此這篇關(guān)于springboot 跨域配置類(lèi)及跨域請(qǐng)求配置的文章就介紹到這了,更多相關(guān)springboot 跨域配置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- springboot項(xiàng)目數(shù)據(jù)庫(kù)配置類(lèi)DatabaseConfig示例詳解
- SpringBoot控制配置類(lèi)加載順序方式
- SpringBoot通過(guò)自定義注解實(shí)現(xiàn)配置類(lèi)的自動(dòng)注入的實(shí)現(xiàn)
- SpringBoot整合Web之CORS支持與配置類(lèi)和 XML配置及注冊(cè)攔截器
- Springboot自動(dòng)配置與@Configuration配置類(lèi)詳解
- SpringBoot中的配置類(lèi)(@Configuration)
- SpringBoot2底層注解@Configuration配置類(lèi)詳解
- springboot如何實(shí)現(xiàn)導(dǎo)入其他配置類(lèi)
相關(guān)文章
Java8時(shí)間api之LocalDate/LocalDateTime的用法詳解
在項(xiàng)目中,時(shí)間的使用必不可少,而java8之前的時(shí)間api?Date和Calander等在使用上存在著很多問(wèn)題,于是,jdk1.8引進(jìn)了新的時(shí)間api-LocalDateTime,本文就來(lái)講講它的具體使用吧2023-05-05Java實(shí)戰(zhàn)練習(xí)之撲克牌魔術(shù)
這篇文章主要介紹了Java實(shí)戰(zhàn)練習(xí)之撲克牌魔術(shù),文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)java的小伙伴們有很好地幫助,需要的朋友可以參考下2021-04-04Spring Security使用數(shù)據(jù)庫(kù)認(rèn)證及用戶密碼加密和解密功能
這篇文章主要介紹了Spring Security使用數(shù)據(jù)庫(kù)認(rèn)證及用戶密碼加密和解密,本文通過(guò)代碼與截圖的形式給大家介紹的非常詳細(xì),對(duì)大家的工作或?qū)W習(xí)具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03spring boot activiti工作流的搭建與簡(jiǎn)單使用
這篇文章主要給大家介紹了關(guān)于spring boot activiti工作流的搭建與簡(jiǎn)單使用的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-08-08springboot post接口接受json時(shí),轉(zhuǎn)換為對(duì)象時(shí),屬性都為null的解決
這篇文章主要介紹了springboot post接口接受json時(shí),轉(zhuǎn)換為對(duì)象時(shí),屬性都為null的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-10-10MyBatis @Param注解的實(shí)現(xiàn)
本文主要介紹了MyBatis @Param注解的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04