猿问

来自另一个模块的 Spring Boot 自动装配

我正在尝试在我的项目中的 3 个模块之间建立连接。当我尝试使用 @Autowired 到达我的对象时出现错误。我会稍微解释一下我的场景。

所有这些模块都在 pom.xml 内部连接。说说我的问题吧。


C -> 路由.JAVA

.

.

.

@Autowired

public CommuniticationRepository;


@Autowired

public Core core;

.

.

.

B -> 核心

public class Core {

    private int id;

    private String name;

    private Date date;


    public Core(int id, String name, Date date) {

        this.id = id;

        this.name = name;

        this.date = date;

    }


    public int getId() {

        return id;

    }


    public void setId(int id) {

        this.id = id;

    }


    public String getName() {

        return name;

    }


    public void setName(String name) {

        this.name = name;

    }


    public Date getDate() {

        return date;

    }


    public void setDate(Date date) {

        this.date = date;

    }

}

错误

com.demo.xyz.A.RestControllers.Route 中的 FieldcommunicationRepository 需要一个无法找到的“com.demo.xyz.A.CommunicationRepository”类型的 bean。


行动:


考虑在您的配置中定义一个“com.demo.xyz.A.CommunicationRepository”类型的 bean。


A - > REPOSITORY.JAVA

@Component

@Repository

public interface CommunicationRepository extends CrudRepository<Communication, Date> {


    List<Communication> findByDate(Date date);


    void countByDate(Date date);

}


慕码人2483693
浏览 89回答 3
3回答
随时随地看视频慕课网APP

相关分类

Java
我要回答