springboot_模拟01

news2024/10/6 6:44:32

demo 模拟springboot

  pom.xml

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <dependencies>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.3.18</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.3.18</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>5.3.18</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.3.18</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-core</artifactId>
            <version>9.0.6</version>
        </dependency>
    </dependencies>

</project>

userdemo 依赖 demo

pom.xml

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>userdemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>userdemo</name>

    <dependencies>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>demo</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

    </dependencies>

</project>

demo  自定义注解 MySpringBootApplication

package org.springframework.boot.autoconfigure;

import java.lang.annotation.*;

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface MySpringBootApplication {
}

userdemo 使用 demo  自定义注解 MySpringBootApplication

package com.example.userdemo;


import org.springframework.boot.autoconfigure.MySpringBootApplication;

@MySpringBootApplication
public class UserdemoApplication {

    public static void main(String[] args) {
        
    }

}

demo  run 方法

package org.springframework.boot;

public class MySpringApplication {

    public static void run(Class clazz){

    }
}

userdemo 使用

package com.example.userdemo;


import org.springframework.boot.MySpringApplication;
import org.springframework.boot.autoconfigure.MySpringBootApplication;

@MySpringBootApplication
public class UserdemoApplication {

    public static void main(String[] args) {
        MySpringApplication.run(UserdemoApplication.class);
    }

}

 demo  启动 tomcat

package org.springframework.boot;

import org.apache.catalina.*;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.core.StandardEngine;
import org.apache.catalina.core.StandardHost;
import org.apache.catalina.startup.Tomcat;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

public class MySpringApplication {

    public static void run(Class clazz) {

        /*
        创建spring容器
         */
        AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
        /*
        解析配置类,创建 bean 交由spring容器管理
         */
        applicationContext.register(clazz);

        /*
        刷新整个Spring 上下文信息,确保使用最新的 bean
         */
        applicationContext.refresh();
        //启动 tomcat
        startTomcat(applicationContext);
    }

    //启动 tomcat
    public static void startTomcat(WebApplicationContext applicationContext){

        Tomcat tomcat = new Tomcat();

        Server server = tomcat.getServer();
        Service service = server.findService("Tomcat");

        Connector connector = new Connector();
        connector.setPort(8081);

        Engine engine = new StandardEngine();
        engine.setDefaultHost("localhost");

        Host host = new StandardHost();
        host.setName("localhost");

        String contextPath = "";
        Context context = new StandardContext();
        context.setPath(contextPath);
        context.addLifecycleListener(new Tomcat.FixContextListener());

        host.addChild(context);
        engine.addChild(host);

        service.setContainer(engine);
        service.addConnector(connector);

        /*
        new DispatcherServlet(applicationContext)
        需要spring容器中的controller bean,根据不同的请求调用不同的controller bean
        */
        tomcat.addServlet(contextPath, "dispatcher", new DispatcherServlet(applicationContext));
        /*
        所有的请求都调用 DispatcherServlet ,再由dispatcherServlet 根据不同的请求调用不同的controller bean
        * */
        context.addServletMappingDecoded("/*", "dispatcher");

        try {
            tomcat.start();
            // 进入监听状态,如果不进入监听状态,启动tomat后就会关闭tomcat
            tomcat.getServer().await();

        } catch (LifecycleException e) {
            e.printStackTrace();
        }

    }
}

@MySpringBootApplication 之上添加 @ComponentScan

 @ComponentScan 未指定basePackages 将默认扫描与包含该注解的类相同的包及其子孙包中的所有组件。

package org.springframework.boot.autoconfigure;

import org.springframework.context.annotation.ComponentScan;

import java.lang.annotation.*;

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@ComponentScan
public @interface MySpringBootApplication {
}

userdemo 使用

package com.example.userdemo;


import org.springframework.boot.MySpringApplication;
import org.springframework.boot.autoconfigure.MySpringBootApplication;

@MySpringBootApplication
public class UserdemoApplication {

    public static void main(String[] args) {
        MySpringApplication.run(UserdemoApplication.class);
    }

}
package com.example.userdemo.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {
    
    @RequestMapping("/test01")
    public String test01(){
        return "test tomcat server";
    }
}


动态选择启动 tomcat 还是jetty服务器

demo 定义 WebServer 接口

package org.springframework.boot;

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;

public interface WebServer {
    //启动 服务器
    public void start(AnnotationConfigWebApplicationContext applicationContext);
}

实现类 TomcatWebServer

启动 tomcat

package org.springframework.boot;

import org.apache.catalina.*;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.core.StandardEngine;
import org.apache.catalina.core.StandardHost;
import org.apache.catalina.startup.Tomcat;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

public class TomcatWebServer implements WebServer {
    //启动 tomcat
    @Override
    public void start(AnnotationConfigWebApplicationContext applicationContext) {

        startTomcat(applicationContext);
    }

    //启动 tomcat
    public static void startTomcat(WebApplicationContext applicationContext){

        Tomcat tomcat = new Tomcat();

        Server server = tomcat.getServer();
        Service service = server.findService("Tomcat");

        Connector connector = new Connector();
        connector.setPort(8081);

        Engine engine = new StandardEngine();
        engine.setDefaultHost("localhost");

        Host host = new StandardHost();
        host.setName("localhost");

        String contextPath = "";
        Context context = new StandardContext();
        context.setPath(contextPath);
        context.addLifecycleListener(new Tomcat.FixContextListener());

        host.addChild(context);
        engine.addChild(host);

        service.setContainer(engine);
        service.addConnector(connector);

        /*
        new DispatcherServlet(applicationContext)
        需要spring容器中的controller bean,根据不同的请求调用不同的controller bean
        */
        tomcat.addServlet(contextPath, "dispatcher", new DispatcherServlet(applicationContext));
        /*
        所有的请求都调用 DispatcherServlet ,再由dispatcherServlet 根据不同的请求调用不同的controller bean
        * */
        context.addServletMappingDecoded("/*", "dispatcher");

        try {
            tomcat.start();
            // 进入监听状态,如果不进入监听状态,启动tomat后就会关闭tomcat
            tomcat.getServer().await();

        } catch (LifecycleException e) {
            e.printStackTrace();
        }

    }



}

实现类 JettyWebServer

启动 Jetty 服务器

依赖

<dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
            <version>9.4.48.v20220622</version>
</dependency>
package org.springframework.boot;

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;

public class JettyWebServer implements WebServer{
    @Override
    public void start(AnnotationConfigWebApplicationContext applicationContext) {
        System.out.println("启动jetty 服务器");
    }
}

demo  MySpringApplication

package org.springframework.boot;

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;

import java.util.Map;


public class MySpringApplication {

    public static void run(Class clazz) {

        /*
        创建spring容器
         */
        AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
        /*
        解析配置类,创建 bean 交由spring容器管理
         */
        applicationContext.register(clazz);

        /*
        刷新整个Spring 上下文信息,确保使用最新的 bean
         */
        applicationContext.refresh();

        //获取某个实现类的对象,调用其 start 方法,启动对应服务器
        WebServer webServer = getWebServer(applicationContext);
        webServer.start(applicationContext);

    }

    private static WebServer getWebServer(AnnotationConfigWebApplicationContext applicationContext){
        //从 spring 容器获取 WebServer 类型的 bean
        Map<String,WebServer> beansOfType = applicationContext.getBeansOfType(WebServer.class);
        //有且仅有一个 bean 对象,返回该对象 否则抛异常
        if(beansOfType.size() == 0){
            throw new NullPointerException();
        }else if( beansOfType.size() > 1){
            throw new IllegalStateException();
        }else {
            /*
            * .values获取map 中的所有 value 组成集合
            * .stream() 将集合转换为一个流并进行各种操作
            * stream().findFirst() 是一个方法链,stream()将集合转换为流(Stream),而findFirst()返回流的第一个元素
            * get() 方法返回该Bean实例
            * */
            return beansOfType.values().stream().findFirst().get();
        }



    }

}

userdemo 使用

配置类中

@Bean
public JettyWebServer jettyWebServer(){
    return new JettyWebServer();
}

使spring容器中有JettyWebServer 的bean

 getWebServer 获取的就是JettyWebServer bean

 调用其 start ,启动的就是 jetty 服务器

如果创建 tomcatWebServer 对象给spring对象,那么就回启动tomcat 服务器

package com.example.userdemo;


import org.springframework.boot.JettyWebServer;
import org.springframework.boot.MySpringApplication;
import org.springframework.boot.autoconfigure.MySpringBootApplication;
import org.springframework.context.annotation.Bean;

@MySpringBootApplication
public class UserdemoApplication {

   @Bean
   public JettyWebServer jettyWebServer(){
       return new JettyWebServer();
   }

    public static void main(String[] args) {
        MySpringApplication.run(UserdemoApplication.class);
    }

}


demo 自动配置 WebServer

package org.springframework.boot.autoconfigure;

import org.springframework.boot.JettyWebServer;
import org.springframework.boot.TomcatWebServer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//配置类
@Configuration
public class WebServerAutoConfiguration {
    
    @Bean
    public TomcatWebServer tomcatWebServer(){
        return new TomcatWebServer();
    }

    
    @Bean
    public JettyWebServer jettyWebServer(){
        return new JettyWebServer();
    }
}

但是不能2个bean都有,只能有一个

加 @Conditional() 条件注解 当条件成立被注解的内容才生效

@Conditional() 注解 有一个属性value,该属性类型是Class数组

Class 泛型要求必须继承 Condition

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.springframework.context.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Conditional {
    Class<? extends Condition>[] value();
}

Condition接口有一个 matches 方法,实现该方法,扫描注解@Conditional时会调用该方法,返回true则条件成立

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.springframework.context.annotation;

import org.springframework.core.type.AnnotatedTypeMetadata;

@FunctionalInterface
public interface Condition {
    boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata);
}
 

TomcatCondition implements Condition

当有tomcat依赖时,条件成立

package org.springframework.boot.autoconfigure;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class TomcatCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        //条件
        try {
            //有 org.apache.catalina.startup.Tomcat 这个类,返会true,条件成立
            context.getClassLoader().loadClass("org.apache.catalina.startup.Tomcat");
            return true;
        }catch (ClassNotFoundException e){
            return false;
        }

    }
}

JettyCondition implements Condition

当有jetty依赖时,条件成立

package org.springframework.boot.autoconfigure;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class JettyCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        //条件
        try {
            //有 org.eclipse.jetty.server 这个类,返会true,条件成立
            context.getClassLoader().loadClass("org.eclipse.jetty.server.Server");
            return true;
        }catch (ClassNotFoundException e){
            return false;
        }

    }
}

package org.springframework.boot.autoconfigure;

import org.springframework.boot.JettyWebServer;
import org.springframework.boot.TomcatWebServer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

//配置类
@Configuration
public class WebServerAutoConfiguration {

    @Conditional(TomcatCondition.class)
    @Bean
    public TomcatWebServer tomcatWebServer(){
        return new TomcatWebServer();
    }

    @Conditional(JettyCondition.class)
    @Bean
    public JettyWebServer jettyWebServer(){
        return new JettyWebServer();
    }
}

demo 中 既有 启动tomcat的代码,需要tomcat依赖,

又有启动jetty的代码,需要jetty依赖,

但在userdemo 中如果两个依赖都有,那么2个@Conditional 都条件成立,

两个@Bean 都生效,会在spring容器中创建2个bean(只有一个才能启动服务器,不然抛异常)

userdemo

package com.example.userdemo;


import org.springframework.boot.JettyWebServer;
import org.springframework.boot.MySpringApplication;
import org.springframework.boot.autoconfigure.MySpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

//导入配置类WebServerAutoConfiguration,使之被解析,创建 bean 对象交由spring容器管理
@Import(org.springframework.boot.autoconfigure.WebServerAutoConfiguration.class)
@MySpringBootApplication
public class UserdemoApplication {

    public static void main(String[] args) {
        MySpringApplication.run(UserdemoApplication.class);
    }

}

因为2个bean,都有,所以抛异常 

demo 依赖jetty ,userdemo依赖demo,由于依赖传递,userdemo也就依赖了jetty

阻止依赖传递 <optional>true</optional>

demo pom.xml

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <dependencies>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.3.18</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.3.18</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>5.3.18</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.3.18</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-core</artifactId>
            <version>9.0.6</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
            <version>9.4.48.v20220622</version>
            <optional>true</optional>
        </dependency>

    </dependencies>

</project>

如此 userdemo 就没有依赖 jetty,只依赖了tomcat

 成功启动tomcat

如果想要改为使用jetty,就在userdemo pom.xml 中引入jetty的依赖并且排除 tomcat的依赖


模拟@ConditioalOnClass

当value属性指定的类存在,则条件成立

package org.springframework.boot.autoconfigure;

import org.springframework.context.annotation.Conditional;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.TYPE,ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Conditional(WebServerCondition.class)
public @interface MyConditionalOnClass {
    String value();
}

WebServerCondition

package org.springframework.boot.autoconfigure;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

public class WebServerCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {

        //从metadata 中获取 MyConditionalOnClass 注解的属性
        Map<String,Object>  annotationAttributes = metadata.getAnnotationAttributes(MyConditionalOnClass.class.getName());
        //获取value属性的值
        String value = (String) annotationAttributes.get("value");
        try{
            //加载 value 属性指定的类,成功加载则条件成立
            context.getClassLoader().loadClass(value);
            return true;
        }catch(ClassNotFoundException e){
            return false;
        }



    }
}
package org.springframework.boot.autoconfigure;

import org.springframework.boot.JettyWebServer;
import org.springframework.boot.TomcatWebServer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

//配置类
@Configuration
public class WebServerAutoConfiguration {


    @MyConditionalOnClass("org.apache.catalina.startup.Tomcat")
    @Bean
    public TomcatWebServer tomcatWebServer(){
        return new TomcatWebServer();
    }

    @MyConditionalOnClass("org.eclipse.jetty.server.Server")
    @Bean
    public JettyWebServer jettyWebServer(){
        return new JettyWebServer();
    }
}

userdemo 使用

package com.example.userdemo;


import org.springframework.boot.JettyWebServer;
import org.springframework.boot.MySpringApplication;
import org.springframework.boot.autoconfigure.MySpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

//导入配置类WebServerAutoConfiguration,使之被解析,创建 bean 对象交由spring容器管理
@Import(org.springframework.boot.autoconfigure.WebServerAutoConfiguration.class)
@MySpringBootApplication
public class UserdemoApplication {

    public static void main(String[] args) {
        MySpringApplication.run(UserdemoApplication.class);
    }

}

成功启动 tomcat 

 

添加@Import(MyAutoConfigurationImportSelector.class) 

AutoConfigurationImportSelector implements DeferredImportSelector

package org.springframework.boot.autoconfigure;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;

import java.lang.annotation.*;

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@ComponentScan
@Import(MyAutoConfigurationImportSelector.class)
public @interface MySpringBootApplication {
}

 

org/springframework/boot/spring-boot/2.7.9/spring-boot-2.7.9.jar!/META-INF/spring.factories

springboot jar包中 spring.factories 记录了配置类的类名

读取各个jar包中的spring.factories 文件,获取配置类的类名

package org.springframework.boot.autoconfigure;

import org.springframework.context.annotation.DeferredImportSelector;
import org.springframework.core.type.AnnotationMetadata;

public class MyAutoConfigurationImportSelector implements DeferredImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
        /*读取各个jar包中的spring.factories 文件,获取配置类的类名
        返回需要解析的配置类的类名*/
        return new String[0];
    }
}
 
package org.springframework.boot.autoconfigure;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;

import java.lang.annotation.*;

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@ComponentScan
@Import(MyAutoConfigurationImportSelector.class)
public @interface MySpringBootApplication {
}

不再需要在 启动类上使用@Import 导入配置类(因为需要导入的配置类很多,也不清楚到底有那些)@MySpringBootApplication 中的 

@Import(MyAutoConfigurationImportSelector.class)

实现导入所有的配置类

package com.example.userdemo;


import org.springframework.boot.JettyWebServer;
import org.springframework.boot.MySpringApplication;
import org.springframework.boot.autoconfigure.MySpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

//导入配置类WebServerAutoConfiguration,使之被解析,创建 bean 对象交由spring容器管理
//@Import(org.springframework.boot.autoconfigure.WebServerAutoConfiguration.class)
@MySpringBootApplication
public class UserdemoApplication {

    public static void main(String[] args) {
        MySpringApplication.run(UserdemoApplication.class);
    }

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/445291.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

李沐读论文笔记--大模型时代下做科研的四个思路

大模型时代下做科研的四个思路 0. 视频来源&#xff1a;1. 提高效率&#xff08;更快更小&#xff09;1.1 PEFT介绍(parameter efficient fine tuning)1.2 作者的方法1.3 AIM效果1.3.1AIM 在 K400 数据集上的表现1.3.2AIM 在 Something-Something 数据集、K700 数据集和 Diving…

《程序员面试金典(第6版)》面试题 16.01. 交换数字(位运算符,异或性质)

题目描述 编写一个函数&#xff0c;不用临时变量&#xff0c;直接交换numbers [a, b]中a与b的值。 示例&#xff1a; 输入: numbers [1,2]输出: [2,1] 提示&#xff1a; numbers.length 2-2147483647 < numbers[i] < 2147483647 解题思路与代码 这道题不让使用额外…

spring getway的配置

1. 创建工程 getway-server 2. 添加 pom 依赖&#xff1a; <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId> </dependency> 3. 添加启动类 4. 添加配置文件&#xff…

【安全防御】IPsec VPN

1.什么是数据认证&#xff0c;有什么用&#xff0c;有哪些实现的技术手段&#xff1f; 在计算机和网络安全领域中&#xff0c;数据认证是指验证数据在传输和存储过程中的完整性、真实性和合法性的过程。数据在传输和存储过程中容易受到数据篡改、损坏或未经授权的访问和修改的…

用Keras单层网络预测银行客户流失率

用Keras单层网络预测银行客户流失率 描述 已知一批客户数据&#xff0c;来预测某个银行的客户是否流失。通过学习历史数据&#xff0c;如果机器能判断出哪些客户很有可能在未来两年内结束在银行的业务&#xff08;这当然是银行所不希望看到的&#xff09;&#xff0c;那么银行…

基于vue+laravel技术框架开发的:PHP不良事件上报系统源码

医院安全&#xff08;不良&#xff09;事件上报系统源码&#xff0c;PHP不良事件上报系统源码 系统定义&#xff1a; 规范医院安全&#xff08;不良&#xff09;事件的主动报告&#xff0c;增强风险防范意识&#xff0c;及时发现医院不良事件和安全隐患&#xff0c;将获取的医…

成都建博会:家居行业数字营销金点子 句句戳心坎,先收藏

四月&#xff0c;不仅是人间最美天&#xff0c;也是第二季度的开始。随着气温上升&#xff0c;行业进入了活跃期。对于西南地区的家居行业从业者来说&#xff0c;来一趟一年一度的成都建博会&#xff0c;总能获得无尽的灵感&#xff0c;对后续更加充满期待。而与同行的交流&…

美国主机常见的安全漏洞与防范方法详解

在今天的数字时代&#xff0c;保护计算机系统和数据安全至关重要。不幸的是&#xff0c;网络安全问题在过去几年中已经成为全球性的问题。攻击者利用各种漏洞和技巧来入侵系统&#xff0c;以窃取敏感信息、加密数据或者破坏系统。在本文中&#xff0c;我们将探讨美国主机常见的…

HTML5 语义元素

文章目录 HTML5 语义元素什么是语义元素?浏览器支持HTML5中新的语义元素HTML5 \<section> 元素HTML5 \<article> 元素HTML5 \<nav> 元素HTML5 \<aside> 元素HTML5 \<header> 元素HTML5 \<footer> 元素HTML5 \<figure> 和 \<figc…

Git Commit message 编写规范

介绍 在 Git 中&#xff0c;每次提交代码&#xff0c;都要写 Commit message&#xff08;提交说明&#xff09;&#xff0c;否则就不允许提交。这个操作将通过 git commit 完成。 git commit -m "hello world"上面代码的-m参数&#xff0c;就是用来指定 commit mes…

你怎么知道我什么都不会

文章目录 查询的存储过程增删改的存储过程返回拼音缩写自动填充拼音缩写的触发器销售完整销售业务存储过程 实现查询销售记录及销售明细退货业务实现营业员对当天销售的扎帐处理存储过程 阿巴阿巴高可用 阿玛阿玛碰运气 文心一言 耶耶耶耶耶 查询的存储过程 创建货品信息查…

kafka--python

文章目录 1、kafka是什么2、docker上部署kafka3、在kafka容器内部署python&#xff0c;并跑通生产者-消费者简单代码4、最新接口4.1、kafka_config.py4.2、kafka_interface.py4.3、run.py4、测试 1、kafka是什么 Producer&#xff1a;即生产者&#xff0c;消息的产生者&#xf…

PICO一方打造:VR音游《闪韵灵境》体验

​《闪韵灵境》本周正式上线&#xff0c;作为PICO一方工作室的首款作品&#xff0c;不少玩家对此寄予厚望。即便是作为一个轻轻度VR音游的用户&#xff0c;经过简短体验&#xff0c;我也发现了闪韵灵境和目前热门的Beat Saber之间的一些差异点。以下是我在简短体验后的一些看法…

Java选择排序、二分查找

一、选择排序 1.选择排序的思想 每轮选择当前的位置&#xff0c;开始找后面的较小值与该位置进行交换。 第一轮&#xff1a;选择当前位置&#xff0c;开始找后面的较小值与该位置进行交换。 5与1交换后&#xff0c;1就在当前位置&#xff0c;因此&#xff0c;1与后面的所有值…

看板与 Scrum:有什么区别?

看板和Scrum是项目管理方法论&#xff0c;以小增量完成项目任务并强调持续改进。但是他们用来实现这些目标的过程是不同的。看板以可视化任务和连续流程为中心&#xff0c;而Scrum更多是关于为每个交付周期实施时间表和分配设定角色。 在看板和Scrum之间做出选择并不总是必要…

【事故】记一次意外把公司项目放到GitHub并被fork,如何使用DMCA下架政策保障隐私

前言 &#x1f34a;缘由 在一个月黑风高的夜晚&#xff0c;正准备休息的我突然接到之前外包老总的亲切问候。一顿输出才知道三年前为了搭建流程化部署&#xff0c;将公司的测试代码放到github上后忘记删除。现在被甲方的代码扫描机制扫到&#xff0c;并且检查到代码已经被其他…

大数据环境生态搭建

文章目录 大数据环境生态搭建一、通用操作1、更改三台节点的主机名2、关闭三台机器 linux 的安全模式3、关闭三台机器的防火墙4、设置三台机器的免密的登录 二、安装 JDK1.8 大数据环境生态搭建 一、通用操作 1、更改三台节点的主机名 输入命令&#xff1a; hostnamectl set…

打通Web2与Web3 欧科云链用数据建桥

在刚刚过去的香港Web3嘉年华系列活动中&#xff0c;欧科云链以链上数据服务商的特别身份带来了新的行业视角&#xff0c;该集团旗下研究院高级研究员蒋照生观察&#xff0c;Web3涵盖的“数据革命”不仅局限于区块链领域&#xff0c;Web2行业同样有需求。 借助区块链数据的透明…

共话开源 - openKylin出席 FOSSASIA Summit 2023 开源盛会!

4月14日&#xff0c;openKylin社区受邀参加FOSSASIA Summit 2023开源盛会&#xff0c;给来自全球的技术开发者带来openKylin社区在RISC-V软硬件生态建设方面的经验与成果介绍&#xff0c;向大家展示中国开源社区的潜力&#xff0c;并同国际技术社区共研RISC-V未来之势。 FOSSA…

Oracle函数记录

一、各个函数介绍 1.OVER(PARTITION BY… ORDER BY…)--开窗函数 1.开窗函数用于为行定义一个窗口&#xff08;这里的窗口是指运算将要操作的行的集合&#xff09;&#xff0c;它对一组 值进行操作&#xff0c;不需要使用GROUP BY子句对数据进行分组&#xff0c;能够在同一…