In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to solve cross-domain problems through yue-library in SpringBoot. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.
Cross-domain description
Under the separation of front and rear, cross-domain has become a clich é topic, but many small partners still often face this problem, and the solutions are varied. Here is a simple and direct back-end solution.
Solve cross-domain (server) / * * CorsConfig- cross-domain * * @ author ylyue * @ since November 26th, 2018 * / @ Slf4j@Configurationpublic class CorsFilterConfig {/ / CorsConfig- cross-domain @ Bean @ ConditionalOnMissingBean public CorsFilter corsFilter () {final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource (); final CorsConfiguration config = new CorsConfiguration () Config.setAllowCredentials (true); config.setAllowedHeaders (Arrays.asList ("*")); config.setAllowedMethods (Arrays.asList ("*")); config.setAllowedOrigins (Arrays.asList ("*")); config.setMaxAge (3600L) / / set the Headers// config.setExposedHeaders (exposedHeaders) allowed by response to expose; / / config.addExposedHeader ("token"); source.registerCorsConfiguration ("/ *", config) Log.info ("[initialize configuration-Cross-Domain] allows cross-domain access by default. Initialized. ") ; return new CorsFilter (source);}} Cross-domain solution based on yue-library
The above code is extracted from yue-library, so yue-library-based projects have solved cross-domain problems by default. Yue-library is an enhanced library of SpringBoot. Cross-domain can be solved by introducing project dependency.
Maven project, add the following code to the pom.xml file, and replace ${version} with the corresponding version number:
Ai.ylyue yue-library-dependencies ${version}
Then introduce the required modules, such as the basic library: yue-library-base
Ai.ylyue yue-library-base...
Click to quickly learn about yue-library
Conclusion
Cross-domain problems are recommended to be solved by the server. There is no need to enable cross-domain security access restrictions. It can only prevent JS script injection in some browsers, but cannot achieve real security access restrictions. If you have any questions, please leave a message below.
After reading the above, do you have any further understanding of how to solve cross-domain problems through yue-library in SpringBoot? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 225
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.