基本上,我需要从Solr索引和查询数据。因此,首先,我尝试创建一个HttpSolrClient并面对该问题。在项目中添加的依赖项是:
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Edgware.SR5</spring-cloud.version>
<spring-kafka.version>1.3.8.RELEASE</spring-kafka.version>
<curator-test-version>2.12.0</curator-test-version>
<solr.version>7.5.0</solr.version>
<zk.version>3.4.10</zk.version>
<curator-version>4.0.0</curator-version>
<slf4j.version>1.7.7</slf4j.version>
<commons-lang3.version>3.5</commons-lang3.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20171018</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.8.2</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro-tools</artifactId>
<version>1.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro-compiler</artifactId>
<version>1.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.8.2</version>
</dependency>
<dependency>
<groupId>tech.allegro.schema.json2avro</groupId>
<artifactId>converter</artifactId>
<version>0.2.5</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>${solr.version}</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>${solr.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
</exclusion>
<exclusion>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-jetty9</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zk.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>${curator-version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-client</artifactId>
<version>${curator-version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
<version>${curator-test-version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.8.2</version>
<executions>
<execution>
<phase>none</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/java/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
运行Maven依赖树。 结果如下: mvn依赖项:tree | grep solr [INFO] +-org.apache.solr:solr-core:jar:7.5.0:compile [INFO] | +-org.apache.solr:solr-solrj:jar:7.5.0:compile
在存储库中,solr文件夹只有3个子文件夹。 1. solr-core,2. solr-parent,3. solr-solrj
尝试在调试模式下运行mvn。 mvnDebug全新安装-X 获取以下错误信息:
申请无法开始
说明:
尝试调用方法org.apache.solr.client.solrj.impl.HttpSolrClient。(Ljava / lang / String;)V,但该方法不存在。可从以下位置获得其类org.apache.solr.client.solrj.impl.HttpSolrClient。
jar:file:/Users/admin/.m2/repository/org/apache/solr/solr-solrj/7.5.0/solr-solrj-7.5.0.jar!/org/apache/solr/client/solrj/impl/HttpSolrClient.class
它是从以下位置加载的:
file:/Users/admin/.m2/repository/org/apache/solr/solr-solrj/7.5.0/solr-solrj-7.5.0.jar
操作:
更正应用程序的类路径,使其包含org.apache.solr.client.solrj.impl.HttpSolrClient的单个兼容版本
java.lang.IllegalStateException:无法加载ApplicationContext
原因:org.springframework.beans.factory.BeanCreationException:在类路径资源[org / springframework / boot / autoconfigure / solr / SolrAutoConfiguration.class]中创建名称为'solrClient'的bean时出错:通过工厂方法实例化Bean失败嵌套的异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.apache.solr.client.solrj.SolrClient]:工厂方法'solrClient'引发了异常;嵌套异常是java.lang.NoSuchMethodError:org.apache.solr.client.solrj.impl.HttpSolrClient。(Ljava / lang / String;)V
原因:org.springframework.beans.BeanInstantiationException:无法实例化[org.apache.solr.client.solrj.SolrClient]:工厂方法“ solrClient”抛出异常;嵌套异常是java.lang.NoSuchMethodError:org.apache.solr.client.solrj.impl.HttpSolrClient。(Ljava / lang / String;)V
由以下原因引起:java.lang.NoSuchMethodError:org.apache.solr.client.solrj.impl.HttpSolrClient。(Ljava / lang / String;)V
private HttpSolrClient solrClient;
public SolrJavaIntegration(String clientUrl) {
solrClient = new HttpSolrClient.Builder(clientUrl).build();
}
需要能够创建HttpSolrClient且没有任何问题,但是有问题。
答案 0 :(得分:0)
@SpringBootApplication(exclude = SolrAutoConfiguration.class)
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
禁用 SolrAutoConfiguration ,它可能会起作用