I am trying to add transaction support to an existing webapp via spring transactions.
I recently changed my session factory class from LocalSessionFactoryBean to AnnotationSessionFactoryBean.
now I get the following error when the webapp starts:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txManager' defined in class path resource [context.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/apache/lucene/analysis/standard/StandardAnalyzer
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
so the root cause it
nested exception is java.lang.NoClassDefFoundError: org/apache/lucene/analysis/standard/StandardAnalyzer
I don’t understand why now I need to include lucene in my webapp. I don’t plan to use it for search and it seems very wrong to me that this error occurs.
Without seeing the full strack trace, I can’t be sure, but my guess is that this has something to do with Hibernate Search, which uses Lucene under the hood.
The
AnnotationSessionFactoryBeanwill attempt to auto-detect the presense of Hibernate Search on the classpath, and will initialize it if it’s found. Dependening on your environment, it may get so far before failing to find Lucene.Have a grub around on your classpath, see if Hibernate Search is there, and see if you can remove it. Another option is to set the
hibernate.search.autoregister_listenershibernate property tofalse, which should explicitly disable the registration of Hibernate Search.