我有一个Spring Boot应用程序,我需要将映像存储在本地文件夹中,并将其详细信息(例如ID,名称和db中的路径)存储到本地。现在,我想在文件夹以及数据库中编辑名称。我成功重命名了文件夹中的文件,我也想在db中重命名。我已经为此编写了代码,但是出现了错误,如不满意的依赖关系。在我的控制器中
@PutMapping("/updateFile")
public String updateFile(@RequestParam String oldFileName,@RequestParam String newFileName,@RequestParam UUID imageId,@RequestParam ImageModel imageModel) throws IOException {
// UUID Id=UUID.fromString(imageId);
imgserv.updateImageData(imageId, imageModel);
return fileStorageService.updateFile(oldFileName, newFileName);
}
和服务实施中
@Override
public String updateImageData(UUID imageId, ImageModel imageModel) {
ImageModel imageData = imageRepo.findImageById(imageId);
if (imageId == null) {
return "Image Data Not Found";
}
imageData.setImageName(imageModel.getImageName());
imageRepo.save(imageData);
return "Image Details Updated Successfully!";
}
和我的存储库类
@Repository(“ imageRepo”)公共接口ImageRepo扩展 MongoRepository {
ImageModel findImageById(UUID imageId);
}
我的错误代码就像
org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为'fileController'的bean时出错:通过字段'imgserv'表示的不满足的依赖关系;嵌套的异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“ imgserv”的bean时出错:通过字段“ imageRepo”表达的不满足的依赖关系;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为'imageRepo'的bean时出错:调用init方法失败;嵌套的异常是org.springframework.data.mapping.PropertyReferenceException:没有找到ImageModel类型的属性ID! 在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:586)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]中 在org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1341)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:572)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:317)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)〜[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)〜[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]