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ō)明:跨域訪(fǎng)問(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在線(xiàn)流程設(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 //加配置注解可以?huà)呙璧?
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)文章
Java中的阻塞隊(duì)列BlockingQueue使用詳解
這篇文章主要介紹了Java中的阻塞隊(duì)列BlockingQueue使用詳解,阻塞隊(duì)列是一種線(xiàn)程安全的數(shù)據(jù)結(jié)構(gòu),用于在多線(xiàn)程環(huán)境下進(jìn)行數(shù)據(jù)交換,它提供了一種阻塞的機(jī)制,當(dāng)隊(duì)列為空時(shí),消費(fèi)者線(xiàn)程將被阻塞,直到隊(duì)列中有數(shù)據(jù)可供消費(fèi),需要的朋友可以參考下2023-10-10
Spring Boot環(huán)境屬性占位符解析及類(lèi)型轉(zhuǎn)換詳解
這篇文章主要給大家介紹了關(guān)于Spring Boot環(huán)境屬性占位符解析及類(lèi)型轉(zhuǎn)換的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-08-08
詳解IDEA 中使用Maven創(chuàng)建項(xiàng)目常見(jiàn)錯(cuò)誤和使用技巧(推薦)
這篇文章主要介紹了詳解IDEA 中使用Maven創(chuàng)建項(xiàng)目常見(jiàn)錯(cuò)誤和使用技巧(推薦),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07
Java 輕松實(shí)現(xiàn)二維數(shù)組與稀疏數(shù)組互轉(zhuǎn)
在某些應(yīng)用場(chǎng)景中需要大量的二維數(shù)組來(lái)進(jìn)行數(shù)據(jù)存儲(chǔ),但是二維數(shù)組中卻有著大量的無(wú)用的位置占據(jù)著內(nèi)存空間,稀疏數(shù)組就是為了優(yōu)化二維數(shù)組,節(jié)省內(nèi)存空間2022-04-04
java加密MD5實(shí)現(xiàn)及密碼驗(yàn)證代碼實(shí)例
這篇文章主要介紹了java加密MD5實(shí)現(xiàn)及密碼驗(yàn)證代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-12-12
Java中關(guān)于Collections集合工具類(lèi)的詳細(xì)介紹
Java提供了一個(gè)操作Set、List和Map等集合的工具類(lèi):Collections,該工具提供了大量方法對(duì)集合元素進(jìn)行排序、查詢(xún)和修改等操作,還提供了將集合對(duì)象設(shè)置為不可變、對(duì)集合對(duì)象實(shí)現(xiàn)同步控制等方法2021-09-09
Spring中使用JSR303請(qǐng)求約束判空的實(shí)現(xiàn)
這篇文章主要介紹了Spring中使用JSR303請(qǐng)求約束判空的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12

