使用最新版本的 Solr 5.0 获取异常。降级到较早的版本(4.10.4),但该版本有其自身的问题(请参阅 Exception No.2)。
SolrConfig 类
public class SolrEmbeddedConfig {
@Autowired
private Environment environment;
@Bean
public EmbeddedSolrServerFactoryBean solrServerFactoryBean() {
EmbeddedSolrServerFactoryBean factory = new EmbeddedSolrServerFactoryBean();
factory.setSolrHome(environment.getRequiredProperty("embeded.solr.home"));
return factory;
}
@Bean
public SolrTemplate solrTemplate() throws Exception {
return new SolrTemplate(solrServerFactoryBean().getObject());
}
}
例外 1:使用最新版本的 Solr 5.0 引发
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accountTemplate' defined in file [/Users/foo/workspace/ProjectX/build/tmp/tomcatRunWar/work/Tomcat/localhost/com.projecta/WEB-INF/classes/com/projecta/core/api/impl/AccountTemplate.class]: Unsatisfied dependency expressed through constructor argument with index 1 of type [com.projecta.core.search.service.AutocompleteDocumentService]: : Error creating bean with name 'autocompleteDocumentService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.data.solr.core.SolrTemplate com.projecta.core.search.service.impl.AutocompleteDocumentServiceImpl.solrTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrTemplate' defined in class path resource [com/projecta/core/config/SolrEmbeddedConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.solr.core.SolrTemplate]: Factory method 'solrTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrServerFactoryBean' defined in class path resource [com/projecta/core/config/SolrEmbeddedConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.solr.server.support.EmbeddedSolrServerFactoryBean]: Factory method 'solrServerFactoryBean' threw exception; nested exception is java.lang.VerifyError: Bad return type
Exception Details:
Location:
org/springframework/data/solr/server/support/EmbeddedSolrServerFactory.getSolrServer(Ljava/lang/String;)Lorg/apache/solr/client/solrj/SolrServer; @4: areturn
Reason:
Type 'org/apache/solr/client/solrj/embedded/EmbeddedSolrServer' (current frame, stack[0]) is not assignable to 'org/apache/solr/client/solrj/SolrServer' (from method signature)
Current Frame:
bci: @4
flags: { }
locals: { 'org/springframework/data/solr/server/support/EmbeddedSolrServerFactory', 'java/lang/String' }
stack: { 'org/apache/solr/client/solrj/embedded/EmbeddedSolrServer' }
Bytecode:
0000000: 2ab6 0032 b0
; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'autocompleteDocumentService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.data.solr.core.SolrTemplate com.projecta.core.search.service.impl.AutocompleteDocumentServiceImpl.solrTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrTemplate' defined in class path resource [com/projecta/core/config/SolrEmbeddedConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.solr.core.SolrTemplate]: Factory method 'solrTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrServerFactoryBean' defined in class path resource [com/projecta/core/config/SolrEmbeddedConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.solr.server.support.EmbeddedSolrServerFactoryBean]: Factory method 'solrServerFactoryBean' threw exception; nested exception is java.lang.VerifyError: Bad return type
Exception Details:
Location:
org/springframework/data/solr/server/support/EmbeddedSolrServerFactory.getSolrServer(Ljava/lang/String;)Lorg/apache/solr/client/solrj/SolrServer; @4: areturn
Reason:
Type 'org/apache/solr/client/solrj/embedded/EmbeddedSolrServer' (current frame, stack[0]) is not assignable to 'org/apache/solr/client/solrj/SolrServer' (from method signature)
Current Frame:
bci: @4
flags: { }
locals: { 'org/springframework/data/solr/server/support/EmbeddedSolrServerFactory', 'java/lang/String' }
stack: { 'org/apache/solr/client/solrj/embedded/EmbeddedSolrServer' }
Bytecode:
0000000: 2ab6 0032 b0
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:185) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1139) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1042) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4937) [tomcat-embed-core-7.0.42.jar:7.0.42]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) [tomcat-embed-core-7.0.42.jar:7.0.42]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-7.0.42.jar:7.0.42]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) [tomcat-embed-core-7.0.42.jar:7.0.42]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) [tomcat-embed-core-7.0.42.jar:7.0.42]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0]
at java.lang.Thread.run(Thread.java:744) [na:1.8.0]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'autocompleteDocumentService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.data.solr.core.SolrTemplate com.projecta.core.search.service.impl.AutocompleteDocumentServiceImpl.solrTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrTemplate' defined in class path resource [com/projecta/core/config/SolrEmbeddedConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.solr.core.SolrTemplate]: Factory method 'solrTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrServerFactoryBean' defined in class path resource [com/projecta/core/config/SolrEmbeddedConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.solr.server.support.EmbeddedSolrServerFactoryBean]: Factory method 'solrServerFactoryBean' threw exception; nested exception is java.lang.VerifyError: Bad return type
Exception Details:
Location:
org/springframework/data/solr/server/support/EmbeddedSolrServerFactory.getSolrServer(Ljava/lang/String;)Lorg/apache/solr/client/solrj/SolrServer; @4: areturn
Reason:
Type 'org/apache/solr/client/solrj/embedded/EmbeddedSolrServer' (current frame, stack[0]) is not assignable to 'org/apache/solr/client/solrj/SolrServer' (from method signature)
Current Frame:
bci: @4
flags: { }
locals: { 'org/springframework/data/solr/server/support/EmbeddedSolrServerFactory', 'java/lang/String' }
stack: { 'org/apache/solr/client/solrj/embedded/EmbeddedSolrServer' }
Bytecode:
0000000: 2ab6 0032 b0
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
... 24 common frames omitted
异常 2:在 Solr 版本 4 降级时抛出。
21:03:12.818 [coreLoadExecutor-13-thread-1] ERROR org.apache.solr.core.CoreContainer - Error creating core [collection1]: Error opening new searcher
org.apache.solr.common.SolrException: Error opening new searcher
at org.apache.solr.core.SolrCore.<init>(SolrCore.java:881) ~[solr-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:43:07]
at org.apache.solr.core.SolrCore.<init>(SolrCore.java:654) ~[solr-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:43:07]
at org.apache.solr.core.CoreContainer.create(CoreContainer.java:491) ~[solr-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:43:07]
at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:255) [solr-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:43:07]
at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:249) [solr-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:43:07]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0]
at java.lang.Thread.run(Thread.java:744) [na:1.8.0]
Caused by: org.apache.solr.common.SolrException: Error opening new searcher
at org.apache.solr.core.SolrCore.openNewSearcher(SolrCore.java:1574) ~[solr-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:43:07]
at org.apache.solr.core.SolrCore.getSearcher(SolrCore.java:1686) ~[solr-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:43:07]
at org.apache.solr.core.SolrCore.<init>(SolrCore.java:853) ~[solr-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:43:07]
... 8 common frames omitted
Caused by: org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out: NativeFSLock@/Users/foo/workspace/ProjectX/solr_sandbox/collection1/data/index/write.lock
at org.apache.lucene.store.Lock.obtain(Lock.java:89) ~[lucene-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:38:43]
at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:755) ~[lucene-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:38:43]
at org.apache.solr.update.SolrIndexWriter.<init>(SolrIndexWriter.java:77) ~[solr-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:43:07]
at org.apache.solr.update.SolrIndexWriter.create(SolrIndexWriter.java:64) ~[solr-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:43:07]
at org.apache.solr.update.DefaultSolrCoreState.createMainIndexWriter(DefaultSolrCoreState.java:284) ~[solr-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:43:07]
at org.apache.solr.update.DefaultSolrCoreState.getIndexWriter(DefaultSolrCoreState.java:116) ~[solr-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:43:07]
at org.apache.solr.core.SolrCore.openNewSearcher(SolrCore.java:1537) ~[solr-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:43:07]
... 10 common frames omitted
21:03:14.655 [Finalizer] ERROR o.apache.solr.update.SolrIndexWriter - SolrIndexWriter was not closed prior to finalize(), indicates a bug -- POSSIBLE RESOURCE LEAK!!!
21:03:14.656 [Finalizer] ERROR o.apache.solr.update.SolrIndexWriter - Error closing IndexWriter
java.lang.NullPointerException: null
at org.apache.lucene.index.IndexWriter.doFlush(IndexWriter.java:3271) ~[lucene-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:38:43]
at org.apache.lucene.index.IndexWriter.flush(IndexWriter.java:3240) ~[lucene-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:38:43]
at org.apache.lucene.index.IndexWriter.shutdown(IndexWriter.java:910) ~[lucene-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:38:43]
at org.apache.lucene.index.IndexWriter.close(IndexWriter.java:987) ~[lucene-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:38:43]
at org.apache.lucene.index.IndexWriter.close(IndexWriter.java:957) ~[lucene-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:38:43]
at org.apache.solr.update.SolrIndexWriter.close(SolrIndexWriter.java:129) [solr-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:43:07]
at org.apache.solr.update.SolrIndexWriter.finalize(SolrIndexWriter.java:182) [solr-core-4.10.4.jar:4.10.4 1662817 - mike - 2015-02-27 16:43:07]
at java.lang.System$2.invokeFinalize(System.java:1267) [na:1.8.0]
at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:98) [na:1.8.0]
at java.lang.ref.Finalizer.access$100(Finalizer.java:34) [na:1.8.0]
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:210) [na:1.8.0]