gpt4 book ai didi

java - Spring Solr 存储库

转载 作者:行者123 更新时间:2023-11-30 06:13:48 24 4
gpt4 key购买 nike

当我尝试从方法名称生成查询时出现错误。不过,我可以使用已经存在的其他内容。 findAll() ...等等...知道为什么吗?

请注意,我使用 HttpSolrClient.Builder对于 solrClient()而不是旧的方式(之前已折旧)

@Configuration
@EnableSolrRepositories
public class SolrConfig {
private static final String SOLR_CORE = "solr.core";
static final String SOLR_HOST = "solr.host";
@Resource
private Environment environment;
@Bean
public HttpSolrClient solrClient() throws Exception {
return new HttpSolrClient.Builder(environment.getProperty(SOLR_HOST)).build();
}

@Bean
public SolrOperations solrTemplate() throws Exception {
return new SolrTemplate(solrClient(),environment.getProperty(SOLR_CORE));
}
}

实体

@SolrDocument(solrCoreName = "Address")
public class AddressSolr {
@Id
@Field
private String id;
@Field
private String Street;
}

存储库

public interface SolrAddressRepository extends SolrCrudRepository<AddressSolr, String> {

List<AddressSolr> findByStreet(String name);
}

application.properties

solr.host=http://localhost:8085/solr
solr.core=Address

服务

@Service
public class SolrService {
public static SolrAddressRepository solrRepositoryX;

@Resource
private SolrAddressRepository solrAddressRepository;

@PostConstruct
private void init() {
solrRepositoryX = this.solrAddressRepository;
}
}

Solr schema.xml

field name="id" type="uuid" indexed="true" stored="true" required="true"
field name="Street" type="text_exact" indexed="true" stored="true"

pom.xml

<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>7.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>4.1.0</version>
<exclusions>
<exclusion>
<artifactId>slf4j-jdk14</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>

我收到以下错误消息

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrAddressRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.solr.repository.support.SolrRepositoryFactory$SolrQueryLookupStrategy.resolveQuery(Ljava/lang/reflect/Method;Lorg/springframework/data/repository/core/RepositoryMetadata;Lorg/springframework/data/repository/core/NamedQueries;)Lorg/springframework/data/repository/query/RepositoryQuery;    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:311) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]    at com.remsdaq.Runner.main(Runner.java:9) [classes/:na]Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrAddressRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.solr.repository.support.SolrRepositoryFactory$SolrQueryLookupStrategy.resolveQuery(Ljava/lang/reflect/Method;Lorg/springframework/data/repository/core/RepositoryMetadata;Lorg/springframework/data/repository/core/NamedQueries;)Lorg/springframework/data/repository/query/RepositoryQuery;    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:512) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:486) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:615) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:169) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:308) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]    ... 17 common frames omittedCaused by: java.lang.AbstractMethodError: org.springframework.data.solr.repository.support.SolrRepositoryFactory$SolrQueryLookupStrategy.resolveQuery(Ljava/lang/reflect/Method;Lorg/springframework/data/repository/core/RepositoryMetadata;Lorg/springframework/data/repository/core/NamedQueries;)Lorg/springframework/data/repository/query/RepositoryQuery;    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.(RepositoryFactorySupport.java:416) ~[spring-data-commons-1.11.4.RELEASE.jar:na]    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:206) ~[spring-data-commons-1.11.4.RELEASE.jar:na]    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251) ~[spring-data-commons-1.11.4.RELEASE.jar:na]    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237) ~[spring-data-commons-1.11.4.RELEASE.jar:na]    at org.springframework.data.solr.repository.support.SolrRepositoryFactoryBean.afterPropertiesSet(SolrRepositoryFactoryBean.java:91) ~[spring-data-solr-2.0.5.RELEASE.jar:na]    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]    ... 29 common frames omitted

如果我这样做List<AddressSolr> solrlist = SolrService.solrRepositoryX.findAll()findByStreet(String name)SolrAddressRepository 中删除然后就可以了。 findOne()也有效。只是无法创建我自己的查询。

方法关键字: https://docs.spring.io/spring-data/solr/docs/1.2.0.RC1/reference/htmlsingle/

最佳答案

您使用的 Spring Data Solr 版本与您使用的 Spring Data Commons 版本不兼容。

由于您用spring-boot标记了您的问题,我猜涉及到Spring Boot的依赖管理。它将为您管理 Spring Data Commons 和 Spring Data Solr 的版本。但是,您已经在 pom 中覆盖了 Spring Data Solr 的版本:

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>

Spring Data Solr 2.0.x 使用 Spring Data commons 1.12.x,但您使用的是 1.11.x。

您需要更新您的 pom 以便这些版本兼容。您尚未共享所有 pom,因此很难提供具体建议。

假设您使用的是 Spring Boot,则可以使用 Spring Boot 1.4.x 并删除版本覆盖。 Spring Boot 1.4.x 使用 Spring Data Hopper 版本。 Spring Data Solr 2.0.x 是 Hopper 版本系列的一部分。

如果您没有尝试过 Spring Data Solr 2.0.x,则可以使用 Spring Boot 1.5.x 或 2.0.0,并再次删除您的版本覆盖。

关于java - Spring Solr 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49669331/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com