我是 Dropwizard 的新手,我想做的是按照教程 ( http://dropwizard.codahale.com/manual/views/#manual-views ) 来实现简单的基于 freemarker 的视图。我完全按照它说的做了,但是当我启动我的应用程序并将浏览器导航到http://localhost:8080/user
码头时,我返回 404。
package com.example.views;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/user")
@Produces(MediaType.TEXT_HTML)
public class UserResource
{
@GET
public UserView getUser()
{
return new UserView();
}
}
package com.example.views;
import com.yammer.dropwizard.views.View;
public class UserView extends View {
public UserView() {
super("user.ftl");
}
}
package com.example.service;
import com.yammer.dropwizard.ConfiguredBundle;
import com.yammer.dropwizard.Service;
import com.yammer.dropwizard.config.Bootstrap;
import com.yammer.dropwizard.config.Environment;
import com.yammer.dropwizard.views.ViewBundle;
public class WebCoreApplication extends Service<WebCoreConfiguration> {
private final ConfiguredBundle[] bundles;
public WebCoreApplication(ConfiguredBundle...bundles) {
this.bundles = bundles;
}
@Override
public void initialize(Bootstrap<WebCoreConfiguration> bootstrap) {
for(ConfiguredBundle bundle : bundles) {
bootstrap.addBundle(bundle);
}
bootstrap.addBundle(new ViewBundle());
}
@Override
public void run(WebCoreConfiguration configuration, Environment environment) throws Exception {
}
}
我的 user.ftl 在 src/main/resources/com/example/views 文件夹中。
我做错了什么,我应该如何注册球衣资源以响应请求?