Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Springboot和IDEA错误:无法自动连线。没有';实体链接';找到的类型_Java_Spring Boot - Fatal编程技术网

Java Springboot和IDEA错误:无法自动连线。没有';实体链接';找到的类型

Java Springboot和IDEA错误:无法自动连线。没有';实体链接';找到的类型,java,spring-boot,Java,Spring Boot,我将跟随《春季行动》第五版学习Springboot。在第6章中,我发现我的IDE在bean org.springframework.hateoas.server.EntityLinks中似乎有一个bug package tech.enigma.web.api; 导入org.springframework.data.domain.PageRequest; 导入org.springframework.data.domain.Sort; 导入org.springframework.hateoas.se

我将跟随《春季行动》第五版学习Springboot。在第6章中,我发现我的IDE在bean org.springframework.hateoas.server.EntityLinks中似乎有一个bug

package tech.enigma.web.api;
导入org.springframework.data.domain.PageRequest;
导入org.springframework.data.domain.Sort;
导入org.springframework.hateoas.server.EntityLinks;
导入org.springframework.web.bind.annotation.CrossOrigin;
导入org.springframework.web.bind.annotation.GetMapping;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RestController;
进口tech.enigma.Taco;
导入tech.enigma.data.TacoRepository;
@RestController
@请求映射(path=“/design”,products=“application/json”)
@交叉原点(原点=“*”)
公共类设计控制器
{
私人他克力普;
私有实体链接实体链接;
公共设计TacoController(TacoRepository tacoRepo,EntityLinks EntityLinks)
{
this.tacoRepo=tacoRepo;
this.entityLinks=entityLinks;
}
@GetMapping(“/recent”)
公共可检索目录
{
PageRequest page=PageRequest.of(
0,12,排序方式(“createAt”).descending();
返回tacoRepo.findAll(page.getContent();
}
}
在public DesignTacoController(TacoRepository tacoRepo,EntityLinks EntityLinks)构造函数中,IDEA给出了一个错误“无法自动连线。未找到'EntityLinks'类型的bean”。我可以编译并运行我的程序,尽管我不确定它是否正常工作。 其他豆子都可以。
这只是一个想法错误还是我搞错了?

@Autowired注释丢失了。要么做构造函数注入,要么做setter注入,然后它就会工作

package tech.enigma.web.api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.hateoas.server.EntityLinks;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.enigma.Taco;
import tech.enigma.data.TacoRepository;


@RestController
@RequestMapping(path = "/design", produces = "application/json")
@CrossOrigin(origins = "*")
public class DesignTacoController
{
    @Autowired
    private TacoRepository tacoRepo;
    @Autowired
    private EntityLinks entityLinks;

   

    @GetMapping("/recent")
    public Iterable<Taco> recentTacos()
    {
        PageRequest page = PageRequest.of(
                0, 12, Sort.by("createAt").descending());

        return tacoRepo.findAll(page).getContent();
    }
}
package tech.enigma.web.api;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.data.domain.PageRequest;
导入org.springframework.data.domain.Sort;
导入org.springframework.hateoas.server.EntityLinks;
导入org.springframework.web.bind.annotation.CrossOrigin;
导入org.springframework.web.bind.annotation.GetMapping;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RestController;
进口tech.enigma.Taco;
导入tech.enigma.data.TacoRepository;
@RestController
@请求映射(path=“/design”,products=“application/json”)
@交叉原点(原点=“*”)
公共类设计控制器
{
@自动连线
私人他克力普;
@自动连线
私有实体链接实体链接;
@GetMapping(“/recent”)
公共可检索目录
{
PageRequest page=PageRequest.of(
0,12,排序方式(“createAt”).descending();
返回tacoRepo.findAll(page.getContent();
}
}
这是一个。由于对自动配置的资源的扫描不正确,IntelliJ不会始终拾取所有可用的bean。
重要的是Spring运行时。如果它没有导致错误,那就去吧。

自Spring 4.3以来,如果只有一个构造函数,那么Autowired是可选的。我尝试了所有三种方法,但是结果都是一样的。谢谢,我想知道为什么这很难解决,因为我在三年前看到过关于堆栈溢出的类似问题。IntelliJ需要索引可用的bean。基于特定的注释,很难知道范围内的内容。如果库甚至更改了这些注释,它将崩溃。如果您不知道注释,它将断开。如果它基于intellij还不知道的类路径上的libs,它将被破坏。它需要在不启动spring运行时的情况下模拟所有这些。