2017-07-03 4 views
0

J'essaie d'utiliser un serveur solr intégré dans mon application de démarrage au printemps. Ma configuration est la suivante:Quel est le chemin de classe pour le serveur solr intégré au démarrage de printemps?

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()); 
    } 
} 

Avec gradle j'inclure les dépendances suivantes

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

L'exécution de l'application renvoie l'exception suivante:

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) 

Il est évident que le classpath com/Acme/solr n'est pas trouvé. Comment puis-je savoir quel est le chemin réel de la classe?

Pour la configuration j'ai suivi http://docs.spring.io/spring-data/solr/docs/2.1.x/reference/html/#solr.annotation

Répondre

0

De la documentation:

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

Paramètres:

solrHome - Toute expression de chemin valide pour une utilisation avec ResourceUtils qui pointe vers le solr.solr .home directory

Cela signifie que vous devez créer un Solr H ome (et mettez les configurations de solr dedans là) dans le dossier de ressource pour gradle pour le ramasser. Ensuite, vous devez transmettre ce chemin à l'usine Solr intégrée. J'espère que ça aide