MicroProfile 示例项目教程
microprofile-samplesMicro Profile Samples项目地址:https://gitcode.com/gh_mirrors/mi/microprofile-samples
1. 项目的目录结构及介绍
MicroProfile 示例项目的目录结构如下:
microprofile-samples/
├── microprofile-sample-canonical/
│ ├── src/
│ │ ├── main/
│ │ │ ├── java/
│ │ │ └── resources/
│ │ └── test/
│ │ └── java/
│ ├── editorconfig
│ ├── gitattributes
│ ├── gitignore
│ ├── travis.yml
│ ├── LICENSE.txt
│ ├── NOTICE
│ ├── README.adoc
│ └── pom.xml
├── microprofile-sample-swagger/
│ ├── src/
│ │ ├── main/
│ │ │ ├── java/
│ │ │ └── resources/
│ │ └── test/
│ │ └── java/
│ ├── editorconfig
│ ├── gitattributes
│ ├── gitignore
│ ├── travis.yml
│ ├── LICENSE.txt
│ ├── NOTICE
│ ├── README.adoc
│ └── pom.xml
└── ...
目录结构介绍
microprofile-sample-canonical/
:最简单的示例,使用 JAX-RS 2.0 / CDI 1.2 / JSON-P 1.0。microprofile-sample-swagger/
:在microprofile-sample-canonical
基础上添加 Swagger。src/
:包含项目的源代码和测试代码。editorconfig
,gitattributes
,gitignore
:编辑器和版本控制配置文件。travis.yml
:Travis CI 配置文件。LICENSE.txt
,NOTICE
:项目许可证和声明文件。README.adoc
:项目说明文档。pom.xml
:Maven 项目配置文件。
2. 项目的启动文件介绍
启动文件
在 microprofile-sample-canonical
和 microprofile-sample-swagger
项目中,启动文件通常是 pom.xml
文件。通过 Maven 命令可以启动项目:
mvn clean package
启动方式
- Apache TomEE:打包成 WAR 文件并部署到应用服务器,访问
http://localhost:<portNumber>/msTopCDs
调用微服务。 - WildFly Swarm:使用以下 Maven 命令打包:
mvn clean package -Pwildfly-swarm
然后执行:
java -jar target/microprofile-sample-canonical-swarm.jar
访问 http://localhost:8081/msTopCDs
调用微服务。
3. 项目的配置文件介绍
配置文件
pom.xml
:Maven 项目配置文件,包含项目的依赖、插件和构建配置。editorconfig
:编辑器配置文件,用于统一代码格式。gitattributes
和gitignore
:Git 配置文件,用于指定文件属性和忽略文件。travis.yml
:Travis CI 配置文件,用于持续集成。
配置示例
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse</groupId>
<artifactId>microprofile-sample-canonical</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<!-- 依赖项 -->
</dependencies>
<build>
<plugins>
<!-- 插件配置 -->
</plugins>
</build>
</project>
editorconfig
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace
microprofile-samplesMicro Profile Samples项目地址:https://gitcode.com/gh_mirrors/mi/microprofile-samples