通过示例项目,我能够解决编译问题。方法中有2个例外
com.SomeService#run。您的module-
info.java中缺少模块,一旦添加这些模块,代码便会编译。
requires dropwizard.jersey;requires dropwizard.jetty;
JerseyEnvironment来自
io.dropwizard:dropwizard-jersey:1.1.0
ServletEnvironment来自
io.dropwizard:dropwizard-jetty:1.1.0
由于它们是不同的jar,因此它们导出不同的模块。因此,需要明确添加需求。您的代码在没有module-
info.java的情况下可以正常工作,因为那时不使用模块系统。
我通过执行以下注释中提到的方法找到了解决方法:
@Overridepublic void run(SomeServiceConfig config, Environment environment) throws Exception { Injector injector = Guice.createInjector(new SomeServiceModule()); // Fix: Extract to variable to find Type of jersey and then find the module to add under requires JerseyEnvironment jersey = environment.jersey(); jersey.register(injector.getInstance(SomeResource.class)); // Fix 2: Same method as Fix 1 ServletEnvironment servlets = environment.servlets(); servlets.addFilter("Some-Filter", SomeFilter.class);}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)