问题
我的SpringBoot应用程序似乎无法连接ElasticSearch。每当我尝试运行我的应用程序时,我总是收到这个错误:
UnsatisfiedDependencyException:创建名为“filterController”的bean时出错:通过字段“服务”表示的未满足的依赖关系:创建名为“filterService”的bean时出错:通过字段“repository”表示的未满足的依赖关系:创建存储库中定义的名为“filterRepository”的Bean时出错。在ElasticsearchRepositoriesRegistrar上声明的@EnableElasticsearchRepositories中定义的FilterRepository。启用ElasticsearchRepositoriesConfiguration:示例化[org]失败。SpringFrameworkdata.elasticsearch.repository.support.SimpleElasticsearchRepository]:构造函数引发异常
代码信息
- 我没有做任何改变,也没有额外的配置。ElasticSearch正常运行
- 我没有创建自定义配置文件,因为SpringBoot does it automatically
- 您可以找到完整的源代码here
这是我 www.example.com 文件:
package br.com.uburu.spring;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
这是我 www.example.com 文件:
package br.com.uburu.spring.controller;
// Imports
@RestController
@RequestMapping("/api/v1/filter")
public class FilterController {
@Autowired
private FilterService service;
@GetMapping
public ResponseEntity<List<Filter>> getAll() {
List<Filter> filters = service.getAll();
return new ResponseEntity<List<Filter>>(filters, HttpStatus.OK);
}
@GetMapping("/{id}")
public ResponseEntity<Filter> getById(@PathVariable("id") long id) {
Filter filter = service.findById(id);
return new ResponseEntity<Filter>(filter, HttpStatus.OK);
}
// Some other methods
}
这是 www.example.com 文件:
package br.com.uburu.spring.service;
// Imports
@Service
public class FilterService {
@Autowired
private FilterRepository repository;
public List<Filter> getAll() {
List<Filter> filters = new ArrayList<>();
repository.findAll().forEach(filters::add);
return filters;
}
public Filter findById(long id) {
return repository.findById(id).orElse(null);
}
public Filter save(Filter filter) {
return repository.save(filter);
}
public void delete(long id) {
repository.deleteById(id);
}
}
我的 www.example.com 文件:
package br.com.uburu.spring.repository;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import br.com.uburu.spring.document.Filter;
public interface FilterRepository extends ElasticsearchRepository<Filter, Long> {}
最后,我的项目的依赖项:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-elasticsearch -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
<version>3.0.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-elasticsearch -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>5.0.5</version>
</dependency>
</dependencies>
我尝试过的一些解决方案:
- 初始化我的服务和存储库变量,不带
@Autowired
标记 - 在类构造函数中初始化它,在构造函数上方传递
@Autowired
标记 - 以admin身份运行ElasticSearch
- 清理Java语言服务器工作区(我正在使用VSCode)
- 在尝试运行应用程序之前再次运行
mvn clean install
ElasticSearch日志
我注意到,每当我尝试运行我的SpringBoot应用程序时,ElasticSearch的控制台中都会出现以下日志:
[2019 -04- 15 00:01:00][2019 - 04 - 15 00:00:00][2019 - 04 - 15 00:00][2019 - 04 - 15 00:00][2019 - 04 - 15 00:00][2019 - 01:00][2019 - 01][2019 - 01][2019 - 01:00][2019 - 01][2019 - 01][2019 - 01][2019 - 01][2019 - 01][2019 - 01][2019 - 01][2019 - 01][2019 - 01][2019 - 01][2019 - 01]e.h.n.Netty4HttpServerTransport] [DESKTOP-LO 4 MIAG]在https通道上接收明文http流量,关闭连接Netty 4 HttpChannel {localAddress=/127。0.0.1:9200,remoteAddress=/127。0.0.1:53007}
1条答案
按热度按时间uemypmqf1#
请将下面的类中的索引名称更改为小写:
结果: