Spring 遇到无效的@Scheduled方法“methodName”:只有没有参数方法可以用@Scheduled进行注释
如果我在我的代码中添加计划注释,我不知道代码中的确切问题是什么突然出现了这个错误 如果您有任何疑问,请告诉我。 如果我在我的代码中添加计划注释,我不知道代码中的确切问题是什么突然出现了这个错误 如果您有任何疑问,请告诉我Spring 遇到无效的@Scheduled方法“methodName”:只有没有参数方法可以用@Scheduled进行注释,spring,spring-boot,jakarta-ee,spring-batch,scheduled-tasks,Spring,Spring Boot,Jakarta Ee,Spring Batch,Scheduled Tasks,如果我在我的代码中添加计划注释,我不知道代码中的确切问题是什么突然出现了这个错误 如果您有任何疑问,请告诉我。 如果我在我的代码中添加计划注释,我不知道代码中的确切问题是什么突然出现了这个错误 如果您有任何疑问,请告诉我 Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 12-09-2019 18:11:54.908 [
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
12-09-2019 18:11:54.908 [restartedMain] ERROR o.s.boot.SpringApplication.reportFailure - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'missionResource': Unsatisfied dependency expressed through field 'missionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'missionImpl' defined in file [C:\Users\El Oussa\Desktop\vgas-api\vgas-manager\target\classes\ma\valueit\vgas\manager\business\impl\MissionImpl.class]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Encountered invalid @Scheduled method 'editMission': Only no-arg methods may be annotated with @Scheduled
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)
删除函数arg。调度程序在其函数中不接受argpublic void editMissionInteger id,missionTo missionTo不可能在调度方法中不能有参数。它必须是公开的无效编辑任务是的,我现在已经工作了,非常感谢你,兄弟
I have added @EnableScheduling in SpringBootApplication
--------------------------------------------------------
@SpringBootApplication
@EnableScheduling
@ComponentScan("com.qaiboub.vs")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@Service
public class MissionImpl extends CrudManagerImpl<MissionDto, Integer, MissionEntity, MissionService, MissionConverter> implements MissionManager {
@Autowired
private MissionService missionService;
@Autowired
private MissionConverter missionConverter;
enter code here
@Override
public MissionService getService() {
return missionService;
}
@Override
public MissionConverter getConverter() {
return missionConverter;
}
@Scheduled(cron = "0 15 18 * * *")
public void editMission(Integer id, MissionDto missionDto) {
if (StringUtils.isEmpty(id)) {
throw new MissingIdException();
}
if (missionDto == null) {
throw new InvalidPayloadException();
}
if (!id.equals(missionDto.getId())) {
throw new BusinessException(CommonErrorCode.TRYING_TO_EDIT_ANOTHER_ENTITY);
}
missionEntity = missionConverter.convertFrom(missionDto);
missionEntity = missionService.save(missionEntity);
}
}