gpt4 book ai didi

java - Spring Boot项目创建bean出错

转载 作者:行者123 更新时间:2023-12-01 10:26:16 26 4
gpt4 key购买 nike

我有以下代码:

package com.frameworkonly.webapp;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.frameworkonly.webapp.domain.Employee;
import com.frameworkonly.webapp.service.EmployeeServiceInterface;

@EnableAutoConfiguration(exclude = {ErrorMvcAutoConfiguration.class})
@ComponentScan("com.frameworkonly.webapp")
public class SpringBootDemoApplication {

@Autowired
EmployeeServiceInterface employeeServiceInterface;

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

我刚刚开始使用Spring Boot。它给了我以下消息,但我不知道这意味着什么:

Error creating bean with name 'springBootDemoApplication': Injection of 
autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not autowire
field: com.exemple.service.PatientServiceInterface
com.example.SpringBootDemoApplication.patientServiceInterface; nested
exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [com.exemple.service.PatientServiceInterface]
found for dependency: expected at least 1 bean which qualifies as autowire
candidate for this dependency.

最佳答案

com.exemple.service 添加到扫描的包列表中,假设 PatientServiceInterface 注释有 @Service

@ComponentScan({"com.frameworkonly.webapp","com.exemple.service"})

关于java - Spring Boot项目创建bean出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35344786/

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