更新时间:2021-01-07 09:38
本文主要对 SOFABoot Web 工程 和 Core 工程中的配置文件 pom.xml 进行说明。2 个工程在配置上的区别,主要是<module>
内容的不同。
Web 工程完整版 pom.xml
配置,请参考 完整版 pom.xml。下文将就 SOFABoot Web 工程 pom.xml 中的重要标签进行详细介绍。
请移步版本说明,查看最新的 SOFABoot 版本,在工程根目录下的主 pom.xml 中,修改下图所示例项的版本号:
在 <project>
标签中,所声明的工程坐标,包括以下内容,可根据工程需要,进行修改:
com.alipay.sofa
。了解这些元素的具体含义,可参见 Apache Maven 官方文档(英文)。
在 <dependencies>
标签中,声明了工程相关的所有依赖,说明如下:
工程原型默认生成 app/endpoint
和 app/web
两个模块(module):
<modules>
<module>app/endpoint</module>
<module>app/web</module>
</modules>
endpoint
模块是 SOFAREST 的服务模块,对外提供 SOFAREST 服务。SOFABoot Web 工程的 app/endpoint
模块中,默认添加了 SOFAREST 的期依赖。
```
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>rest-enterprise-sofa-boot-starter</artifactId>
</dependency>
```
SOFABoot 使用一系列的 {XXXXXX}-sofa-boot-starter
来统一管理中间件的依赖。例如,您需要新增对 RPC 中间件的依赖,可以在 pom.xml
中添加以下配置:
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>rpc-enterprise-sofa-boot-starter</artifactId>
</dependency>
web
模块是启动模块,包含 main
函数后可以直接运行,同时将全局的配置文件以及静态资源等放在这个模块下。
SOFABoot Web 工程在 web 模块中配置 构建(build),使用 spring-boot-maven-plugin 作为构建工具并在工程根目录的 target
下生成一个 fat JAR(.jar)包。该 fat JAR 包是一个可部署单元,有本地和云端 2 种部署方式:
java -jar
命令启动该 .jar
包;build
标签示例如下:
<build>
<plugins>
<!-- http://docs.spring.io/spring-boot/docs/current/maven-plugin/usage.html -->
<plugin>
<groupId>org.springframework.boot</groupId>
<!-- http://docs.spring.io/spring-boot/docs/current/maven-plugin/usage.html -->
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.4.2.RELEASE</version>
<configuration>
<!-- 可部署的 fat JAR 打包在工程的根目录的 target 下面 -->
<outputDirectory>../../target</outputDirectory>
<classifier>executable</classifier>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Core 工程完整版 pom.xml
配置,请参考完整版 pom.xml。下文将就 SOFABoot Core 工程 pom.xml 中的重要标签进行详细介绍。
请移步版本说明,查看最新的 SOFABoot 版本,在工程根目录下的主 pom.xml 中,修改下图所示例项的版本号:
请您参考上文 Web 工程中的相关说明。
在 <dependencies>
标签中,声明了工程相关的所有依赖,说明如下:
工程原型默认生成 APPNAME-facade
和 APPNAME-service
两个模块(module):
<modules>
<module>APPNAME-facade</module>
<module>APPNAME-service</module>
</modules>
facade
模块用于定义服务的接口,同时在使用 RPC 中间件时方便将这个模块打包的 JAR 分发给服务的调用方。
service
模块包含的配置信息包括 全局配置、应用的日志配置文件 以及 技术栈相关的配置信息。service
模块引入 facade
模块和 RPC 中间件需要的所有依赖。以下是 service
模块的 pom.xml
:
<!-- facade 依赖 -->
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>APPNAME-facade</artifactId>
</dependency>
<!-- 引入了 RPC 中间件需要的所有依赖 -->
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>rpc-enterprise-sofa-boot-starter</artifactId>
</dependency>
关于打包部署方式,请您参考上文 Web 工程中 打包部署说明。
在文档使用中是否遇到以下问题
更多建议
匿名提交