2011-10-07 2 views
1

저지에서 Google Guice (jax-rs)를 사용하고 있습니다.Google Guice and Jersey - JAXB에서 인터페이스를 처리 할 수 ​​없습니다. 오류

@POST 
public void addUser(UserTO user){ 
} 

UserTO가 인터페이스이지만, Guice에서 내가 구현에 바인딩 :

bind(UserTO.class).to(DefaultUserTO.class); 

I JAXB - 예외 (JAXB는 인터페이스를 처리 할 수 ​​없습니다) 내가 그것을 호출하면 방법을 던졌습니다 다음 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(); 

아니면 구현 만 사용해야합니까?

답변

2

구체적인 클래스를 사용해야합니다. Guice는 게임에서 여기 있지 않습니다. 사용자 인스턴스는 JAXB를 사용하여 Jersey에 의해 작성됩니다. Guice (또는 다른 DI 프레임 워크)가 할 수있는 것은 없습니다. 또한 UserTO에 대한 바인딩을 제거해야합니다. 일반적으로 DI 프레임 워크에서 데이터를 나타내는 객체를 관리하는 것은 좋지 않다고 말할 수 있습니다.

관련 문제