Loading

SpringCloudAlibaba学习笔记--Java基础知识

dependencyManagement与dependencies区别

父模块声明
点击查看代码
<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.44</version>
            </dependency>
        </dependencies>
</dependencyManagement>
子模块引用
点击查看代码
 <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
 </dependencies>
  • 子模块声明的时候不需要引用版本号,dependencyManagement父模块统一控制版本号
  • dependencyManagement父模块声明的依赖如果子模块不声明则不继承
  • 但是子模块指定了版本号则子模块版本号覆盖

@interface注解学习

@interface自定义注解自动继承了java.lang.annotation.Annotation接口,由编译程序自动完成其他细节。
在定义注解时,不能继承其他的注解或接口。
使用@interface来声明一个注解

作用在属性上
点击查看代码
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface FiledAnnotation {
	 String value() default "GetFiledAnnotation";   
}
作用在方法上注解
点击查看代码
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MethodAnnotation {
	String name() default "MethodAnnotation";   
    String url() default "https://www.cnblogs.com";
}
作用在类上
点击查看代码
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface TypeAnnotation {
	String value() default "Is-TypeAnnotation";
}

1、RetentionPolicy.SOURCE:注解只保留在源文件,当Java文件编译成class文件的时候,注解被遗弃;
2、RetentionPolicy.CLASS:注解被保留到class文件,但jvm加载class文件时候被遗弃,这是默认的生命周期;
3、RetentionPolicy.RUNTIME:注解不仅被保存到class文件中,jvm加载class文件之后,仍然存在;

参考链接

https://blog.csdn.net/u010002184/article/details/79166478
https://blog.csdn.net/u010002184/article/details/79166478

posted @ 2022-09-01 15:12  DoDo神  阅读(31)  评论(0)    收藏  举报