本人第一篇博客,简单介绍一下Dropwizard框架的搭建,多多指教
本人都是从官方网站上学习到的,游客们可以参考以下连接学习:dropwizard Get-Start
下面开始一步一步的搭建环境:(Intellij14.1, JDK1.7)
1.1 添加依赖包
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>0.8.5</version>
</dependency>
后面统一都用0.8.5这个版本,用Intellij 工具maven可以自动导入这些依赖包
1.2 添加yml文件
笔者认为这个文件类似于普通web项目中的 .xml文件,对一些的项目配置之类的,可以去https://github.com/dropwizard/dropwizard/tree/master/dropwizard-example git-hub上的实例下载yml文件
以后会具体分析yml文件的各个关键字的具体用处,文件中很多东西是多出来的,必须要删除或者注释掉才能正常启动项目,此博客只简单介绍helloworld的项目(所有都是helloworld为第一个项目)
1.3 添加example.keystore 文件
同样的在上面那个地址去找,笔者只知道没有这个文件不能运行整个项目,具体作用不太清楚
2.1 写 Configuration 配置类
import io.dropwizard.Configuration;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.NotEmpty;
public class HelloWorldConfiguration extends Configuration {
@NotEmpty
private String template;
@NotEmpty
private String defaultName = "Stranger";
@JsonProperty
public String getTemplate() {
return template;
}
@JsonProperty
public void setTemplate(String template) {
this.template = template;
}
@JsonProperty
public String getDefaultName() {
return defaultName;
}
@JsonProperty
public void setDefaultName(String name) {
this.defaultName = name;
}
}
先简单的搭建起来,让项目能跑起来,具体的意义后面分析,包括其中的一些Annotation,有框架基础的一眼或许就能看懂,此处的template 和 defaultname 可以不要,但是和yml文件中的关键字是有关联的,如果要删