简体   繁体   English

如何在spring-boot中启用跨域微服务

[英]How to enable cross-origin in spring -boot for micro-services

I have nearly 5 spring boot applications which are connected to discovery service to communicate with each other. 我有将近5个Spring Boot应用程序,这些应用程序连接到发现服务以相互通信。 and also I want to expose some controllers to the public, so how can I enable cross-origin? 而且我想向公众公开一些控制器,那么如何启用跨域? should I do it in all controller level or from discovery? 我应该在所有控制器级别还是从发现中执行? Any other suggestion Please! 还有其他建议吗!

Use the @CrossOrigin annotation either on your controller classes or on each of your controller methods that you want to permit. 在控制器类或要允许的每个控制器方法上使用@CrossOrigin批注。

You can also create a WebMvcConfigurer Bean in one of your configuration classes where you can establish cross origin configuration at a global level. 您还可以在其中一个配置类中创建WebMvcConfigurer Bean,在其中可以在全局级别上建立跨源配置。

Edit: I like @peekay suggestion as well. 编辑:我也喜欢@peekay建议。

I have used Kong Api Gateway in front of all services. 我在所有服务之前都使用了Kong Api Gateway。 To enable cross origin.its very easy to do it in single place rather than in every single controller 为了实现交叉原点,非常容易在单个位置而不是每个单个控制器中进行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM