我在测试执行中遇到此异常:
UnsatisfiedDependencyException:创建名为“net.gencat.transversal.espaidoc.mongo.GridFSTest”的bean时出错:通过字段“resourceProperties”表达的不满意依赖;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有可用的“net.gencat.transversal.espaidoc.ResourcesConfigProperties”类型的合格 bean:预计至少有 1 个 bean 有资格作为自动装配候选。
所以,我认为信息是如此清楚不过了:ResourcesConfigProperties is not satisfied。
我的测试:
RunWith(SpringRunner.class)
@SpringBootTest()
public class GridFSTest {
@Autowired
private GridFsTemplate gridFsTemplate;
@Autowired
private ResourcesConfigProperties resourceProperties;
public URL getHugeResource() {
try {
return Paths
.get(this.resourceProperties.getHuge())
.toUri()
.toURL();
} catch (MalformedURLException e) {
return null;
}
}
@Test
public void storeHugeFile() throws IOException {
URL resource = this.getHugeResource();
this.gridFsTemplate.store(
resource.openStream(),
resource.getPath(),
"mime"
);
}
}
Run Code Online (Sandbox Code Playgroud)
并且ResourcesConfigProperties是:
@ConfigurationProperties(prefix = "files")
public class ResourcesConfigProperties {
private String huge; …Run Code Online (Sandbox Code Playgroud)