gpt4 book ai didi

java - org.test.api.controller.CheckerController 中的字段检查器需要类型为 'org.test.api.checker.Checker' 的 bean,但无法找到

转载 作者:太空宇宙 更新时间:2023-11-04 11:33:34 32 4
gpt4 key购买 nike

从 IntellijIDEA 运行 Spring 应用程序时出现以下错误。

2017-04-20 18:20:50.645 ERROR 28680 --- [main] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************
APPLICATION FAILED TO START
***************************

Description:

Field checker in org.test.api.controller.CheckerController required a bean of type 'org.test.api.checker.Checker' that could not be found.


Action:

Consider defining a bean of type 'org.test.api.checker.Checker' in your configuration.

但是,我在路径 org.test.api.checker.Checker 中有类 Checker

这是CheckerController类的示例代码:

@RestController
@RequestMapping("/api/{clientId}")
public class CheckerController {

@Autowired
Validator validator;

@Autowired
@Qualifier("Checker")
Checker checker;


@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(Context.class, new ContextEditor());
}

@RequestMapping(value = "/{userId}/{sessionId}/check", method = RequestMethod.GET)
public CheckResults check(@PathVariable String clientId,
@PathVariable String userId,
@PathVariable String sessionId) {
CheckRequest checkRequest = new CheckRequest(CheckRequest.TYPE_1, clientId, userId, sessionId);
this.validateRequest(checkRequest);
return checker.check(checkRequest);
}

}

Checker:

public interface Checker {

CheckResults check(CheckRequest request);

}

如何解决这个问题?

更新:

@Service
public class CheckerImpl implements Checker {

@Override
public CheckResults check(CheckRequest request)
{
// ...
}
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.test</groupId>
<artifactId>mytestapi</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spark.version>1.6.1</spark.version>
<es.version>2.2.0</es.version>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.5.BUILD-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>compiler</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${es.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.3</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-tdb</artifactId>
<version>3.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.10</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-scala_2.10</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
<version>6.5.0</version>
</dependency>
</dependencies>

<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/libs-snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>

</project>

最佳答案

当您通过 @Qualifier("Checker") Autowiring 时,请在 CheckerImpl 类的 @Service 中定义 bean 名称。

@Service("Checker")
public class CheckerImpl implements Checker {

@Override
public CheckResults check(CheckRequest request)
{
// ...
}
}

关于java - org.test.api.controller.CheckerController 中的字段检查器需要类型为 'org.test.api.checker.Checker' 的 bean,但无法找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43525296/

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