2017-07-03 47 views
0

我尝试在我的弹簧启动应用程序中使用嵌入式solr服务器。我的配置是如下:Spring引导中的嵌入式solr服务器的类路径是什么?

package ch.*.rest.config; 
import java.io.IOException; 
import javax.xml.parsers.ParserConfigurationException; 
import org.apache.solr.client.solrj.SolrClient; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.data.solr.core.SolrOperations; 
import org.springframework.data.solr.core.SolrTemplate; 
import org.springframework.data.solr.repository.config.EnableSolrRepositories; 
import org.springframework.data.solr.server.support.EmbeddedSolrServerFactory; 
import org.xml.sax.SAXException; 

@Configuration 
@EnableSolrRepositories 
public class SolrContext { 

    @Bean 
    public SolrClient solrClient() throws ParserConfigurationException, IOException, SAXException { 
     EmbeddedSolrServerFactory factory = new EmbeddedSolrServerFactory("classpath:com/acme/solr"); 
     return factory.getSolrClient(); 
    } 
    @Bean 
    public SolrOperations solrTemplate() throws ParserConfigurationException, IOException, SAXException { 
     return new SolrTemplate(solrClient()); 
    } 
} 

随着gradle这个我包括以下依存

compile('org.apache.solr:solr-core:5.5.4') 
compile('org.springframework.data:spring-data-solr:2.1.4.RELEASE') 

应用程序的执行引发以下异常:

java.io.FileNotFoundException: class path resource [com/acme/solr] cannot be resolved to absolute file path because it does not exist 
> Buildiat org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:178) 
    at org.springframework.data.solr.server.support.EmbeddedSolrServerFactory.createCoreContainer(EmbeddedSolrServerFactory.java:110) 
    at org.springframework.data.solr.server.support.EmbeddedSolrServerFactory.initCoreContainer(EmbeddedSolrServerFactory.java:85) 
    at org.springframework.data.solr.server.support.EmbeddedSolrServerFactory.getCoreContainer(EmbeddedSolrServerFactory.java:193) 
    at org.springframework.data.solr.server.support.EmbeddedSolrServerFactory.getSolrClient(EmbeddedSolrServerFactory.java:80) 
    at ch.*.rest.config.SolrContext.solrClient(SolrContext.java:23) 
    at ch.*.rest.config.SolrContext$$EnhancerBySpringCGLIB$$ca87555f.CGLIB$solrClient$1(<generated>) 
    at ch.*.rest.config.SolrContext$$EnhancerBySpringCGLIB$$ca87555f$$FastClassBySpringCGLIB$$4c9fb49c.invoke(<generated>) 
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) 
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) 
    at ch.*.rest.config.SolrContext$$EnhancerBySpringCGLIB$$ca87555f.solrClient(<generated>) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1134) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1028) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) 
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1136) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1064) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1225) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:552) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) 
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1136) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1064) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1225) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:552) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) 
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) 
    at ch.*.rest.RestApplication.main(RestApplication.java:13) 

显然classpath中COM/ACME/solr未找到。我如何知道实际的课程路径是什么?

有关设置我跟着http://docs.spring.io/spring-data/solr/docs/2.1.x/reference/html/#solr.annotation

回答

0

从文档:

public EmbeddedSolrServerFactory(String solrHome) 
         throws ParserConfigurationException, 
          IOException, 
          SAXException 

参数

solrHome - 任何路径表达式有效使用与ResourceUtils指向solr.solr .home directory

这意味着你应该创建一个Solr H ome(并将solr配置放在那里)放在资源文件夹中,以便Gradle检索它。 然后,您应该将该路径传递给嵌入式Solr工厂。 希望它有帮助