Dropwizard学习笔记(1)

作者: 麻辣阁 分类: Java 发布时间: 2019-01-22 22:45

安装 IDEA

这里假定用 IDEA环境开发, 并且使用 IDEA自带的 Maven.

安装完成后, 添加类似如下的maven/bin到系统环境变量,如:

C:\JetBrains\IntelliJ IDEA Community Edition 2018.3.4\plugins\maven\lib\maven3\bin

检查版本:

D:\>mvn -v
D:\
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: C:\JetBrains\IntelliJ IDEA Community Edition 2018.3.4\plugins\maven\lib\maven3\bin\..

编辑 C:\JetBrains\IntelliJ IDEA Community Edition 2018.3.4\plugins\maven\lib\maven3\conf\settings.xml, 添加阿里的中央仓库:

    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>       
    </mirror>

创建项目骨架

参考如下资料创建骨架, 这里指定了1.3.8版本:

  • [https://www.dropwizard.io/1.3.8/docs/getting-started.html](https://www.dropwizard.io/1.3.8/docs/getting-started.html
  • Dropwizard Archetypes
D:\>mvn archetype:generate -DarchetypeGroupId=io.dropwizard.archetypes -DarchetypeArtifactId=java-simple -DarchetypeVersion=1.3.8
Define value for property 'groupId': xyz.mylog
Define value for property 'artifactId': dropwizardTest
Define value for property 'version' 1.0-SNAPSHOT: :
Define value for property 'package' xyz.mylog: :
[INFO] Using property: description = null
Define value for property 'name': HelloWorld
  • maven中, groupId一般填写组织对应域名
  • artifactId 一般填项目名称, 这里会用来生成对应的项目文件夹名
  • 要注意的是name, make sure to use a camel case word such as HelloWorld as it is used to generate Configuration and Application classess such as HelloWorldConfiguration.java and HelloWorldApplication.java.

这样就生成了项目框架.

在IDEA中编辑项目

下载依赖包:

D:\>cd dropwizardTest
D:\dropwizardTest>mvn clean install

README.md 内容:

# HelloWorld

How to start the HelloWorld application
---

1. Run `mvn clean install` to build your application
1. Start application with `java -jar target/dropwizardTest-1.0-SNAPSHOT.jar server config.yml`
1. To check that your application is running enter url `http://localhost:8080`

Health Check
---

To see your applications health enter url `http://localhost:8081/healthcheck`

所以实际上, dropwizard 会占用两个端口, 如果报错提示端口占用了,可能只报其中一个端口, 要同时检查另一个端口.


发表评论

电子邮件地址不会被公开。 必填项已用*标注