重新认识maven

本文内容,为 中华石杉课程 本人的学习笔记,如有侵权,联系我删除,谢谢。

目标

  1. 能够快速熟悉公司项目的maven配置,并且能够配置自己的maven配置
  2. 配置maven,不用再copy,能够做到应用自如
  3. 开源项目的maven配置文件,不在迷茫
  4. 能够搭建自己的maven私服,用maven进行企业级的规范工程管理

maven背景

自己依赖的jar,都需要自己copy到lib文件夹中。

  1. 大型项目依赖的jar,非常多
  2. 缺少依赖,自己寻找依赖的对应的jar
  3. 依赖冲突,依赖版本可能不一样
  4. 单体应用,拆分成多个模块的,每个模块都是一个工程,最后还得将所有的工程合并,编译起来通过统一的入口进行启动。

流程痛苦

自己一顿操作在本地跑起来,然后进行集成测试,然后编译代码,然后手动打包,然后将war\jar部署到服务器,QA测试,出现了bug之后,我们又得本地跑,集成测试,手工打包,编译部署,一直到测试通过

最后,将通过测试的jar或者war,部署到上线生产环境。

结论

效率低下,程序员维护各种jar非常痛苦。

maven如何解决依赖和构建自动化的问题

  1. 上班,先写代码,然后编写单元测试,接着一个maven test 的命令,maven就自动将项目中单元测试自动哦跑起来,还能自动出来一个完整的单元测试的覆盖率的报告,已经单元测试运行错误的一份报告
  2. 如果一个系统有多工程,maven会将多个模块工程集成起来,无需手动集成
  3. 对应依赖,完成自动化,简单配置一下依赖,maven会自动下载依赖的版本,所有依赖下载、版本调解、版本升级等繁琐的事情都交给maven自动完成
  4. 编译+打包+发布,自动化
  5. maven对工程进行统一的编译、打包,发布,

总而言之,用了maven之后,在依赖管理、构建管理、模块化拆分管理,全部自动化完成

maven的历史

  1. make
    最原始的工具,不能跨品台
  2. ant
    配置烦杂
  3. maven
    目前还是最有影响力的工具之一
  4. gradle
    不再依赖xml进行配置,基于DSL语言进行构建

未来,预计还是maven和gradle共存的年代

安装maven(Windows or Mac)

  1. install Jdk environment(java -version —》1.8)
  2. download maven zip
  3. set path M2_HOME or MAVEN_OPTS -Xms128 -Xmx512m
  4. set setting.xml
  5. mvn help:system will auto download some requirement

maven基本使用

maven快速构建一个工程

mvn archetype:generate -DgroupId=com.jaryoung.demo -DartifactId=first-demo -DarchetypeArtiactId=maven-archetype-quickstart -DinteractiveMode=false

maven的目录约定

1
2
3
4
5
6
源码:
/src/main/java
单元测试:
/src/main/java
核心maven配置文件
pom.xml

pom.xml之初认识

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!-- pom.xml 中顶层的元素 -->
<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/maven-v4_0_0.xsd">
<!-- pom本身的版本号,一般很少改变 -->
<modelVersion>4.0.0</modelVersion>
<!-- 项目所在的组织 -->
<groupId>com.jaryoung.demo</groupId>
<!-- 项目中唯一标识 -->
<artifactId>first-demo</artifactId>
<!-- 项目的打包类型 -->
<packaging>jar</packaging>
<!-- 项目的版本号 -->
<version>1.0-SNAPSHOT</version>
<!-- 项目的展示的名称 -->
<name>first-demo</name>
<!-- 项目的文档下载url -->
<url>http://maven.apache.org</url>
<!-- 项目的描述 -->
<description>
<p> my first demo
</description>
<!-- pom 配置文件的配置项 -->
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<!-- 依赖配置 -->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

maven对项目进行打包

源代码和单元测试写好之后,可以通过maven进行自动化的单元测试和编译 、打包。

mvn clean package,会先清空target目录下所有的内容,然后对工程进行构建,构建出来一个可以执行的jar包。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
xxx@xx-Pro  ~/project/demo/first-demo  mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building first-demo 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ first-demo ---
[INFO] Deleting /Users/jaryoung/project/demo/first-demo/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ first-demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/jaryoung/project/demo/first-demo/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ first-demo ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/jaryoung/project/demo/first-demo/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ first-demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/jaryoung/project/demo/first-demo/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ first-demo ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/jaryoung/project/demo/first-demo/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ first-demo ---
Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-booter/2.12.4/surefire-booter-2.12.4.pom
[INFO] Surefire report directory: /Users/jaryoung/project/demo/first-demo/target/surefire-reports
Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-junit3/2.12.4/surefire-junit3-2.12.4.pom
Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-junit3/2.12.4/surefire-junit3-2.12.4.pom (0 B at 0 B/s)
Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-providers/2.12.4/surefire-providers-2.12.4.pom
Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-providers/2.12.4/surefire-providers-2.12.4.pom (0 B at 0 B/s)
Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-junit3/2.12.4/surefire-junit3-2.12.4.jar
Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-junit3/2.12.4/surefire-junit3-2.12.4.jar (0 B at 0 B/s)

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.jaryoung.demo.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.005 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ first-demo ---
Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/maven-archiver/2.5/maven-archiver-2.5.pom
[INFO] Building jar: /Users/jaryoung/project/demo/first-demo/target/first-demo-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.617 s
[INFO] Finished at: 2021-02-17T16:15:08+08:00
[INFO] Final Memory: 16M/60M
[INFO] ------------------------------------------------------------------------

执行jar包

1
java -cp target/first-demo-1.0-SNAPSHOT.jar com.jaryoung.demo.App

maven架构

maven鸟瞰图

%E9%87%8D%E6%96%B0%E8%AE%A4%E8%AF%86maven%2024fba34a5ee5462cbca9db8b86fe4619/Untitled.png

maven重要的知识点

maven坐标

1
2
3
4
5
6
7
8
9
10
<!-- 项目所在的组织 -->
<groupId>com.jaryoung.demo</groupId>
<!-- 项目中唯一标识 -->
<artifactId>first-demo</artifactId>
<!-- 项目的打包类型 -->
<packaging>jar</packaging>
<!-- 项目的版本号 -->
<version>1.0-SNAPSHOT</version>
<!-- 定义某个工程的附属项目 -->
<classifier> </classifier>

坐标的作用,上面的五个坐标就代表了特定版本的代码,就是特定代码版本的jar包,可以上传到maven的仓库,能够提供给别人下载使用。

总结:

  1. 坐标的元素(五个g a p v c)
  2. 每个坐标的意义
  3. 五个坐标的作用

依赖标签重认识

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<dependency>
<!-- 三要素 groupId、artifactId、version -->
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.2.16.RELEASE</version>

<!-- 项目类型,比较少用 -->
<type>xx</type>

<!-- 依赖范围 -->
<scope>test</scope>

// maven有三套classpath
// 1. 编译源码 2. 单元测试 3.项目运行
// 编译、测试、运行 三个不同的阶段会有不同的类型
// compile:默认,对于编译、测试、运行的classpath都是有效
// test:测试的classpath有效
// provided:编译和测试的classpath有效
// runtime:测试和运行的classpath有效

maven的传递性依赖,会自动递归解析所有的依赖,然后下载到本地仓库。

我们的项目依赖了junit,junit依赖A,A又依赖了B

如果我们的junit的依赖范围是test,junit对A的依赖范围是compile(默认),
我们项目对A的依赖范围也是test

如果我们依赖A,范围为compile(默认),A又依赖B范围:test,那么我们是不会依赖它。

第一列为,一级依赖,第一行为,二级依赖
compile test provided runtime
compile compile runtime
test test test
provided provided provided provided
runtime runtime runtime
有可能依赖是不会传递的,就是可能有些多层级的依赖,是不会成为项目的依赖。

依赖调解(就近原则)
A->B->C->Y(1.0),A->D->Y(2.0),就近原则,会选择Y(2.0)
A->B->Y(1.0),A->D->Y(2.0),A声明那个就用那个

<!-- 可选依赖 -->
// 如果为true,不会向上传递,否则会先上传递
<optional>true</optional>
</dependency>

解决依赖冲突

例子:

A → B → Y(1.0)

A → B → C → Y(2.0)

Y (2.0) 某个接口增加一个方法,所以调用的时候,就会有找不到方法。

解决办法:

使用新版本,一般来说开源项目是会有向后兼容性的。

分析

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
mvn dependency:tree

INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building oa-org 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ oa-org ---
Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/doxia/doxia-sink-api/1.0-alpha-10/doxia-sink-api-1.0-alpha-10.pom
....
[INFO] com.jaryoung:oa-org:jar:1.0-SNAPSHOT
[INFO] +- org.springframework:spring-core:jar:3.2.18.RELEASE:compile
[INFO] | \- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] +- org.springframework:spring-webmvc:jar:3.2.18.RELEASE:compile
[INFO] | +- org.springframework:spring-beans:jar:3.2.18.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:3.2.18.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:3.2.18.RELEASE:compile
[INFO] +- org.springframework:spring-context-support:jar:3.2.15.RELEASE:compile
[INFO] +- org.springframework:spring-aop:jar:3.2.18.RELEASE:compile
[INFO] | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.springframework:spring-aspects:jar:3.2.15.RELEASE:compile
[INFO] | \- org.aspectj:aspectjweaver:jar:1.7.4:compile
[INFO] +- org.springframework:spring-tx:jar:3.2.18.RELEASE:compile
[INFO] +- org.springframework:spring-jdbc:jar:3.2.18.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:3.2.18.RELEASE:compile
[INFO] +- junit:junit:jar:4.12:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.springframework:spring-test:jar:3.2.16.RELEASE:test
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.25:compile
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] | \- log4j:log4j:jar:1.2.17:compile
[INFO] +- org.mybatis:mybatis:jar:3.2.3:compile
[INFO] +- org.mybatis:mybatis-spring:jar:1.2.0:compile
[INFO] \- mysql:mysql-connector-java:jar:5.1.29:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 26.348 s
[INFO] Finished at: 2021-02-19T09:02:57+08:00
[INFO] Final Memory: 16M/189M
[INFO] ------------------------------------------------------------------------

排除旧版本

1
2
3
4
5
6
7
8
9
10
11
<dependency>
<groupId>B</groupId>
<artifactId>B</artifactId>
<version>3.5.5</version>
<exclusions>
<exclusion>
<groupId>Y</groupId>
<artifactId>Y</artifactId>
</exclusion>
</exclusions>
</dependency>

maven仓库

目的,为了消除重复jar包,以前没有maven的时候,各个项目都要有自己的lib目录存放各种依赖jar包。

  1. 本地仓库
  2. 云端仓库
    1. 官方中央仓库
    2. 内网私服
    3. 阿里云镜像

%E9%87%8D%E6%96%B0%E8%AE%A4%E8%AF%86maven%2024fba34a5ee5462cbca9db8b86fe4619/Untitled%201.png

maven的生命周期以及执行原理

Maven - Available Plugins

生命周期的图

mvn命令相关的

mvn clean package

mvn clean install

mvn clean deploy

独立的生命周期(phase)

  1. clean
    1. pre-clean
    2. clean
    3. post-clean
  2. default
    1. validate
    2. initialize
    3. generate-sources
    4. process-sources
    5. process-resources
    6. compile
    7. process-classes
    8. generate-test-sources
    9. generate-test-resources
    10. process-test-resources
    11. test-compile
    12. process-test-classes
    13. test
    14. prepare-package
    15. package
    16. pre-integration-test
    17. integration-test
    18. post-integration-test
    19. verify
    20. install
    21. deploy
  3. site(部署文档)
    1. pre-site
    2. site
    3. post-site
    4. site-deploy

phrase和plugin的绑定

process-resources -》 resources:resources

compile -》 compile:compile

process-test-resources -》 resources:testResources

test-compile -》compiler:testCompile

test -》surefire:test

package -》jar:jar or war:war

install -》install:install

deploy -》deploy:deploy

site -》site:site

clean -》clean:clean

命令行和phrase的关系

mvn clean package

%E9%87%8D%E6%96%B0%E8%AE%A4%E8%AF%86maven%2024fba34a5ee5462cbca9db8b86fe4619/Untitled%202.png

clean,代表是clean 生命周期的中clean phase。

会执行,clean 所有的 操作,也就是上面clean 的1 - 3 步。

package,代表是会执行default中package phase之前所有的操作,当然也包含当前packagephase的操作

mvn dependency:tree

%E9%87%8D%E6%96%B0%E8%AE%A4%E8%AF%86maven%2024fba34a5ee5462cbca9db8b86fe4619/Untitled%203.png

mvn deploy:deploy-file

直接执行,不会执行任何 default上面的生命周期的内容,会直接执行插件的中的goal。例如 ,mvn dependency:tree,直接执行dependency插件中的tree的goal。

plugin配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>source jar</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>

maven企业级实战

从0到1搭建一个私服仓库

架构图

%E9%87%8D%E6%96%B0%E8%AE%A4%E8%AF%86maven%2024fba34a5ee5462cbca9db8b86fe4619/Untitled%204.png

  1. 下载 neuxs repository

    docker pull sonatype/nexus3:latest

  2. 启动

    1
    2
    3
    -v 挂载volume到意思
    $PWD 代表到是当前到目录
    docker run -d -p 8090:8081 --name nexus -v $PWD/nexus-data:/nexus-data sonatype/nexus3
  3. 修改maven-central代理仓库中的remote storage https://repo1.maven.org/maven2/ 修改成:https://maven.aliyun.com/repository/central

    %E9%87%8D%E6%96%B0%E8%AE%A4%E8%AF%86maven%2024fba34a5ee5462cbca9db8b86fe4619/Untitled%205.png

  4. maven-snapshot和maven-releases宿主仓库已有,无需修改

  5. 3rd-party仓库,需要手动创建,并且配置到maven-public group中

    %E9%87%8D%E6%96%B0%E8%AE%A4%E8%AF%86maven%2024fba34a5ee5462cbca9db8b86fe4619/Untitled%206.png

    选择 maven2(hosted),宿主类型

    %E9%87%8D%E6%96%B0%E8%AE%A4%E8%AF%86maven%2024fba34a5ee5462cbca9db8b86fe4619/Untitled%207.png

    输入3rd-party,然后创建。

    设置maven-public

    %E9%87%8D%E6%96%B0%E8%AE%A4%E8%AF%86maven%2024fba34a5ee5462cbca9db8b86fe4619/Untitled%208.png

    添加组内,保存,大功告成

    %E9%87%8D%E6%96%B0%E8%AE%A4%E8%AF%86maven%2024fba34a5ee5462cbca9db8b86fe4619/Untitled%209.png

  6. 本地强制配置走私服

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    <?xml version="1.0" encoding="UTF-8"?>

    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <pluginGroups>

    </pluginGroups>

    <proxies>

    </proxies>

    <servers>
    <!--配置专用账号 -->
    <server>
    <id>nexus-releases</id>
    <username>nx-deployment</username>
    <password>nx-deployment123</password>
    </server>
    <server>
    <id>nexus-snapshots</id>
    <username>nx-deployment</username>
    <password>nx-deployment123</password>
    </server>
    <server>
    <id>nexus-3rd-party</id>
    <username>nx-deployment</username>
    <password>nx-deployment123</password>
    </server>
    </servers>

    <mirrors>
    <mirror>
    <id>nexus</id>
    <mirrorOf>*</mirrorOf>
    <url>http://localhost:8090/repository/maven-public/</url>
    </mirror>

    </mirrors>

    <profiles>
    <profile>
    <id>neuxs</id>
    <repositories>
    <repository>
    <id>neuxs</id>
    <name>neuxs</name>
    <url>http://localhost:8090/repository/maven-public/</url>
    <releases>
    <enabled>true</enabled>
    </releases>
    <snapshots>
    <enabled>true</enabled>
    </snapshots>
    </repository>
    </repositories>
    </profile>
    <pluginRepositories>
    <pluginRepository>
    <id>nexus</id>
    <name>Nexus Plugin Repository</name>
    <url>http://localhost:8090/repository/maven-public/</url>
    <releases>
    <enabled>true</enabled>
    </releases>
    <snapshots>
    <enabled>true</enabled>
    </snapshots>
    </pluginRepository>
    </pluginRepositories>

    </profiles>

    <activeProfiles>
    <activeProfile>neuxs</activeProfile>
    </activeProfiles>

    </settings>
  7. 权限管理,例如配置一个可以上传的jar的账号,nx-deployment

    %E9%87%8D%E6%96%B0%E8%AE%A4%E8%AF%86maven%2024fba34a5ee5462cbca9db8b86fe4619/Untitled%2010.png

  8. 使用专用的账号,上传

    pom文件添加,需要跟setting文件中的 servers 配置server的id一致

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <distributionManagement>
    <repository>
    <!-- 需要跟setting文件中的 servers 配置server的id一致 -->
    <id>nexus-releases</id>
    <name>Releases</name>
    <url>http://localhost:8090/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
    <id>nexus-snapshots</id>
    <name>Snapshot</name>
    <url>http://localhost:8090/repository/maven-snapshots/</url>
    </snapshotRepository>
    </distributionManagement>
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    mvn clean deploy
    [WARNING]
    [WARNING] Some problems were encountered while building the effective settings
    [WARNING] Unrecognised tag: 'pluginRepositories' (position: START_TAG seen ...</profile>\n <pluginRepositories>... @252:25) @ /Users/jaryoung/.m2/settings.xml, line 252, column 25
    [WARNING]
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building oa-org 1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ oa-org ---
    [INFO] Deleting /Users/jaryoung/project/study/maven/oa-org/target
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ oa-org ---
    [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
    [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] Copying 5 resources
    [INFO] Copying 5 resources
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ oa-org ---
    [INFO] Changes detected - recompiling the module!
    [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
    [INFO] Compiling 5 source files to /Users/jaryoung/project/study/maven/oa-org/target/classes
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ oa-org ---
    [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] skip non existing resourceDirectory /Users/jaryoung/project/study/maven/oa-org/src/test/resources
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ oa-org ---
    [INFO] Changes detected - recompiling the module!
    [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
    [INFO] Compiling 1 source file to /Users/jaryoung/project/study/maven/oa-org/target/test-classes
    [INFO]
    [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ oa-org ---
    [INFO] Surefire report directory: /Users/jaryoung/project/study/maven/oa-org/target/surefire-reports
    Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.pom
    Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.pom (0 B at 0 B/s)
    Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.jar
    Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.jar (0 B at 0 B/s)

    -------------------------------------------------------
    T E S T S
    -------------------------------------------------------
    Running com.jaryoung.oa.org.service.impl.EmployeeServiceImplTest
    log4j:ERROR Could not find value for key log4j.appender.Stdout
    log4j:ERROR Could not instantiate appender named "Stdout".
    2021-02-20 00:38:22,869 [main] DEBUG [org.springframework.test.context.junit4.SpringJUnit4ClassRunner] - SpringJUnit4ClassRunner constructor called with [class com.jaryoung.oa.org.service.impl.EmployeeServiceImplTest].
    2021-02-20 00:38:22,914 [main] DEBUG [org.springframework.test.context.support.AbstractDelegatingSmartContextLoader] - Delegating to GenericXmlContextLoader to process context configuration [ContextConfigurationAttributes@60addb54 declaringClass = 'com.jaryoung.oa.org.service.impl.EmployeeServiceImplTest', classes = '{}', locations = '{classpath*:application-org.xml}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.springframework.test.context.ContextLoader'].
    2021-02-20 00:38:22,915 [main] DEBUG [org.springframework.test.context.ContextLoaderUtils] - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.jaryoung.oa.org.service.impl.EmployeeServiceImplTest]
    2021-02-20 00:38:22,917 [main] DEBUG [org.springframework.test.context.TestContextManager] - @TestExecutionListeners is not present for class [com.jaryoung.oa.org.service.impl.EmployeeServiceImplTest]: using defaults.
    2021-02-20 00:38:22,919 [main] INFO [org.springframework.test.context.TestContextManager] - Could not instantiate TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [javax/servlet/ServletContext]
    2021-02-20 00:38:22,929 [main] DEBUG [org.springframework.test.annotation.ProfileValueUtils] - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.jaryoung.oa.org.service.impl.EmployeeServiceImplTest]
    2021-02-20 00:38:22,929 [main] DEBUG [org.springframework.test.annotation.ProfileValueUtils] - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.jaryoung.oa.org.service.impl.EmployeeServiceImplTest]
    2021-02-20 00:38:22,930 [main] DEBUG [org.springframework.test.annotation.ProfileValueUtils] - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.jaryoung.oa.org.service.impl.EmployeeServiceImplTest]
    2021-02-20 00:38:22,930 [main] DEBUG [org.springframework.test.annotation.ProfileValueUtils] - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.jaryoung.oa.org.service.impl.EmployeeServiceImplTest]
    2021-02-20 00:38:22,932 [main] DEBUG [org.springframework.test.annotation.ProfileValueUtils] - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.jaryoung.oa.org.service.impl.EmployeeServiceImplTest]
    2021-02-20 0est.context.support.DirtiesContextTestExecutionListener] - After test class: context [[TestContext@50c87b21 testClass = EmployeeServiceImplTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@1810399e testClass = EmployeeServiceImplTest, locations = '{classpath*:application-org.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]], dirtiesContext [false].
    Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.191 sec
    2021-02-20 00:38:23,962 [Thread-0] INFO [org.springframework.context.support.GenericApplicationContext] - Closing org.springframework.context.support.GenericApplicationContext@26be92ad: startup date [Sat Feb 20 00:38:23 CST 2021]; root of context hierarchy
    2021-02-20 00:38:23,962 [Thread-0] DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'sqlSessionFactory'
    2021-02-20 00:38:23,962 [Thread-0] DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'lifecycleProcessor'
    2021-02-20 00:38:23,962 [Thread-0] INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@80ec1f8: defining beans [propertyConfigurer,dataSource,sqlSessionFactory,org.mybatis.spring.mapper.MapperScannerConfigurer#0,employeeService,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,employeeDao]; root of factory hierarchy
    2021-02-20 00:38:23,962 [Thread-0] DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Retrieved dependent beans for bean 'employeeService': [com.jaryoung.oa.org.service.impl.EmployeeServiceImplTest]

    Results :

    Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

    [INFO]
    [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ oa-org ---
    [INFO] Building jar: /Users/jaryoung/project/study/maven/oa-org/target/oa-org-1.0-SNAPSHOT.jar
    [INFO]
    [INFO] --- maven-install-plugin:2.4:install (default-install) @ oa-org ---
    [INFO] Installing /Users/jaryoung/project/study/maven/oa-org/target/oa-org-1.0-SNAPSHOT.jar to /Users/jaryoung/.m2/repository/com/jaryoung/oa-org/1.0-SNAPSHOT/oa-org-1.0-SNAPSHOT.jar
    [INFO] Installing /Users/jaryoung/project/study/maven/oa-org/pom.xml to /Users/jaryoung/.m2/repository/com/jaryoung/oa-org/1.0-SNAPSHOT/oa-org-1.0-SNAPSHOT.pom
    [INFO]
    [INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ oa-org ---
    Downloading from nexus-snapshots: http://localhost:8090/repository/maven-snapshots/com/jaryoung/oa-org/1.0-SNAPSHOT/maven-metadata.xml
    Downloaded from nexus-snapshots: http://localhost:8090/repository/maven-snapshots/com/jaryoung/oa-org/1.0-SNAPSHOT/maven-metadata.xml (762 B at 28 kB/s)
    Uploading to nexus-snapshots: http://localhost:8090/repository/maven-snapshots/com/jaryoung/oa-org/1.0-SNAPSHOT/oa-org-1.0-20210219.163824-5.jar
    Uploaded to nexus-snapshots: http://localhost:8090/repository/maven-snapshots/com/jaryoung/oa-org/1.0-SNAPSHOT/oa-org-1.0-20210219.163824-5.jar (13 kB at 155 kB/s)
    Uploading to nexus-snapshots: http://localhost:8090/repository/maven-snapshots/com/jaryoung/oa-org/1.0-SNAPSHOT/oa-org-1.0-20210219.163824-5.pom
    Uploaded to nexus-snapshots: http://localhost:8090/repository/maven-snapshots/com/jaryoung/oa-org/1.0-SNAPSHOT/oa-org-1.0-20210219.163824-5.pom (4.9 kB at 68 kB/s)
    Downloading from nexus-snapshots: http://localhost:8090/repository/maven-snapshots/com/jaryoung/oa-org/maven-metadata.xml
    Downloaded from nexus-snapshots: http://localhost:8090/repository/maven-snapshots/com/jaryoung/oa-org/maven-metadata.xml (276 B at 13 kB/s)
    Uploading to nexus-snapshots: http://localhost:8090/repository/maven-snapshots/com/jaryoung/oa-org/1.0-SNAPSHOT/maven-metadata.xml
    Uploaded to nexus-snapshots: http://localhost:8090/repository/maven-snapshots/com/jaryoung/oa-org/1.0-SNAPSHOT/maven-metadata.xml (762 B at 12 kB/s)
    Uploading to nexus-snapshots: http://localhost:8090/repository/maven-snapshots/com/jaryoung/oa-org/maven-metadata.xml
    Uploaded to nexus-snapshots: http://localhost:8090/repository/maven-snapshots/com/jaryoung/oa-org/maven-metadata.xml (276 B at 4.6 kB/s)
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 5.095 s
    [INFO] Finished at: 2021-02-20T00:38:24+08:00
    [INFO] Final Memory: 23M/190M
    [INFO] ------------------------------------------------------------------------
  9. 上传到3rd-party仓库
    mvn deploy:deploy-file -DgroupId=com.stbz -DartifactId=stbz -Dversion=1.0 -Dpackaging=jar -Dfile=$PWD/target/stbz-1.0.jar -Durl=http://localhost:8090/repository/3rd-party/ -DrepositoryId=nexus-3rd-party

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    ~/project/study/maven/stbz mvn deploy:deploy-file -DgroupId=com.stbz -DartifactId=stbz -Dversion=1.0 -Dpackaging=jar -Dfile=$PWD/target/stbz-1.0.jar -Durl=http://localhost:8090/repository/3rd-party/ -DrepositoryId=nexus-3rd-party
    [WARNING]
    [WARNING] Some problems were encountered while building the effective settings
    [WARNING] Unrecognised tag: 'pluginRepositories' (position: START_TAG seen ...</profile>\n <pluginRepositories>... @257:25) @ /Users/jaryoung/.m2/settings.xml, line 257, column 25
    [WARNING]
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building stbz 1.0
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- maven-deploy-plugin:2.8.2:deploy-file (default-cli) @ stbz ---
    Uploading to nexus-3rd-party: http://localhost:8090/repository/3rd-party/com/stbz/stbz/1.0/stbz-1.0.jar
    Uploaded to nexus-3rd-party: http://localhost:8090/repository/3rd-party/com/stbz/stbz/1.0/stbz-1.0.jar (403 kB at 829 kB/s)
    Uploading to nexus-3rd-party: http://localhost:8090/repository/3rd-party/com/stbz/stbz/1.0/stbz-1.0.pom
    Uploaded to nexus-3rd-party: http://localhost:8090/repository/3rd-party/com/stbz/stbz/1.0/stbz-1.0.pom (383 B at 1.5 kB/s)
    Downloading from nexus-3rd-party: http://localhost:8090/repository/3rd-party/com/stbz/stbz/maven-metadata.xml
    Uploading to nexus-3rd-party: http://localhost:8090/repository/3rd-party/com/stbz/stbz/maven-metadata.xml
    Uploaded to nexus-3rd-party: http://localhost:8090/repository/3rd-party/com/stbz/stbz/maven-metadata.xml (288 B at 1.7 kB/s)
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 1.728 s
    [INFO] Finished at: 2021-02-21T13:48:37+08:00
    [INFO] Final Memory: 10M/204M
    [INFO] ------------------------------------------------------------------------
  10. 配置task,创建日常任务的task

仓库类型

%E9%87%8D%E6%96%B0%E8%AE%A4%E8%AF%86maven%2024fba34a5ee5462cbca9db8b86fe4619/Untitled%2011.png

  1. group:仓库组,虚拟的仓库组。中央仓库:maven1或者maven2
  2. hosted:宿主仓库,内部发布使用
  3. proxy:代理仓库,代理各种其他的仓库的。

maven-central:maven中央仓库代理仓库

maven-releases:宿主仓库,用于部署公司内部的发布的release版本项目

maven-snapshots:宿主仓库,用于部署公司内部的发布的snapshot版本项目

3rd party:宿主仓库,用于部署三方的项目

maven public:仓库组,所有release仓库都在这个仓库组

OA需求分析

  1. 组织模块
    包含部门和员工,curd
  2. 权限模块
    员工、角色、权限
  3. 审批模块
    员工、申请、审批

从0到1搭建一个spring + mvc + mybatis到项目

  1. 创建maven项目
  2. 编写pom依赖
  3. 配置Spring 、mybatis、日志配置
  4. 自动生成curd操作和相关到类
  5. 编写单元测试

开发权限管理模块

idea esay code 自动生成代码

1
2
3
4
5
6
7
CREATE TABLE `authorization`
(
`id` INT NOT NULL AUTO_INCREMENT,
`employee_id` INT NULL,
`role_id` INT NULL,
PRIMARY KEY (`id`)
);

开发流程审批模块

idea esay code 自动生成代

1
2
3
4
5
6
7
CREATE TABLE `application`
(
`id` INT NOT NULL AUTO_INCREMENT,
`employee_id` INT NULL,
`days` INT NULL,
PRIMARY KEY (`id`)
);

基于聚合功能实现多模块统一构建

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?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>

<groupId>com.jaryoung.oa</groupId>
<artifactId>oa-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>oa parent pom</name>

<modules>
<module>oa-org</module>
<module>oa-auth</module>
<module>oa-flow</module>
</modules>
</project>

基于继承功能将所有模块的依赖版本强制统一

解决父子pom版本统一的问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?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>

<groupId>com.jaryoung.oa</groupId>
<artifactId>oa-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>oa parent pom</name>

<modules>
<module>oa-org</module>
<module>oa-auth</module>
<module>oa-flow</module>
</modules>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<springframework.release.version>5.1.3.RELEASE</springframework.release.version>
<jackson.version>2.9.2</jackson.version>
</properties>

<dependencyManagement>
<dependencies>
<!-- spring依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${springframework.release.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${springframework.release.version}</version>
<scope>test</scope>
</dependency>

<!-- 文件上传 -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>

</dependencies>
</dependencyManagement>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>

依赖集中约束版本号

解决版本依赖统一的问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?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>

<groupId>com.jaryoung.oa</groupId>
<artifactId>oa-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>oa parent pom</name>

<modules>
<module>oa-org</module>
<module>oa-auth</module>
<module>oa-flow</module>
</modules>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<springframework.release.version>5.1.3.RELEASE</springframework.release.version>
</properties>

<dependencyManagement>
<dependencies>
<!-- spring依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${springframework.release.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${springframework.release.version}</version>
<scope>test</scope>
</dependency>

</dependencies>
</dependencyManagement>

</project>

基于import pom强制约束依赖方的版本号

组件强制要求依赖方需要使用合理版本依赖,以防止组件在被依赖之后,无法使用的情况。

  1. 新建 oa-common的项目,pom文件如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    <?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>

    <groupId>com.jaryoung.oa</groupId>
    <artifactId>oa-common</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
    <maven.compiler.source>8</maven.compiler.source>
    <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
    <dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.11.3</version>
    </dependency>
    </dependencies>

    </project>
  2. 新建bom文件,也就是一个特殊maven项目,只有pom文件的

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    <?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>

    <groupId>com.jaryoung.bom</groupId>
    <artifactId>oa-commons-bom</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <properties>
    <maven.compiler.source>8</maven.compiler.source>
    <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencyManagement>
    <dependencies>
    <dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.11.3</version>
    </dependency>
    </dependencies>
    </dependencyManagement>

    </project>
  3. 在 dependencyManagement 通过 import方式导入到项目中

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    <?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>
    <groupId>com.jaryoung.oa</groupId>
    <artifactId>oa-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>oa-org</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>oa-org</name>
    <!-- FIXME change it to the project's website -->
    <url>http://www.example.com</url>

    <dependencies>
    <dependency>
    <groupId>com.jaryoung.oa</groupId>
    <artifactId>oa-common</artifactId>
    <version>1.0-SNAPSHOT</version>
    </dependency>

    <dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.9.2</version>
    </dependency>
    </dependencies>

    <dependencyManagement>
    <dependencies>
    <dependency>
    <groupId>com.jaryoung.bom</groupId>
    <artifactId>oa-commons-bom</artifactId>
    <version>1.0-SNAPSHOT</version>
    <type>pom</type>
    <!-- oa-common-bom 组件的依赖,作为引入组件 oa-common,-->
    <!-- 引用的开源或者其他项目的版本依赖 -->
    <scope>import</scope>
    </dependency>
    </dependencies>
    </dependencyManagement>

    </project>

开发OA系统的web服务

目录结构

%E9%87%8D%E6%96%B0%E8%AE%A4%E8%AF%86maven%2024fba34a5ee5462cbca9db8b86fe4619/Untitled%2012.png

java
resources
—application-web.xml
—spring-servlet.xml
webapp
—WEB-INF
—web.xml

application-web.xml

1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<import resource="classpath*:application-org.xml" />
<import resource="classpath*:application-auth.xml" />
<import resource="classpath*:application-flow.xml" />
</beans>

spring-servlet.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 扫描controller(controller层注入) -->
<context:component-scan base-package="com.jaryoung.oa.web.controller"/>

<!-- 启动注解支持 -->
<mvc:annotation-driven/>

<!-- 静态资源 -->
<mvc:resources location="/WEB-INF/js/" mapping="/js/**"/>
<mvc:resources location="/WEB-INF/css/" mapping="/css/**"/>
<mvc:resources location="/WEB-INF/image/" mapping="/image/**"/>

<!-- 视图解析器 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>

web.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<display-name>Archetype Created Web Application</display-name>

<!-- Spring配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:application-web.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Spring MVC -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

基于surefire插件运行单元测试以及输出覆盖率报告

surefire 会 跟 Junit 单元测试测试很好的结合

可选项

  1. 跳过所有单元测试-不推荐

  2. 跳过某些单元测试-不推荐

  3. 测试报告

    1. 单元测试覆盖率,代表单元测试是否会覆盖到代码的行数,或者方法的覆盖率

    2. 引用cobertura插件

      1
      2
      3
      4
      5
      <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>cobertura-maven-plugin</artifactId>
      <version>2.7</version>
      </plugin>
    3. 执行mvn cobertura:cobertura 命令

    4. 查看target/site/index.html报告

基于jetty插件在本地启动web服务进行功能测试

  1. 项目配置jetty本地启动

    1
    2
    3
    4
    5
    6
    7
    8
    <plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.4.37.v20210219</version>
    <configuration>
    <scanIntervalSeconds>10</scanIntervalSeconds>
    </configuration>
    </plugin>
  2. 配置setting文件

    1
    2
    3
    4
    5
    6
    7
    <pluginGroups>
    <!-- pluginGroup
    | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
    <pluginGroup>org.eclipse.jetty</pluginGroup>
    </pluginGroups>
  3. 在oa-web项目下执行mvn jetty:run

基于cargo对web服务进行自动化部署

  1. 第一步docker安装tomcat镜像

  2. 启动 tomcat 镜像,docker run -d --name tomcat -p 8888:8080

  3. 复制配置

    1
    2
    3
    4
    docker cp [contain id]:/usr/local/tomcat/webapps.dist .
    mv webapps.dist webapps
    docker cp [contain id]:/usr/local/tomcat/conf .
    docker cp [contain id]:/usr/local/tomcat/logs .
  4. 以挂载的方式启动tomcat
    docker run -d --name tomcat -p 8888:8080 -v $PWD/conf/:/usr/local/tomcat/conf -v $PWD/webapps/:/usr/local/tomcat/webapps -v $PWD/logs/:/usr/local/tomcat/logs tomcat:latest

  5. 修改配置tomcat-users.xmlwebapps/manager/META-INF/context.xml

    1
    2
    3
    4
    5
    tomcat-users.xml
    <role rolename="tomcat"/>
    <role rolename="manager-gui"/>
    <role rolename="manager-script"/>
    <user username="admin" password="admin" roles="tomcat,manager-gui,manager-script"/>
    1
    2
    3
    4
    5
    6
    7
    webapps/manager/META-INF/context.xml  
    <!-- 注释掉访问地址限制 -->
    <Context antiResourceLocking="false" privileged="true" >
    <!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"
    allow="\d+\.\d+\.\d" /> -->
    <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
    </Context>
  6. mvn clean package,打成war

  7. mvn clean verify org.codehaus.cargo:cargo-maven3-plugin:deploy,使用cargo插件部署

  8. 访问接口

基于资源过滤+profile功能自动适配各个发布环境

  1. 配置pom文件夹增加 profiles配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    <profiles>
    <profile>
    <id>dev</id>
    <activation>
    <activeByDefault>true</activeByDefault>
    </activation>
    <properties>
    <jdbc.driverClassName>com.mysql.jdbc.Driver</jdbc.driverClassName>
    <jdbc.url>jdbc:mysql://localhost:3306/oa</jdbc.url>
    <jdbc.username>root</jdbc.username>
    <jdbc.password>123456</jdbc.password>
    </properties>
    </profile>
    <profile>
    <id>test</id>
    <properties>
    <jdbc.driverClassName>com.mysql.jdbc.Driver</jdbc.driverClassName>
    <jdbc.url>jdbc:mysql://test:3306/oa</jdbc.url>
    <jdbc.username>root</jdbc.username>
    <jdbc.password>123456</jdbc.password>
    </properties>
    </profile>
    <profile>
    <id>prod</id>
    <properties>
    <jdbc.driverClassName>com.mysql.jdbc.Driver</jdbc.driverClassName>
    <jdbc.url>jdbc:mysql://prod:3306/oa</jdbc.url>
    <jdbc.username>root</jdbc.username>
    <jdbc.password>123456</jdbc.password>
    </properties>
    </profile>
    </profiles>
  2. mvn package -Pdev,看看打出来jar配置是否正确

  3. mvn package -Ptest -DskipTests=true,同上

  4. 配置 cargo 多环境配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    						<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven3-plugin</artifactId>
    <version>1.9.0</version>
    <configuration>
    <container>
    <containerId>tomcat9x</containerId>
    <type>remote</type>
    </container>

    <configuration>
    <type>runtime</type>
    <properties>
    <cargo.hostname>${cargo.hostname}</cargo.hostname>
    <cargo.servlet.port>${cargo.servlet.port}</cargo.servlet.port>
    <cargo.tomcat.manager.url>${cargo.tomcat.manager.url}</cargo.tomcat.manager.url>
    <cargo.remote.username>${cargo.remote.username}</cargo.remote.username>
    <cargo.remote.password>${cargo.remote.password}</cargo.remote.password>
    </properties>
    </configuration>

    <deployer>
    <type>remote</type>
    </deployer>

    <deployables>
    <deployable>
    <groupId>${project.groupId}</groupId>
    <artifactId>${project.artifactId}</artifactId>
    <type>${project.packaging}</type>
    </deployable>
    </deployables>
    </configuration>
    </plugin>

    <profiles>
    <profile>
    <id>dev</id>
    <activation>
    <activeByDefault>true</activeByDefault>
    </activation>
    <properties>
    <jdbc.driverClassName>com.mysql.jdbc.Driver</jdbc.driverClassName>
    <jdbc.url>jdbc:mysql://localhost:3306/oa</jdbc.url>
    <jdbc.username>root</jdbc.username>
    <jdbc.password>123456</jdbc.password>

    <cargo.hostname>localhost</cargo.hostname>
    <cargo.servlet.port>8888</cargo.servlet.port>
    <cargo.tomcat.manager.url>http://localhost:8888/manager</cargo.tomcat.manager.url>
    <cargo.remote.username>admin</cargo.remote.username>
    <cargo.remote.password>admin</cargo.remote.password>
    </properties>
    </profile>
    <profile>
    <id>test</id>
    <properties>
    <jdbc.driverClassName>com.mysql.jdbc.Driver</jdbc.driverClassName>
    <jdbc.url>jdbc:mysql://test:3306/oa</jdbc.url>
    <jdbc.username>root</jdbc.username>
    <jdbc.password>123456</jdbc.password>

    <cargo.hostname>localhost</cargo.hostname>
    <cargo.servlet.port>8888</cargo.servlet.port>
    <cargo.tomcat.manager.url>http://test:8888/manager</cargo.tomcat.manager.url>
    <cargo.remote.username>test</cargo.remote.username>
    <cargo.remote.password>test</cargo.remote.password>
    </properties>
    </profile>
    <profile>
    <id>prod</id>
    <properties>
    <jdbc.driverClassName>com.mysql.jdbc.Driver</jdbc.driverClassName>
    <jdbc.url>jdbc:mysql://prod:3306/oa</jdbc.url>
    <jdbc.username>root</jdbc.username>
    <jdbc.password>123456</jdbc.password>

    <cargo.hostname>localhost</cargo.hostname>
    <cargo.servlet.port>8888</cargo.servlet.port>
    <cargo.tomcat.manager.url>http://prod:8888/manager</cargo.tomcat.manager.url>
    <cargo.remote.username>prod</cargo.remote.username>
    <cargo.remote.password>prod</cargo.remote.password>
    </properties>
    </profile>
    </profiles>
  5. mvn clean verify org.codehaus.cargo:cargo-maven3-plugin:deploy -Pdev -DskipTests=true

  6. mvn clean verify org.codehaus.cargo:cargo-maven3-plugin:deploy -Ptest -DskipTests=true

  7. 进行资源文件的多环境配置

%E9%87%8D%E6%96%B0%E8%AE%A4%E8%AF%86maven%2024fba34a5ee5462cbca9db8b86fe4619/Untitled%2013.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
公共资源配置,非profiles.build.resources中resrouce的配置					
<resource>
<directory>src/main/profiles/${env}</directory>
<includes>
<include>/**</include>
</includes>
<filtering>true</filtering>
</resource>
profiles的配置
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<jdbc.driverClassName>com.mysql.jdbc.Driver</jdbc.driverClassName>
<jdbc.url>jdbc:mysql://localhost:3306/oa</jdbc.url>
<jdbc.username>root</jdbc.username>
<jdbc.password>123456</jdbc.password>
<env>dev</env>
</properties>
</profile>

上面主要是增加一个propertie → <env>dev</env>

版本管理和版本控制的区别

maven的版本管理的目的,是管理好maven的对应的版本。
git目的是做好版本控制,也就是给我们能鼓回滚某一个commit的时刻。

互联网公司最佳实践之如何进行版本管理

开发中的版本:x.x.x-SNASHOPT
发布的版本:x.x.x
举个例子
开发中:1.0.1-SNASHOPT → 1.0.2-SNASHOPT(修复某个bug)→1.0.2(发布版本)
重大升级:2.0.1-SNASHOPT → 2.0.2-SNASHOPT(修复某个bug)→2.0.1(发布版本)
第一位,一般相对稳定除非大的变更,第二位,用于次重大变更,第三位用于日常变更

为项目创建统一的工程骨架

Maven - Guide to Creating Archetypes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
archetype
|-- pom.xml
`-- src
`-- main
`-- resources
|-- META-INF
| `-- maven
| `--archetype-metadata.xml
`-- archetype-resources
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- App.java
`-- test
`-- java
`-- AppTest.java

pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?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>

<groupId>com.jaryoung.oa</groupId>
<artifactId>archetypes-oa</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Releases</name>
<url>http://localhost:8090/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Snapshot</name>
<url>http://localhost:8090/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>

<build>
<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>3.1.1</version>
</extension>
</extensions>
</build>

</project>

archetype-metadata.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<archetype-descriptor
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0 https://maven.apache.org/xsd/archetype-descriptor-1.1.0.xsd"
name="quickstart">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
</fileSet>
<fileSet filtered="true" packaged="false" encoding="UTF-8">
<directory>src/main/resources</directory>
</fileSet>
<fileSet filtered="true" packaged="false" encoding="UTF-8">
<directory>src/main/profiles</directory>
</fileSet>

<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/test/java</directory>
</fileSet>

<fileSet filtered="false" packaged="false" encoding="UTF-8">
<directory>/.gitignore</directory>
</fileSet>
</fileSets>

<requiredProperties>
<!-- package 默认会取自 groupId -->
<requiredProperty key="groupId">
<defaultValue>com.jaryoung.oa</defaultValue>
</requiredProperty>
<requiredProperty key="artifactId">
</requiredProperty>

<requiredProperty key="version">
<defaultValue>1.0.0-SNAPSHOT</defaultValue>
</requiredProperty>
</requiredProperties>

</archetype-descriptor>

mybatis源码中的pom.xml解释

1
2021-02-28 17:08:54,847 [main] INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from URL [file:/Users/jaryoung/project/study/maven/oa-parent/oa-web/target/classes/application-web.xml]

课程总结

%E9%87%8D%E6%96%B0%E8%AE%A4%E8%AF%86maven%2024fba34a5ee5462cbca9db8b86fe4619/Untitled%2014.png

遇到的问题及解决思路

多模块进行聚合的时候,发现部分项目的mamper没有被扫描到。
解决思路,查询日志看那些mapper没有被扫描到
Parsed mapper file:’URL [jar:file:/**/oa-org-1.0-SNAPSHOT.jar!/mapper/AuthorizationDao.xml]’

解决思路:

  1. 单个项目构建跑单元测试通过,表明配置每个项目的配置是ok
  2. 调试源码看到只有oa-auth的mapper被扫描到了,其实通过启动日志也能看到扫描那些mapper
  3. 发现<property name="mapperLocations" value="classpath:mapper/*.xml"/>
  4. 问题分析,上面的配置导致多模块聚合的时候,只扫描了oa-auth下面classpath下面的mapper的文件
  5. 修改<property name="mapperLocations" value="classpath*:mapper/*.xml"/>问题解决
  6. spring配置文件中application-xx.xml多个一致的property key配置的时候,主要覆盖的内容喔。

引出问题 classpath: vs classpath*:

Difference between Classpath: & Classpath: in Spring

application-org.xml

1
2
3
4
5
6
<!-- 配置mybatis sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath*:mapper/*.xml"/>
<property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>

application-flow.xml

1
2
3
4
5
6
<!-- 配置mybatis sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath*:mapper/*.xml"/>
<property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>

application-auth.xml

1
2
3
4
5
6
<!-- 配置mybatis sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
<property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>
1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<import resource="classpath*:application-org.xml" />
<import resource="classpath*:application-flow.xml" />
<import resource="classpath*:application-auth.xml" />
</beans>

properties 中 如果名称一样,值不一样的话,排在下面的配置,会覆盖上面的配置

日志分析

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2021-02-28 17:08:54,847 [main] INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from URL [file:/Users/jaryoung/project/study/maven/oa-parent/oa-web/target/classes/application-web.xml]

2021-02-28 17:08:54,976 [main] INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from URL [file:/Users/jaryoung/project/study/maven/oa-parent/oa-org/target/classes/application-org.xml]

2021-02-28 17:08:55,147 [main] INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from URL [file:/Users/jaryoung/project/study/maven/oa-parent/oa-flow/target/classes/application-flow.xml]

2021-02-28 17:08:55,192 [main] INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from URL [file:/Users/jaryoung/project/study/maven/oa-parent/oa-auth/target/classes/application-auth.xml]

2021-02-28 17:08:55,243 [main] INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from URL [file:/Users/jaryoung/project/study/maven/oa-parent/oa-web/target/classes/spring-servlet.xml]

2021-02-28 17:08:55,364 [main] INFO [org.springframework.web.context.support.GenericWebApplicationContext] - Refreshing org.springframework.web.context.support.GenericWebApplicationContext@4c583ecf: startup date [Sun Feb 28 17:08:55 CST 2021]; root of context hierarchy

2021-02-28 17:19:59,375 [main] DEBUG [org.springframework.core.io.support.PathMatchingResourcePatternResolver] - Looking for matching resources in directory tree [/Users/jaryoung/project/study/maven/oa-parent/oa-org/target/classes/mapper]
2021-02-28 17:19:59,375 [main] DEBUG [org.springframework.core.io.support.PathMatchingResourcePatternResolver] - Searching directory [/Users/jaryoung/project/study/maven/oa-parent/oa-org/target/classes/mapper] for files matching pattern [/Users/jaryoung/project/study/maven/oa-parent/oa-org/target/classes/mapper/*.xml]
2021-02-28 17:20:02,090 [main] DEBUG [org.springframework.core.io.support.PathMatchingResourcePatternResolver] - Resolved location pattern [classpath:mapper/*.xml] to resources [file [/Users/jaryoung/project/study/maven/oa-parent/oa-org/target/classes/mapper/EmployeeDao.xml]]
2021-02-28 17:20:02,094 [main] DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Invoking afterPropertiesSet() on bean with name 'sqlSessionFactory'
如果有不对的地方,及时指出,我会继续努力。
稳食艰难啊,老细。(中文翻译:原创不易,您的支持将鼓励我继续创作!)
0%