首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SpringBoot:不能在接口级别工作的原型注释

SpringBoot:不能在接口级别工作的原型注释
EN

Stack Overflow用户
提问于 2020-02-25 14:45:55
回答 1查看 436关注 0票数 0
代码语言:javascript
复制
   package com.Test.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan({"com.Test.springboot"})
public class SpringBoot1Application {

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



    }

}

控制器类

代码语言:javascript
复制
package com.Test.springboot;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.Test.springboot.model.Student;
import com.Test.springboot.model.StudentDao;

@Controller
public class StudentController {
    @Autowired
    private StudentDao studentDao;

    @RequestMapping("/")
    public String homePage() {
        return "home";
    }

StudentDao

代码语言:javascript
复制
@Repository
public interface StudentDao {
    public Student addStudent(Student student);
    public Student getStudent(long id);
    public List<Student> getAllStudents();
    public String deleteStudent();

}

--如果我们将原型(Repository)注释更改为实现类,那么它就能正常工作。但是,接口级别抛出了一个error(org.springframework.beans.factory.NoSuchBeanDefinitionException: No合格bean,类型为“com.vitechinc.springboot.model.StudentDao”可用:)

EN

回答 1

Stack Overflow用户

发布于 2021-01-28 17:21:08

尝试将下面的代码作为maven依赖项添加到pom.xml文件中:

我也遇到了同样的问题,在安装了这个依赖程序之后,

代码语言:javascript
复制
<dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.8</version>
        <scope>provided</scope>
</dependency>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60397220

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档