跨域调用简介、Actuator插件使用、SpringBoot Admin使用、SpringCloud简介(Eureka实现)

跨域调用处理

什么是跨域

客户端发起异步请求一个服务器,该服务器再异步请求另一服务器

解决

  1. 使用jsonp(使用访问回调函数,可以随机生成回调函数名,保证不被劫持,只能通过get请求方式传参)
  2. 使用cors协议(不能处理劫持-在跨域异步调用时劫持请求,包装再转发-可以使用VPN专线连接保证不被劫持)
    cross-origin resource sharing(跨域资源共享)

前后端分离

前端项目与后端项目都可单独运行

使用cors协议

  1. 使用@Configuration注解(全局)
  2. 使用@CrossOrigin注解(局部,可用于类或方法)
    @CrossOrigin(origins={“http://localhost/”})建议使用域名而非localhost,因为localhost可以被解析为:127.0.0.1 /IP /主机名 /000:00:000:1 /localhost

监控

Actuator插件

用来监控应用的状态

  1. 引入依赖
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <parent>
            <artifactId>spring-boot-parent</artifactId>
            <groupId>org.springframework.boot</groupId>
            <version>2.1.10.RELEASE</version>
        </parent>
    
        <groupId>cn.khue</groupId>
        <artifactId>springboot-actuator-test</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <dependencies>
            <!--web依赖-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <!--actuator依赖-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
        </dependencies>
    </project>
    
  2. 创建启动类
    @SpringBootApplication
    public class SpringBootApp {
         
        public static void main(String[] args) {
         
            SpringApplication.run(SpringBootApp.class,args);
        }
    }
    
  3. 启动,通过http://localhost:8080/actuator路径查看详情
    在这里插入图片描述
    在这里插入图片描述

Spring Boot Admin

图形化管理Spring Boot

Spring Boot Admin Server

  1. 引入依赖
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值