tags:

views:

395

answers:

1

Hi Everyone,

I am trying to get Guice working with Struts, Hibernate and Quartz scheduler. When I deploy my application under Tomcat, I get the following error -

Nov 19, 2009 2:11:26 PM com.google.inject.struts2.GuiceObjectFactory buildBean INFO: Creating injector... com.google.inject.CreationException: Guice configuration errors:

1) Error at com.sample.common.entity.PersistenceServiceImpl.scheduler(PersistenceServiceImpl.java:22):
 Error while injecting at com.sample.cacher.UiAction.persistenceService(UiAction.java:27): Error while   injecting at com.sample.cacher.UiAction.persistenceService(UiAction.java:27): Binding to    org.quartz.Scheduler not found. No bindings to that type were found.

2) Error at com.sample.common.entity.PersistenceServiceImpl.session(PersistenceServiceImpl.java:22):
  Error while injecting at com.sample.cacher.UiAction.persistenceService(UiAction.java:27): Error while injecting at com.sample.cacher.UiAction.persistenceService(UiAction.java:27): Binding to org.hibernate.Session not found. No bindings to that type were found.

2 error[s]
    at com.google.inject.BinderImpl.createInjector(BinderImpl.java:277)
    at com.google.inject.Guice.createInjector(Guice.java:79)
    at com.google.inject.Guice.createInjector(Guice.java:53)
    at com.google.inject.Guice.createInjector(Guice.java:43)

And the code

@ImplementedBy(PersistenceServiceImpl.class)
public interface PersistenceService {
public void save(JobInformation dataObject);

public void remove(String jobName, String jobGroup, Class jobClass);

public List getActiveJobsFor(String userName, Class clazz) throws Exception;
}

public class PersistenceServiceImpl implements PersistenceService 
{  
  @Inject
   private Session session;
  @Inject
   private Scheduler scheduler;
   ...
}

package com.sample.common.entity;
public class ManagerModule extends AbstractModule {
protected void configure() {
    bind(Session.class)
            .toProvider(SessionProvider.class);
    bind(Scheduler.class)
            .toProvider(SchedulerProvider.class);
}
}

public class UiAction extends ActionSupport implements PrincipalAware
{
   @Inject
   private PersistenceService persistenceService;
   ....

    public String doSave() throws ParseException {


        persistenceService.save(data);

       return  doList();
      }
   }

And the web.xml

<filter>
    <filter-name>guice</filter-name>
    <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>guice</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

Can anyone please shed some light on why this application is crashing? I have inherited this code from someone and I don't fully understand how the injection is happening using Guice.

I am suspecting it has to do with any jars or configuration problems?

Any help is greatly appreciated,

Thanks

+1  A: 

I have inherited this code from someone and I don't fully understand how the injection is happening using Guice.

The details are described on the Guice wiki. But grossly simplified:

The GuiceFilter intercepts all calls and allows Guice to redirect them to Guice injected objects.

A user-built class extending GuiceServletContextListener returns a correctly configured Injecter that Guice will create your objects with. This is set in your XML file as a listener.

This uses normal Modules and one or more ServletModules. The latter allow for a code-based configuration of servlets, filters and listeners.


If was to guess at your problem then the GuiceServletContextListener does not contain a reference to ManagerModule.

mlk