gpt4 book ai didi

java - 初始化SolrRepository时出错:通过字段表示的不满意依赖性

转载 作者:行者123 更新时间:2023-12-01 09:44:41 27 4
gpt4 key购买 nike

这是给我以下异常的代码:

@SpringBootApplication
@ComponentScan(basePackages = { "com.ns.services.search", "com.ns.services.commons.exceptions" })
@EnableSolrRepositories(value = "com.ns.services.search", schemaCreationSupport = true, multicoreSupport = true)
@EnableSwagger2
public class SearchServiceApplication {

public static void main(String[] args) {
SpringApplication.run(SearchServiceApplication.class, args);
}

@Bean
public HttpSolrClient solrClient() {
return new HttpSolrClient("http://localhost:8983/solr");
}

@Bean
public SolrTemplate solrTemplate(SolrClient client) throws Exception {
return new SolrTemplate(client);
}

@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any()).build();
}

@Bean
public SolrTemplate bookTemplate() throws Exception {
SolrTemplate solrTemplate = new SolrTemplate(solrClient());
solrTemplate.setSolrCore("demo");
return solrTemplate;
}

}


BookRepository.java

@NoRepositoryBean
public interface BookRepository extends SolrCrudRepository<Book, String> {

List<Book> findByName(String name);

}


BookService.java

public interface BookService {

Book addBookToIndex(Book book);

}


BookServiceImpl.java

@Service
public class BookServiceImpl implements BookService {

public BookServiceImpl() {
super();
}

@Autowired
public BookRepository bookRepository;

@Override
public Book addBookToIndex(Book book) {
return bookRepository.save(book);
}

}


尝试启动服务时的异常跟踪:

org.springframework.beans.factory.BeanCreationException:创建名称为'bookController'的bean时出错:自动连接依赖项的注入失败;嵌套的异常是org.springframework.beans.factory.BeanCreationException:无法自动连线字段:私有com.neighbourspoon.services.search.repositories.BookRepository com.neighbourspoon.services.search.api.rest.BookController.bookRepository;嵌套的异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有发现依赖项类型为[com.neighbourspoon.services.search.repositories.BookRepository]的合格Bean:期望至少有1个Bean可以作为此依赖项的自动装配候选。依赖项注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}
在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)〜[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)〜[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)〜[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)〜[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)〜[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)〜[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)〜[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)〜[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
在org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)〜[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)〜[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)〜[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
在org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)〜[spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)上[spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
在org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)上[spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
在org.springframework.boot.SpringApplication.run(SpringApplication.java:307)[spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
在org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)上[spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
在org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)上[spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
在com.neighbourspoon.services.search.main.SearchServiceApplication.main(SearchServiceApplication.java:26)[bin /:na]
引起原因:org.springframework.beans.factory.BeanCreationException:无法自动连线字段:私有com.neighbourspoon.services.search.repositories.BookRepository com.neighbourspoon.services.search.api.rest.BookController.bookRepository;嵌套的异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有发现依赖项类型为[com.neighbourspoon.services.search.repositories.BookRepository]的合格Bean:期望至少有1个Bean可以作为此依赖项的自动装配候选。依赖项注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}
在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)〜[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]中
在org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)〜[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)〜[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
...省略了17个通用框架
由以下原因引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有发现类型为[com.neighbourspoon.services.search.repositories.BookRepository]的合格Bean作为依赖项:至少应有1个可作为该依赖项的自动装配候选的bean。依赖项注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}
在org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)〜[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
在org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119)〜[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)〜[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)〜[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]中
...省略了19个通用框架

2016-07-03 15:08:34.596信息35332 ---

最佳答案

stacktrace包含


没有合格的Bean类型
[com.neighbourspoon.services.search.repositories.BookRepository]


这是因为BookRepository中的@NoRepositoryBean批注。您应该将其删除。这仅用于自定义中间存储库。在这里,您直接扩展了Spring Data存储库。

关于java - 初始化SolrRepository时出错:通过字段表示的不满意依赖性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38160986/

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