Skip to content

Commit 782b92e

Browse files
authored
Update 80.5 Use a Spring Boot application as a dependency.md
1 parent 32aab96 commit 782b92e

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed
Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,28 @@
1-
###80.5 Use a Spring Boot application as a dependency
1+
###80.5 将Spring Boot应用作为依赖
2+
3+
跟war包一样,Spring Boot应用不是用来作为依赖的。如果你的应用包含需要跟其他项目共享的类,最好的方式是将代码放到单独的模块,然后其他项目及你的应用都可以依赖该模块。
4+
5+
如果不能按照上述推荐的方式重新组织代码,你需要配置Spring Boot的Maven和Gradle插件去产生一个单独的artifact,以适合于作为依赖。可执行存档不能用于依赖,因为[可执行jar格式](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#executable-jar-jar-file-structure)将应用class打包到`BOOT-INF/classes`,也就意味着可执行jar用于依赖时会找不到。
6+
7+
为了产生两个artifacts(一个用于依赖,一个用于可执行jar),你需要指定classifier。classifier用于可执行存档的name,默认存档用于依赖。
8+
9+
可以使用以下配置Maven中classifier的`exec`
10+
```xml
11+
<build>
12+
<plugins>
13+
<plugin>
14+
<groupId>org.springframework.boot</groupId>
15+
<artifactId>spring-boot-maven-plugin</artifactId>
16+
<configuration>
17+
<classifier>exec</classifier>
18+
</configuration>
19+
</plugin>
20+
</plugins>
21+
</build>
22+
```
23+
使用Gradle可以添加以下配置:
24+
```gradle
25+
bootRepackage {
26+
classifier = 'exec'
27+
}
28+
```

0 commit comments

Comments
 (0)