Help DropWizard for maintenance

Help! I tried for many hours, looking for everything I could think of. I have a problem that I would like to show static content instead of my application on my site. I changed the simple hello-world application:

public static void main(String[] args) throws Exception {
    Class.forName("org.sqlite.JDBC");
    new HelloWorldApplication().run(args);
}

@Override
public String getName() {
    return "hello-world";
}

@Override
public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) {
    bootstrap.addBundle(new AssetsBundle("/assets/*", "/"));
}

@Override
public void run(HelloWorldConfiguration configuration, Environment environment) {
    final HelloWorldResource resource = new HelloWorldResource(
            configuration.getTemplate(),
            configuration.getDefaultName()
        );
    final AddResource addResource = new AddResource();
    final DeleteResource deleteResource = new DeleteResource();
    final TemplateHealthCheck healthCheck = new TemplateHealthCheck(configuration.getTemplate());
    environment.healthChecks().register("template", healthCheck);
    environment.jersey().register(resource);
    environment.jersey().register(addResource);
    environment.jersey().register(deleteResource);
}

Here is my hello-world.yml:

server:
  type: simple
  applicationContextPath: /application/hello-world

template: Hello, %s!
defaultName: Stranger

I applied everything that DropWizard reports ( http://dropwizard.readthedocs.org/en/latest/manual/core.html#serving-assets ). But I just can't get to index.html

+4
source share
4 answers

I got it using the default constructor for the AssetsBundle () class.

With the default constructor, your resources will be searched in the directory along the path of the java class, for example.

/src/main/resources/assets/

ContextPath only/application

localhost:8080/application/assets/index.htm
+4

, , . Dropwizard, , : Jetty applicationContextPath SimpleServerFactory:103:

environment.getApplicationContext().setContextPath(applicationContextPath);

AssetBundle Context run() (AssetBundle:109):

environment.servlets().addServlet(assetsName, createServlet()).addMapping(uriPath + '*');

, applicationContextPath, YAML, ContextPath ( , )

- /:

applicationContextPath: /

bootstrap() run() AssetBundles :

bootstrap.addBundle(new AssetsBundle("/static", "/"));

environment.jersey().setUrlPattern("/application/*");
+5

Dropwizard 0.8.0 :

applicationContextPath: /
rootPath: /application

applicationContextPath - Jetty, rootPath - .

+1

, applicationContextPath. , AssetsBundle contextPath run, AssetServlet contextPath.

, AssetsBundle AssetsServlet run ( contextPath):

environment.getApplicationContext().setContextPath("/");
environment.servlets().addServlet("assets", new AssetServlet("/assets", "/", "index.html", StandardCharsets.UTF_8)).addMapping("/*");
0

All Articles