【问题标题】:APPLICATION FAILED TO START The injection point has the following annotations: @org.springframework.beans.factory.annotation.Autowired应用程序启动失败注入点有以下注释:@org.springframework.beans.factory.annotation.Autowired
【发布时间】:2020-09-22 18:54:01
【问题描述】:

我创建了两个不同的项目,一个用于 API,一个用于 SQL,并将 SQLConnect 项目添加到 REST 项目中。

Rest 项目中的这个类

@RestController
public class PersonController {
    @Autowired
    private PersonRepository personRepository;
    @GetMapping("/person")
    public List<Person> getAllEmployees() {
        return personRepository.findAll();
    }
    @PostMapping("/addPerson")
    public Person createEmployee(@RequestBody Person person) {
        return personRepository.save(person);
    }
}

另一个项目项目中的接口名称是SQLConnect

@Repository
public interface PersonRepository extends JpaRepository<Person, Long>{
}

休息项目的 POM 文件:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>
<!--
<dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
</dependency>

 local dependencies -->
<dependency>
     <groupId>com.seedq.restinterface</groupId>
     <artifactId>RestInterface</artifactId>
     <version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
     <groupId>com.seedq.sql</groupId>
     <artifactId>SQLConnect</artifactId>
     <version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- local dependencies -->

SQLConnect 项目的 POM 文件:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>

错误是:


应用程序启动失败


说明:

com.seedq.rest.controller.PersonController 中的字段 personRepository 需要 'com.seedq.rest.repo.PersonRepository' 类型的 bean,但无法找到。

注入点有以下注解: - @org.springframework.beans.factory.annotation.Autowired(required=true)

行动:

考虑在您的配置中定义一个 'com.seedq.rest.repo.PersonRepository' 类型的 bean。

【问题讨论】:

  • 你是否在你的 RestController 中导入了 PersonRepository 接口?它在正确的路径上吗?似乎您在尝试导入它时遇到了问题。
  • 是的,路径正确

标签: java spring spring-boot hibernate jpa


【解决方案1】:

我认为您必须为本地 maven 项目添加系统路径或 url。

<systemPath>${project.basedir}/src/main/resources/Name_Your_JAR.jar</systemPath>

<repositories>
    <repository>
        <id>local-maven-repo</id>
        <url>file:///${project.parent.basedir}/local-maven-repo</url>
    </repository>
</repositories>

【讨论】:

    猜你喜欢
    • 2021-04-06
    • 2020-05-16
    • 2017-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多