1
我使用Google Guice和Jersey(jax-rs)。以下方法拋出的JAXB異常(JAXB不能處理接口),如果我稱之爲:Google Guice和Jersey - JAXB無法處理接口錯誤
@POST
public void addUser(UserTO user){
}
用戶至一個接口,但在吉斯我把它綁定到實現:
bind(UserTO.class).to(DefaultUserTO.class);
我認爲Guice應該能夠處理這個問題。但也許東西在我的服務器啓動是錯誤的:
Injector injector =
Guice.createInjector(new GuiceServerModule(),
new JerseyServletModule() {
@Override
protected void configureServlets() {
// Route all requests through GuiceContainer
serve("/*").with(GuiceContainer.class);
}
});
// Create the server.
Server server = new Server(12345);
// Create a servlet context and add the jersey servlet.
ServletContextHandler sch = new ServletContextHandler(server, "/");
// Add our Guice listener that includes our bindings
sch.addEventListener(new GuiceServletConfig(injector));
// Then add GuiceFilter and configure the server to
// reroute all requests through this filter.
sch.addFilter(GuiceFilter.class, "/*", null);
// Must add DefaultServlet for embedded Jetty.
// Failing to do this will cause 404 errors.
// This is not needed if web.xml is used instead.
sch.addServlet(DefaultServlet.class, "/");
// Start the server
server.start();
// Wait until server shut down
server.join();
還是我只使用一個實現?