关于一些开发过程中需要了解的知识点
推荐
springAll:github也有相对应的代码
其它
maven的哲学在上次技术分享的时候也提到了:约定大于配置
1.linux常用
https://github.com/Snailclimb/JavaGuide/blob/master/docs/operating-system/linux.md
2.maven的SNAPSHOT版本与RELEASE版本的区别
1、SNAPSHOT版本代表不稳定(快照版本),还在处于开发阶段,随时都会有变化。当上传同样的版本号jar包的时候,SNAPSHOT会在版本号的后面自动追加一串新的数字,即日志标签;
2、RELEASE则代表稳定的版本(发布版本),一般上线后都会改用RELEASE版本。
在maven的依赖管理机制中,唯一标识一个依赖项是由该依赖项的三个属性构成的,分别是groupId、artifactId以及Version。这三个属性唯一确定一个组件(即我们平时说的war包和jar包)。
3.maven查看pom中各个依赖关系
4.pom中手动删除自己不需要的依赖
比如spring-boot-starter-web默认集成了tomcat,假如我们想把它换为jetty,可以在pom.xml中spring-boot-starter-web下排除tomcat依赖,然后手动引入jetty依赖:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency> </dependencies>
//格式说明
<exclusions> <exclusion> 不需要的内部依赖 </exclusion> </exclusions>
5.springboot在pom中的引用
因为一般使用springboot都会先引用spring-boot-starter-parent,而其他比如spring-boot-starter-web、spring-boot-starter-test等等都是依赖于spring-boot-starter-parent,所以可以不写version。
个人猜测这种依赖关系是groupId相同的原因,比如以上几个的都是 <groupId>org.springframework.boot</groupId>
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.7</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
6.scope的分类
- compile:默认值 他表示被依赖项目需要参与当前项目的编译,还有后续的测试,运行周期也参与其中,是一个比较强的依赖。打包的时候通常需要包含进去
- test:依赖项目仅仅参与测试相关的工作,包括测试代码的编译和执行,不会被打包,例如:junit
- runtime:表示被依赖项目无需参与项目的编译,不过后期的测试和运行周期需要其参与。与compile相比,跳过了编译而已。例如JDBC驱动,适用运行和测试阶段
- provided:打包的时候可以不用包进去,别的设施会提供。事实上该依赖理论上可以参与编译,测试,运行等周期。相当于compile,但是打包阶段做了exclude操作
- system:从参与度来说,和provided相同,不过被依赖项不会从maven仓库下载,而是从本地文件系统拿。需要添加systemPath的属性来定义路径