I have two projects, server and client.
The server has the Jersey and Guice, the client has Wicket and Guice (Inject
OK)
I'm trying to expose my web service to be consumed by wicket
The big problem is that server-side Guice does not work.
When I call the web service it returns java.lang.NullPointerException
at br.impa.apps.eventos.ws.EventoWS.list (EventoWS.java: 34)
Line 34 is: return eventoService.list ();
eventoService should be injected by Guice but is not.
Someone tell me what's going on?
*-----------------------------------*
* Gabriel Cardelli
** Software Developer
** **gabrcardelli.appspot.com*
*
-----------------------------------
*
*
*
2011/6/20 Mischa Dasberg <[email protected]>
> Hi Gabriel,
>
> Try adding the following in your Module:
>
> bind(EventoWS.class);
>
> That should work.
>
> Regards,
>
> Mischa
>
> On Mon, Jun 20, 2011 at 1:56 AM, Gabriel Cardelli <
> [email protected]> wrote:
>
>> I'm trying to set up a project using Google Guice 3.0 JAX-RS and Jersey 1.7
>> for the server side however google guice is not injecting any class.
>>
>> *web.xml*
>> <?xml version="1.0" encoding="ISO-8859-1"?>
>> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="
>> http://www.w3.org/2001/XMLSchema-instance"
>> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
>> http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
>> version="2.4">
>>
>> <display-name>Institucional Eventos - Wicket Application</display-name>
>>
>> <listener>
>>
>> <listener-class>br.impa.apps.eventos.config.servlet.listener.ImpaGuiceServletContextListener</listener-class>
>> </listener>
>>
>> <servlet>
>> <servlet-name>Jersey REST Service</servlet-name>
>>
>> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
>> <init-param>
>> <param-name>com.sun.jersey.config.property.packages</param-name>
>> <param-value>br.impa.apps.eventos.ws</param-value>
>> </init-param>
>> <load-on-startup>1</load-on-startup>
>> </servlet>
>> <servlet-mapping>
>> <servlet-name>Jersey REST Service</servlet-name>
>> <url-pattern>/ws/*</url-pattern>
>> </servlet-mapping>
>>
>> </web-app>
>>
>> *ImpaGuiceServletContextListener*
>> *
>> *
>> public class ImpaGuiceServletContextListener extends
>> GuiceServletContextListener{
>>
>> private final transient Logger log =
>> Logger.getLogger(ImpaGuiceServletContextListener.class);
>> @Override
>> protected Injector getInjector() {
>> log.info("getInject() - Executando");
>> return Guice.createInjector(new EventosModule());
>>
>> }
>> }
>>
>> *EventosModule*
>> public class EventosModule extends ServletModule {
>>
>> private final transient Logger log =
>> Logger.getLogger(EventosModule.class.getName());
>> public final static String PERSISTENCE_UNIT = "eventosImpa";
>>
>> public void configureServlets() {
>> log.info("Configurando Modulo - Eventos");
>> final Map<String, String> params = new HashMap<String, String>();
>> params.put("javax.ws.rs.Application",
>> "br.impa.apps.eventos.config.module.JerseyApp");
>> install(new JpaPersistModule(PERSISTENCE_UNIT));
>> filter("/*").through(PersistFilter.class);
>>
>> bind(EventoService.class).to(EventoServiceImpl.class).in(Singleton.class);
>> filter("/*").through(GuiceFilter.class);
>> log.info("Cofigurando Modulo JPA");
>> }
>>
>> }
>>
>> *Web Service Rest*
>> @Path("/evento")
>> @RequestScoped
>> public class EventoWS {
>>
>> private final transient Logger log = Logger.getLogger(EventoWS.class);
>> @Inject
>> private EventoService eventoService;
>> @GET
>> @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
>> public List<Evento> list() {
>> log.info("Executando método list()");
>> log.info("EventoService: " + eventoService );
>> return eventoService.list(null);
>> }
>>
>> public void setEventoService(EventoService eventoService) {
>> this.eventoService = eventoService;
>> }
>> }
>>
>>
>> When I try to run the web service
>> eventoService is null,
>> I am not able to understand why?
>>
>> thks all!
>>
>> *
>> Gabriel Cardelli
>> Software Developer
>>
>> *
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "google-guice" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/google-guice?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.