寻找一个dropwizard示例,我发现:
https://github.com/codahale/dropwizard/tree/master/dropwizard-example
但我对一个更完整的例子感兴趣,至少:
三分之二将是一个开始,我将获得"接受".
我正在使用dropwizrd-migrations模块进行liquibase db重构.请参阅此处的指南:http://dropwizard.codahale.com/manual/migrations/
当我运行java -jar my_project.jar db migrate my_project.yml时
我收到以下错误:
错误[2013-09-11 20:53:43,089] liquibase:更改设置migrations.xml :: 11 ::我失败了.错误:执行SQL CREATE或REPLACE TRIGGER时出错add_current_date_to_my_table更新在my_table之前为每个行执行过程更改_update_time();:错误:语法错误在"TRIGGER"处或附近位置:19
以下是我的migrations.xml文件中的一些相关变更集:
<changeSet id="1" author="me">
<createProcedure>
CREATE OR REPLACE FUNCTION change_update_time() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
NEW.updated_at := CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$;
</createProcedure>
<rollback>
DROP FUNCTION change_update_time();
</rollback>
</changeSet>
<changeSet id="2" author="me">
<preConditions>
<not>
<tableExists tableName="my_table"/>
</not>
</preConditions>
<createTable tableName="my_table">
<column name="_id" type="integer" defaultValue="0">
<constraints nullable="false"/>
</column>
<column name="updated_at" type="timestamp without time zone" defaultValue="now()">
<constraints nullable="false"/>
</column>
</createTable> …Run Code Online (Sandbox Code Playgroud) 在我的情况下,我需要运行一些计划任务(例如每分钟)在DB中进行一些检查,如果需要,还需要一些子任务.这应该是没有DB健康检查!
DW文档说:
"应该注意,Environment有针对ExecutorService和ScheduledExecutorService实例的内置工厂方法.有关详细信息,请参阅LifecycleEnvironment#executorService和LifecycleEnvironment#scheduledExecutorService."
有谁知道如何在DW中实现这一点?试着玩DW代码的可能性,我发现了这个:
String nameFormat = "?What should this string contain?";
ScheduledExecutorServiceBuilder sesBuilder = environment.lifecycle().scheduledExecutorService(nameFormat);
ScheduledExecutorService ses = sesBuilder.build();
Runnable alarmTask = new AlarmTask();
ses.scheduleWithFixedDelay(alarmTask, 0, 5, TimeUnit.SECONDS);
Run Code Online (Sandbox Code Playgroud)
这是DW中正确的方法吗?BTW一个可运行的假人:
private static final class AlarmTask implements Runnable {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
@Override public void run() {
++fCount;
cal = Calendar.getInstance();
System.out.println(fCount + "x BEEP:" + dateFormat.format(cal.getTime()));
}
private int fCount;
}
Run Code Online (Sandbox Code Playgroud)
什么是初始名称的目的,是否在某处使用?希望有人能提供帮助.
我想为DropWizard提供几个yaml文件.其中一个包含敏感信息,一个包含非敏感信息.
你能指点我的任何文档或例子如何在DropWizard中有多个配置吗?
我正在使用angularjs应用程序前端开发一个应用程序作为后端dropwizard.我打算使用Nginx作为后端dropwizard服务器的网关,并作为资产服务器(图像和angularjs应用程序).
我的问题是什么是部署的最佳策略:
提前致谢,
我有一个项目,里面有多个模块.其中一个模块,比如说"main",就是我的服务类"MyService.class".Dropwizard有一个jar - dropwizard-core.我想在多个模块中使用这个jar,所以我想在父POM中保持它的依赖性.通过这样做,在运行我的dropwizard服务文件时,我遇到如下异常:
SLF4J: Class path contains multiple SLF4J bindings.<br>
SLF4J: Found binding in [jar:file:/home/username/.m2/repository/org/slf4j/slf4j-simple/1.7.12/slf4j-simple-1.7.12.jar!/org/slf4j/impl/StaticLoggerBinder.class]<br>
SLF4J: Found binding in [jar:file:/home/username/.m2/repository/ch/qos/logback/logback-classic/1.1.3/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]<br>
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.<br>
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]<br><br>
Exception in thread "main" java.lang.IllegalStateException: Unable to acquire the logger context
at io.dropwizard.logging.LoggingUtil.getLoggerContext(LoggingUtil.java:46)
at io.dropwizard.logging.BootstrapLogging.bootstrap(BootstrapLogging.java:45)
at io.dropwizard.logging.BootstrapLogging.bootstrap(BootstrapLogging.java:34)
at io.dropwizard.Application.<init>(Application.java:24)
at my.project.package.MyService.<init>(MyService.java:31)
at my.project.package.MyService.main(MyService.java:38)
Run Code Online (Sandbox Code Playgroud)
如果我将依赖项放在"main"模块的POM中,那么这个项目运行得很好.
Dropwizard与错误的记录器绑定,这就是这个异常背后的原因.但这种绑定发生在后台,我无法控制它.
我也在为这两个场景共享依赖树.
案例1:当dropwizard-core在子POM(主模块)中时:
my.groupId.myProject:myProject-main:jar:1.0-SNAPSHOT<br>
[INFO] +- io.dropwizard:dropwizard-core:jar:0.9.2:compile<br>
[INFO] | +- io.dropwizard:dropwizard-util:jar:0.9.2:compile<br>
[INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.0:compile<br>
[INFO] | | +- com.google.guava:guava:jar:18.0:compile<br>
[INFO] | …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用@Timed(http://metrics.dropwizard.io/3.1.0/apidocs/com/codahale/metrics/annotation/package-summary.html)等注释自动将指标发布到我的MetricRegistry .
这不是开箱即用的.在搜索问题时,我发现了Codahale Metrics:在普通Java中使用@Timed指标注释,其中提到了这个工作的唯一方法是使用aspectj.我将此添加到我的项目中,但仍未在MetricRegistry中看到我的指标.
这是我的pom文件.我添加了一个librato库,它加载了com.codahale.metrics:metrics-annotation.
<dependency>
<groupId>io.astefanutti.metrics.aspectj</groupId>
<artifactId>metrics-aspectj</artifactId>
<version>${metrics-aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.10</version>
</dependency>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>1.8</source>
<target>1.8</target>
<complianceLevel>1.8</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>true</verbose>
<aspectLibraries>
<aspectLibrary>
<groupId>io.astefanutti.metrics.aspectj</groupId>
<artifactId>metrics-aspectj</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<dependency>
<groupId>com.librato.metrics</groupId>
<artifactId>metrics-librato</artifactId>
<version>${metrics-librato.version}</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
这就是我尝试使用指标的方式
@Metrics(registry = "default") // this.metricRegistry is default
public class Foo {
@Inject
private MetricRegistry metricRegistry;
...
@Metered(name = "meterName")
public void bar() { …Run Code Online (Sandbox Code Playgroud) 我似乎无法配置Dropwizard使用ssl.
我创造了一把钥匙
openssl genrsa -des3 -out server.key 1024
Run Code Online (Sandbox Code Playgroud)
和证书
openssl req -new -key server.key -days 365 -out server.crt -x509
Run Code Online (Sandbox Code Playgroud)
并将其导入密钥库
keytool -import -file server.crt -keystore keystore.jks
Run Code Online (Sandbox Code Playgroud)
从那里开始,我将keystore.jks文件放在/ src/main/resources中,并放在了dropwizard的config.yaml文件旁边.
然后我尝试根据手册为dropwizard配置ssl:
http:
ssl:
keyStore: ./keystore.jks
keyStorePassword: ********
Run Code Online (Sandbox Code Playgroud)
但是,当我导航到登录页面时,它只能在没有https的情况下工作:并且在使用https时会出现错误107(net :: ERR_SSL_PROTOCOL_ERROR):SSL协议错误.
还有其他我缺少的步骤吗?
我一直试图找到一种在Google AppEngine上部署Dropwizard应用程序的方法,但到目前为止我还没有找到任何东西.
从这个问题(和答案)判断,我认为这可能是不可能的.我想确定一下,如果确实有效,我想学习如何.
有一个名为warwizard的dropwizard fork ,它显然可以让你从你的dropwizard代码创建war文件,但它已经超过6个月未被触及,这可能使得使用dropwizard文档很难.
要开始这项服务,我知道有人使用new MyService().run(args).怎么阻止它?
我需要启动和编程停止setUp(),并tearDown()在我的测试.