【Spring Boot】详解条件注解以及条件拓展注解@Conditional与@ConditionalOnXxx

news2024/9/26 5:13:01

Spring

@Conditional

        Spring 4.0+提供的注解。作用是给需要装载的Bean增加一个条件判断。只有满足条件才会装在到IoC容器中。而这个条件可以由自己去完成的,可以通过重写Condition接口重写matches()方法去实现自定义的逻辑。所以说这个注解增加了对Bean装载的灵活性。

源码

        可以看出来首先可以修饰在类、接口、枚举以及方法上。并且可以接收一个或多个实现Condition接口的类。

        那么在Condition接口中只有一个返回布尔类型的matches()方法。从这个单词也看得出来这是匹配的意思,所以就是匹配校验Bean是否可以被加载进IoC容器中。Determine if the condition matches(确定条件是否匹配)。

实战代码

        以下先建两个Bean类、一个条件类、一个配置类、以及测试Main类。需要注意的是条件类中的参数并不是Spring的上下文ApplicationContext,所以其内容需要设置在-vm options中。至于这个-vm [options]中的options可以通过DOS窗口输入Java就可以看到有什么选项了。

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Animal {
	private String name;
	private String sex;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Person {
	private String name;
	private Integer age;
}
public class PersonCondition implements Condition {

	/**
	 * @param context 上下文
	 * @param metadata 注解元信息
	 */
	@Override
	public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
		// 通过条件上下文获取环境中的配置文件信息
		String property = context.getEnvironment().getProperty("spring.createBean");
		if(null == property) {
			return false;
		}
		return property.contains("person");
	}
}
public class AnimalCondition implements Condition {

    /**
     * @param context 上下文
     * @param metadata 注解元信息
     */
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        // 通过条件上下文获取环境中的配置文件信息
        String property = context.getEnvironment().getProperty("spring.createBean");
        if(null == property) {
            return false;
        }
        return property.contains("animal");
    }
}

public class ConditionalTest {
    public static void main(String[] args) {
        // 通过Spring上下文ApplicationContext传入配置类获取其中的Bean描述并输出
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ConditionalConfig.class);
        Arrays.stream(applicationContext.getBeanDefinitionNames()).forEach(System.out::println);
    }
}

测试结果

SpringBoot

        关于@ConditionalOnXxx注解是在SpringBoot中拓展出来的,是原先Spring框架中没有存在的注解。那么以下就逐一去了解每个注解的作用。需要说的是这些注解全部都可以注解在类、接口、枚举和方法上

        从上图可以发现有十三种是@ConditionalOnXxx。其中就不了解@ConditionalOnCloudPlatform与@ConditionOnJndi这两个注解了。

       上面的扩展注解我们可以简单的分为以下几类:

  • Bean作为条件:@ConditionalOnBean、@ConditionalOnMissingBean、@ConditionalOnSingleCandidate。
  • 类作为条件:@ConditionalOnClass、@ConditionalOnMissingClass。
  • SpEL表达式作为条件:@ConditionalOnExpression。
  • Java版本作为条件: @ConditionalOnJava
  • 配置属性作为条件:@ConditionalOnProperty。
  • 资源文件作为条件:@ConditionalOnResource。
  • 是否Web应用作为判断条件:@ConditionalOnWebApplication、@ConditionalOnNotWebApplication。

条件为Bean的情况

@ConditionalOnBean

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional({OnBeanCondition.class})
public @interface ConditionalOnBean {

    /**
     * 需要作为条件的类的Class对象数组
     */
    Class<?>[] value() default {};

    /**
     * 需要作为条件的类的Name, Class.getName()
     */
    String[] type() default {};

    /**
     * (用于指定注解修饰的Bean)条件所需的注解类
     */
    Class<? extends Annotation>[] annotation() default {};

    /**
     * Spring容器中Bean的名字
     */
    String[] name() default {};

    /**
     * 搜索容器层级,当前容器,父容器
     */
    SearchStrategy search() default SearchStrategy.ALL;

    /**
     * 可能在其泛型参数中包含指定Bean类型的其他类
     */
    Class<?>[] parameterizedContainer() default {};
}

        源码中的属性就不一一展示测试了,这里就测试value于name即可,value传入的是Class类型。而这个注解的含义很简单:如果IoC容器中存在该注解中value属性对应的Bean,那么就加载被该注解注解的Bean。否则不加载。测试代码采用上面Spring目录下的测试结果中的代码。这里主要展示配置类中的逻辑。

@Configuration
public class ConditionalConfig {

	@Bean
	public Person person() {
		return new Person();
	}

	@Bean
	@ConditionalOnBean(Person.class)
    //@ConditionalOnBean(name = "com.gok.entity.Person")
	public Animal animal() {
		return new Animal();
	}
}

        这里需要注意的是,Spring加载Bean是在配置类中自上而下加载的,所以说如果person()与animal()两个方法换位置的话Animal是不会被加载到IoC容器中的,因为在它加载时Person还没被加载入IoC容器。

@ConditionalOnMissingBean

@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(OnBeanCondition.class)
public @interface ConditionalOnMissingBean {

    /**
     * 需要作为条件的类的Class对象数组
     */
    Class<?>[] value() default {};

    /**
     * 需要作为条件的类的Name, Class.getName()
     */
    String[] type() default {};

    /**
     * 匹配Bean的时候需要忽视的Class对象数组,一般是父类
     * @ConditionalOnMissingBean(value = JdbcFactory.class, ignored = MySqlDefaultFactory.class)
     */
    Class<?>[] ignored() default {};

    /**
     * 匹配Bean的时候需要忽视的类的Name, Class.getName()
     */
    String[] ignoredType() default {};

    /**
     * (用于指定注解修饰的Bean)条件所需的注解类
     */
    Class<? extends Annotation>[] annotation() default {};

    /**
     * Spring容器中Bean的名字
     */
    String[] name() default {};

    /**
     * 搜索容器层级,当前容器,父容器
     */
    SearchStrategy search() default SearchStrategy.ALL;

    /**
     * 可能在其泛型参数中包含指定Bean类型的其他类
     */
    Class<?>[] parameterizedContainer() default {};
}

        理解了上面注解的作用,那这个注解就游刃有余了,miss单词意为错过、没有的意思。所以这个注解的作用就是:如果IoC容器中不存在该注解中value属性对应的Bean,那么就加载被该注解注解的Bean。否则不加载

@Configuration
public class ConditionalConfig {

	@Bean
	public Person person() {
		return new Person();
	}

	@Bean
	@ConditionalOnMissingBean(Person.class)
    //@ConditionalOnMissingBean(name = "com.gok.entity.Person")
	public Animal animal() {
		return new Animal();
	}
}

@ConditionalOnSingleCandidate

@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(OnBeanCondition.class)
public @interface ConditionalOnSingleCandidate {

    /**
     * 需要作为条件的类的Class对象
     */
    Class<?> value() default Object.class;

    /**
     * 需要作为条件的类的Name, Class.getName()
     */
    String type() default "";

    /**
     * 搜索容器层级,当前容器,父容器
     */
    SearchStrategy search() default SearchStrategy.ALL;
}

        此注解从单词single与candidate可以得出是单个候选人的意思。大致可以猜测是存在相同类型的Bean的话只会对单个有效。我尝试将其放到person02()上,还是一样将这两个Bean加载到了IoC当中,但是放在第一个person01()上,导致person01没有被加载到IoC容器当中。所以此Bean的作用就是:如果当指定Bean在容器中只有一个,或者虽然有多个但是指定首选Bean的时候则生效。即同类型的Bean中,首选Bean无法被加载入IoC容器中。

@Configuration
public class ConditionalConfig {

	@Bean
	@ConditionalOnSingleCandidate
	public Person person01() {
		return new Person();
	}

	@Bean
	public Person person02() {
		return new Person();
	}
}

条件为类的情况

@ConditionalOnClass

@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(OnClassCondition.class)
public @interface ConditionalOnClass {

    /**
     * 需要作为条件的类的Class对象数组
     */
    Class<?>[] value() default {};

    /**
     * 需要作为条件的类的Name, Class.getName()
     */
    String[] name() default {};
}

        这个其实和@ConditionalOnBean类似,但是那个注解是在IoC容器中或者是类全限定名找是否存在该Spring Bean。而@ConditionalOnClas是在IoC容器中或者是类全限定名找到是否存在该类。如果存在就加载,不存在就不加载到IoC容器中。

@ConditionalMissingClass

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional({OnClassCondition.class})
public @interface ConditionalOnMissingClass {

    /**
     * 需要作为条件的类的Name, Class.getName()
     */
    String[] value() default {};
}

        与@ConditionalOnClass相反。会在这里一起展示代码以及测试的结果。Plant类是真实存在的,所以说person01被加载到IoC容器中,而person02没有被加载到IoC当中。

@Configuration
public class ConditionalConfig {

	@Bean
	@ConditionalOnClass(Animal.class)
	public Person person01() {
		return new Person();
	}

	@Bean
	@ConditionalOnMissingClass("com.gok.entity.Animal")
	public Person person02() {
		return new Person();
	}
}

条件为SpEL表达式的情况

@ConditionalOnExpression

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
@Documented
@Conditional(OnExpressionCondition.class)
public @interface ConditionalOnExpression {

    /**
     * 要作为条件的SpEL表达式
     */
    String value() default "true";
}

        这个注解就是用来判断该Bean是否符合SpEL表达式,至于什么是SpEL表达式就自行百度学习了,就不多放篇幅去详细说明了。这里我设置person01为true,而person02为false。

@Configuration
public class ConditionalConfig {

	@Bean
	@ConditionalOnExpression("true")
	public Person person01() {
		return new Person();
	}

	@Bean
	@ConditionalOnExpression("false")
	public Person person02() {
		return new Person();
	}
}

条件为Java的情况

@ConditionalOnJava

@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(OnJavaCondition.class)
public @interface ConditionalOnJava {

    /**
     * 比较方式,Range.EQUAL_OR_NEWER:当前版本等于或高于、Range.OLDER_THAN:当前版本老于,越早的版本越老
     */
    ConditionalOnJava.Range range() default ConditionalOnJava.Range.EQUAL_OR_NEWER;

    /**
     * 指定JAVA版本
     */
    JavaVersion value();

    /**
     * Range options.
     */
    public static enum Range {

        /**
         * Equal to, or newer than the specified {@link JavaVersion}.
         */
        EQUAL_OR_NEWER,

        /**
         * Older than the specified {@link JavaVersion}.
         */
        OLDER_THAN

        private Range() {}
    }
}

         此注解用来判断当前运行环境的Java版本是多少。符合范围内的条件才会加载Bean。

@Configuration
public class ConditionalConfig {

	@Bean
	@ConditionalOnJava(JavaVersion.EIGHT)
	public Person person01() {
		return new Person();
	}

	@Bean
	@ConditionalOnJava(JavaVersion.NINE)
	public Person person02() {
		return new Person();
	}
}

条件为配置条件的情况

@ConditionalOnProperty

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
@Documented
@Conditional(OnPropertyCondition.class)
public @interface ConditionalOnProperty {

    /**
     * 对应property名称的值
     */
    String[] value() default {};
    String[] name() default {};

    /**
     * property名称的前缀,可有可无
     */
    String prefix() default "";

    /**
     * 与name组合使用,比较获取到的属性值与havingValue给定的值是否相同,相同才加载配置
     */
    String havingValue() default "";

    /**
     * 缺少该property时是否可以加载。如果为true,没有该property也会正常加载;反之报错
     */
    boolean matchIfMissing() default false;
}

        此注解用于条件配置中读取peoperties文件中的信息。本人测试读取yml无效,需要在配置类上多添加个@PropertySource注解读取文件才能够使用配置条件注解。

# application.properties中的内容
com.gok.test=true
com.gok.password=123456
@Configuration
// 读取properties文件的方式 可以配合@Value注解读取详细信息
@PropertySource(value = "classpath:application.properties", encoding = "UTF-8")
//@PropertySources({@PropertySource(value = "classpath:application.properties", encoding = "UTF-8")})
public class ConditionalConfig {

	@Bean
	@ConditionalOnProperty("com.gok.test")
	public Person person01() {
		return new Person();
	}

	@Bean
	@ConditionalOnProperty(name = "com.gok.test")
	public Person person02() {
		return new Person();
	}

	@Bean
	@ConditionalOnProperty("com.gok.password")
	public Person person03() {
		return new Person();
	}

	@Bean
	@ConditionalOnProperty(name = "com.gok.password", havingValue = "123456")
	public Person person04() {
		return new Person();
	}

	@Bean
	@ConditionalOnProperty(name = "com.gok.password", havingValue = "123456789")
	public Person person05() {
		return new Person();
	}

	@Bean
	@ConditionalOnProperty(value = "com.gok.password=123456", matchIfMissing = true)
	public Person person06() {
		return new Person();
	}

	@Bean
	// 这里要注意如果要使用prefix前缀的话 必须带上name或者value
	// 或者会报错:The name or value attribute of @ConditionalOnProperty must be specified
	// 以下拼接即为:是否存在com.gok.password这个属性
	@ConditionalOnProperty(prefix = "com.gok", name = "password")
	public Person person07() {
		return new Person();
	}
}

条件为资源条件的情况

@ConditionalOnResource

@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(OnResourceCondition.class)
public @interface ConditionalOnResource {

    /**
     * 要作为判断条件的资源文件名称  @ConditionalOnResource(resources = ”mybatis.xml”)
     */
    String[] resources() default {};
}

        查询指定的资源,不仅仅可以查找classpath下的文件,还可以用来查找外部资源是否存在。

@Configuration
public class ConditionalConfig {

	@Bean
	@ConditionalOnResource(resources = "https://www.baidu.com")
	public Person person01() {
		return new Person();
	}

	@Bean
	@ConditionalOnResource(resources = "classpath:application.properties")
	public Person person02() {
		return new Person();
	}

	@Bean
	@ConditionalOnResource(resources = "https://www.baiduhaha.com")
	public Person person03() {
		return new Person();
	}
}

条件为Web应用的情况

@ConditionalOnWebApplication

@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(OnWebApplicationCondition.class)
public @interface ConditionalOnWebApplication {

    /**
     * 需要作为条件的Web应用程序的必需类型
     */
    ConditionalOnWebApplication.Type type() default ConditionalOnWebApplication.Type.ANY;

    /**
     * Available application types.
     */
    public static enum Type {

        /**
         * 任何web应用都将匹配
         */
        ANY,

        /**
         * 仅基于servlet的Web应用程序将匹配
         */
        SERVLET,

        /**
         * 仅基于反应式的Web应用程序将匹配
         */
        REACTIVE;

        private Type() {}
    }
}

        判断当前是否为Web项目/Web环境。主要就是从是否有导入Web的依赖。这里简单介绍以下三种不同情况的依赖引入情况。

<!-- 无Web容器 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- 使用Tomcat/Servlet Web容器 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 使用Netty 响应式的Web容器 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

@ConditionalOnNotWebApplication

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional({OnWebApplicationCondition.class})
public @interface ConditionalOnNotWebApplication {
}

参考文章

https://www.cnblogs.com/dusucyy/p/16609736.html

@ConditionalOnBean详解_你就像甜甜的益达的博客-CSDN博客a

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

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

相关文章

基于FPGA视频接口之HDMI2.0编/解码

简介 为什么要特别说明HDMI的版本,是因为HDMI的版本众多,代表的HDMI速度同样不同,当前版本在HDMI2.1速度达到48Gbps,可以传输4K及以上图像,但我们当前还停留在1080P@60部分,且使用的芯片和硬件结构有很大差别,故将HDMI分为两个部分说明1080@60以下分辨率和4K以上分辨率(…

怎么写出更好的高质量内容输出

为了更好地输出高质量的内容&#xff0c;不仅仅需要了解写作的基本原则&#xff0c;还需要深入挖掘目标读者的需求、持续的自我提升以及对信息的严格筛选。以下是一些建议&#xff0c;帮助你更好地输出高质量的内容&#xff1a; 1.充分了解你的受众 调查和了解你的目标读者&am…

SpringBoot整合阿里云OSS,实现图片上传

在项目中&#xff0c;将图片等文件资源上传到阿里云的OSS&#xff0c;减少服务器压力。 项目中导入阿里云的SDK <dependency><groupId>com.aliyun.oss</groupId><artifactId>aliyun-sdk-oss</artifactId><version>3.10.2</version>…

1985-2021年30m全国逐年土地覆被数据(含分省数据)

1.研究背景 2022年8月,武汉大学杨杰和黄昕教授团队向公众发布了CLCD 2021年全国土地覆数据。 中国在过去几十年中经济和人口迅速发展,土地覆盖随之发生巨大变化,因此迫切需要对其进行连续和精细的监测。然而,由于缺乏足够的训练样本和计算能力,基于卫星遥感观测数据的中国…

问道管理股市资讯:影视股集体走高,暑期档票房持续破纪录

影视股24日盘中集体走高&#xff0c;截至发稿&#xff0c;幸福蓝海、金逸影视涨停&#xff0c;上海电影、横店影视涨约8%&#xff0c;百纳千成、光线传媒涨约5%&#xff0c;中国电影、唐德影视、华谊兄弟等涨超3%。 上海问道私募基金管理有限公司&#xff08;百度一下问道管理&…

完成出版工作

书籍完成出版&#xff0c;正式上线售卖。若有需要&#xff0c;可在淘宝&#xff0c;当当&#xff0c;京东这些平台上都可以搜索到&#xff0c;书名是《多智能体机器人系统控制及其应用》&#xff0c;提前感谢&#xff0c;封面如下。 至于本专栏&#xff0c;留作大家讨论和书籍…

当一个程序员决定穿上粉色裤子

作为一个大众眼中的“非典型程序员”&#xff0c;我喜欢拥抱时尚和潮流&#xff0c;比如我经常在演讲时穿粉色裤子&#xff0c;这甚至已经成为一个标志性打扮。某天又逢主题演讲日&#xff0c;我站在衣柜前挑选上衣的时候&#xff0c;忽然灵光乍现&#xff1a;有没有可能借助 M…

基于jenkins自动化部署PHP环境

实验环境 操作系统 IP地址 主机名 角色 CentOS7.5 192.168.147.141 git git服务器 CentOS7.5 192.168.147.142 Jenkins git客户端 jenkins服务器 CentOS7.5 192.168.147.143 web web服务器 具体环境配置见上一篇&#xff01; 准备git仓库 [rootgit ~]# su -…

如何写好公文材料

写好公文材料需要具备一定的写作技巧&#xff0c;同时也需要对公文的格式、语言和结构有深入的了解。以下是如何写好公文材料的建议和步骤&#xff1a; 1.确定公文的目的 在开始写作前&#xff0c;明确公文的目的。它是为了传达什么样的信息&#xff1f;是通知、申请、报告、建…

专题-【十字链表】

有向图的十字链表表示法&#xff1a;

U盘文件恢复,拯救文件,只需简单3招!

“u盘文件删掉了还能恢复吗&#xff1f;七夕和对象吵架了&#xff0c;一气之下把之前一起旅游的照片视频都删了&#xff0c;今天看到空空的u盘&#xff0c;心里真的很难受。有什么方法可以恢复u盘文件吗&#xff1f;” U盘在我们的日常生活中已经扮演了很重要的角色&#xff0c…

TC1016-同星4路CAN(FD),2路LIN转USB接口卡

TC1016是同星智能推出的一款多通道CAN&#xff08;FD&#xff09;和LIN总线接口设备&#xff0c;CANFD总线速率最高支持8M bps&#xff0c;LIN支持速率0~20K bps&#xff0c;产品采用高速USB2.0接口与PC连接&#xff0c;Windows系统免驱设计使得设备具备极佳的系统兼容性。 支…

【附安装】R语言4.3.0安装教程

软件下载 软件&#xff1a;R语言版本&#xff1a;4.3.0语言&#xff1a;简体中文大小&#xff1a;77.74M安装环境&#xff1a;Win7及以上版本&#xff0c;64位操作系统硬件要求&#xff1a;CPU2.0GHz 内存4G(或更高&#xff09;下载通道①百度网盘丨64位下载链接&#xff1a;h…

android Junit4编写自测用例

10多年的android开发经验&#xff0c;一直以来呢&#xff0c;也没有使用过android自带的测试代码编写。说来也惭愧。今天也花了点时间稍微研究了下。还挺简单。接下来就简单的说一下。 新建工程 直接默认新建一个工程&#xff0c;就会有两个目录androidTest和test(unitTest)两…

漏洞复现 || muhttpd 任意文件读取

漏洞描述 muhttpd&#xff08;mu-HTTP-deamon&#xff09;是一个简单但完整的web服务器&#xff0c;用可移植的ANSI C编写。它支持静态页面、CGI脚本、基于MIME类型的处理程序和HTTPS&#xff0c;muhttpd 1.1.7之前版本存在安全漏洞。攻击者利用该漏洞读取系统任意文件。 免责…

免费制作高质量的电子期刊网站

工具介绍&#xff1a;FLBOOK 打开FLBOOK首页就能看见有四五本高质量的电子书刊&#xff0c;并且每打开一本&#xff0c;书的最下方就有阅读次数的统计。 FLBOOK制作电子期刊的方法也非常简单&#xff0c;可以根据小编的步骤开始制作或是看FLBOOK的教程&#xff0c;亲自动手制作…

第一讲使用IDEA创建Java工程——HelloWorld

一、前言导读 为了能够让初学者更快上手Java,不会像其他书籍或者视频一样,介绍一大堆历史背景,默认大家已经知道Java这么编程语言了。本专栏只会讲解干货,直接从HelloWord入手,慢慢由浅入深,讲个各个知识点,这些知识点也是目前工作中项目使用的,而不是讲一些老的知识点…

Tuxera NTFS2023中文版Mac读写NTFS格式硬盘访问、编辑、存储和传输文件工具

因为Mac电脑不能写入NTFS格式磁盘&#xff0c;但是多数用户使用的是NTFS格式的移动硬盘、u盘&#xff0c;因此很多NTFS for Mac软件应运而生。但是市面上很多NTFS for Mac软件很多&#xff0c;例如&#xff1a;Tuxera NTFS for Mac、Paragon NTFS for Mac等。Tuxera NTFS for M…

【分析绘图】R语言实现一些常见的绘图

微生信-在线绘图网站 线性图 library(ggplot2)x <- rnorm(100, 14, 5) # rnorm(n, mean 0, sd 1) y <- x rnorm(100, 0, 1) ggplot(data NULL, aes(x x, y y)) # 开始绘图geom_point(color "darkred") # 添加点annotate("text",x 13,…

Java面试题—2023年8月24日—YDZH

2023-08-24 10:54:28 北京 yī do zh h 答案仅供参考&#xff0c;博主仅记录发表&#xff0c;没有实际查询&#xff0c;不保证正确性。 面试题&#xff1a; 1、请你谈谈关于 Synchronized 和 lock ? 2、请简单描述一下类的加载过程?类加载器有几个种&#xff0c;分别作用是什…