【发布时间】:2020-12-01 10:40:26
【问题描述】:
我正在尝试在我的项目中的 3 个模块之间建立连接。当我尝试使用@Autowired 到达我的对象时出现错误。我会稍微解释一下我的场景。
模块
所有这些模块都已连接到 pom.xml 中。说说我的问题吧。
C -> ROUTE.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 中的字段 communicationRepository '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);
}
【问题讨论】:
-
确保您将所需的包裹提供给
@ComponentScan,请参阅相关问答here -
我已经试过了。当我使用@ComponentScan 时,它不会在运行语句之前标记下划线。当我运行项目时,它返回一个错误,我写在黄色框中
-
你的意思是“它在运行语句之前没有标记下划线”?它是否显示编译错误?
-
请向我们展示您的“核心”课程
-
@Damith,Intellij Idea 说好的,但是当我运行它时,Spring 返回一个错误
标签: java spring spring-boot