我正在使用 Spring 3.2.3.RELEASE、Google Guice 3.0、guice-repository 2.1.0、guice-servlet 3.0 和 Hibernate 3。
当我在 servlet 模块(web.xml)中安装 JpaRepository 时,出现运行时错误。
下面是源代码
public class JpaGuiceServletConfig extends GuiceServletContextListener {
@Override
protected Injector getInjector() {
return Guice.createInjector(new ServletModule(){
@Override
protected void configureServlets() {
this.install(new JpaRepositoryModule("ptol-persistence-unit") {
@Override
protected void bindRepositories(RepositoryBinder binder) {
binder.bind(CategoryRepository.class).to("ptol-persistence-unit");
}
});
//filter("/*").through(PersistFilter.class);
}
});
}
}
在 web.xml 中
<!-- Listener Configuration -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>phattuonline.common.base.JpaGuiceServletConfig</listener-class>
</listener>
我得到了错误:
Jul 10, 2013 4:37:05 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class phattuonline.common.base.JpaGuiceServletConfig
java.lang.NoSuchMethodError: org.springframework.transaction.annotation.AnnotationTransactionAttributeSource.<init>(Lorg/springframework/transaction/annotation/TransactionAnnotationParser;)V
at com.google.code.guice.repository.configuration.JpaRepositoryModule.createTransactionAttributeSource(JpaRepositoryModule.java:283)
at com.google.code.guice.repository.configuration.JpaRepositoryModule.configure(JpaRepositoryModule.java:170)
at com.google.inject.AbstractModule.configure(AbstractModule.java:59)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
at com.google.inject.AbstractModule.install(AbstractModule.java:118)
at phattuonline.common.base.JpaGuiceServletConfig$1.configureServlets(JpaGuiceServletConfig.java:19)
at com.google.inject.servlet.ServletModule.configure(ServletModule.java:53)
at com.google.inject.AbstractModule.configure(AbstractModule.java:59)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
at com.google.inject.spi.Elements.getElements(Elements.java:101)
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:133)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
at com.google.inject.Guice.createInjector(Guice.java:95)
at com.google.inject.Guice.createInjector(Guice.java:72)
at com.google.inject.Guice.createInjector(Guice.java:62)
at phattuonline.common.base.JpaGuiceServletConfig.getInjector(JpaGuiceServletConfig.java:16)
at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4765)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5260)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1525)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1515)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
你知道为什么会发生错误吗?交易有问题吗?
谢谢