我正在尝试让 Guice 与 Struts、Hibernate 和 Quartz 调度程序一起工作。当我在 Tomcat 下部署我的应用程序时,我收到以下错误 -
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)
和代码
@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();
}
}
和 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>
谁能解释一下为什么这个应用程序崩溃了?我从某人那里继承了这段代码,但我不完全理解如何使用 Guice 进行注入。
我怀疑它与任何罐子或配置问题有关?
任何帮助是极大的赞赏,
谢谢