<分区>
我的 Spring-Boot
应用程序中有 2 个类:
-任务
-运行者
runner 类包含我的 main
方法,我在其中尝试从我的 Tasks 类调用方法:
运行者:
@Component
public class Runner {
Tasks tasks;
@Autowired
public void setTasks(Tasks tasks){
this.tasks=tasks;
}
public static void main(String[] args){
//error being caused by below line
tasks.createTaskList();
}
任务类:
@Service
public class Tasks {
public void createTaskList() {
//my code
}
//other methods
}
在我的 Runner 中,当我尝试调用 Tasks 类中的 createTaskList() 方法时,出现以下错误:
Non static field 'tasks' cannot be referenced from a static context
我该如何解决这个问题?