autowire - springboot的configuration类无法注入bean
问 题 @Configuration public class ScheduledTasks implements Job{ @Autowired private GridFSService gridFSService; @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { this.gridFSService.saveFiles(); } } 我使用的注解配置,但是gridFSService总是会报空指针异常。请问在@Configuration配置类里面应该如何注入bean呢? 谢谢! GridFSService如下: @Component public class GridFSService { @Autowired MongoOperati
3688 2022-07-19
编程技术问答社区
java - 如何在Comparator类中autowire一个接口
问 题 使用springboot,和mongo的repository,我定义了一个Comparator类,想实现自己的对象的比较方法。代码如下: package com.story.utils; import java.util.Comparator; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.story.model.Phase; import com.story.model.Story; import com.story.repository.StoryRepository; @Service public class PhaseComparator implements Comparator{ private String field; private Story stor
188 2022-07-19
编程技术问答社区