【发布时间】:2021-06-20 15:51:29
【问题描述】:
我发现jar只有三个通用文件,没有java文件,没有pom.xml文件。这个怎么运作?迷茫了,谢谢~
➜ jar -tf spring-boot-starter-data-redis-2.5.1.jar
META-INF/
META-INF/MANIFEST.MF
META-INF/LICENSE.txt
META-INF/NOTICE.txt
【问题讨论】:
我发现jar只有三个通用文件,没有java文件,没有pom.xml文件。这个怎么运作?迷茫了,谢谢~
➜ jar -tf spring-boot-starter-data-redis-2.5.1.jar
META-INF/
META-INF/MANIFEST.MF
META-INF/LICENSE.txt
META-INF/NOTICE.txt
【问题讨论】:
该包还包括一个 pom.xml,它定义了对其他项目的一些依赖项,例如 spring-data-redis、lettuce-core。这些依赖项将包含在您的构建过程中。 所以jar中没有实际的代码。
来自 spring-boot-starter-data-redis 2.0.6-RELEASE pom.xml 的示例:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.0.6.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.0.11.RELEASE</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>jcl-over-slf4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<version>5.0.5.RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
【讨论】:
正如 Luc 所说,如果您查看工件内部,您会看到一个 POM https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter-data-redis/2.5.2/spring-boot-starter-data-redis-2.5.2.pom,它带来了所有需要的依赖项。 Baeldung 有一篇关于初学者如何工作的好文章https://www.baeldung.com/spring-boot-starters
【讨论】:
代码在jar spring-boot-autoconfigure,在包org.springframework.boot.autoconfigure.data.redis,核心类是RedisAutoConfiguration
【讨论】: