简介
Dropwizard是一款开发运维友好、高效、RESTful web服务的框架。Dropwizard将稳定、成熟的java生态系统中的库整合为一个简单的、轻量级的包,即跨越了库和框架之间的界限,使得我们可以更关注于业务本身。
Dropwizard 集成的三方包:Jersey,Jetty,Jackson,metrics,其他
HelloWorld
学习程序的常规操作,helloworld。了解大致的应用启动流程。
dropwizard-core
该模块是dropwizard的核心模块,掌握了这个模块,对dw的基本运行机制等大部分的常用功能基本就了解了。
core官方文档
Application
Application类是dw的核心类,使用dw的应用必须需要继承该类,比如helloworld.
Application的核心函数为run,在该部分会完成应用初始化和启动
    public void run(String... arguments) throws Exception {         //注意创建bootstrap对象时赋的其他对象,比如默认使用的ConfigurationSourceProvider为FileConfigurationSourceProvider         final Bootstrap<T> bootstrap = new Bootstrap<>(this);         //添加默认的command,只有check和server。         addDefaultCommands(bootstrap);         //调用app的init方法,在这里可以addBundle,addCommand,设置configuration的替换方法,由应用自身实现         initialize(bootstrap);         //注册metrics,为监控服务器做准备         bootstrap.registerMetrics();          //创建命令执行器,Cli类解析命令行输入参数并执行命令         final Cli cli = new Cli(new JarLocation(getClass()), bootstrap, System.out, System.err);         //根据输入参数执行command,比如利用server Command为应用启动HTTP 服务器         if (!cli.run(arguments)) {             // only exit if there's an error running the command             onFatalError();         }     }Configuration类
Configuration类是core的核心类之一,YAML配置文件的对象表示
Configuration主要功能实现在dropwizard-confiugration模块实现
dropwizard-confiugration模块的主要功能是加载、解析、绑定和验证配置文件。核心接口ConfigurationFactory
Bootstrap类
Bootstrap类是core模块的核心类之一,官方定位为application的预启动环境。我个人将其作用理解为完成application启动前的环境准备和初始化,比如添加Bundles、Commands或者注册Jackson modules,这样就能允许我们把一些自定义的类型加载到配置中。
其实,根据Bootstrap的构造器我们能大致看出类的功能,Bootstrap主要负责构造器里的对象的管理(get和set),然后提供addBundle和addCommand功能。
    public Bootstrap(Application<T> application) {         this.application = application;         //Jackson的主要类,用于Java对象和Json对象相互转换         this.objectMapper = Jackson.newObjectMapper();         //维护bundle的列表         this.configuredBundles = new ArrayList<>();         //维护command的列表         this.commands = new ArrayList<>();         //Validator负责配置文件解析后的验证功能         this.validatorFactory = Validators.newValidatorFactory();         //度量对象,用于@Timed等         this.metricRegistry = new MetricRegistry();         //配置文件的读取方式,具体见dropwizard-configuration模块         this.configurationSourceProvider = new FileConfigurationSourceProvider();         this.classLoader = Thread.currentThread().getContextClassLoader();         this.configurationFactoryFactory = new DefaultConfigurationFactoryFactory<>();         //HealCheck,负责应用状态检查,可以查看应用是否正在工作         this.healthCheckRegistry = new HealthCheckRegistry();     } .........     public void addCommand(ConfiguredCommand<T> command) {         commands.add(command);     } ......... //注意,init()添加bundle时进行了初始化     public void addBundle(ConfiguredBundle<? super T> bundle) {         bundle.initialize(this);         configuredBundles.add(bundle);     }Environment类
Environment类是dropwizard的应用环境。包含应用提供的所有的的 Resources, servlets, filters, Health Checks, Jersey providers, Managed Objects, Tasks, and Jersey properties。
Environment类的属性如下
    private final String name;     private final MetricRegistry metricRegistry;     private 
                    
                