mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Prevent docker access when running AOT processing on tests
Closes gh-37097
This commit is contained in:
parent
1a2919bb0e
commit
d310fb6fce
@ -74,8 +74,12 @@ class ServiceConnectionContextCustomizerFactory implements ContextCustomizerFact
|
|||||||
field.getDeclaringClass().getName(), Container.class.getName()));
|
field.getDeclaringClass().getName(), Container.class.getName()));
|
||||||
Class<C> containerType = (Class<C>) fieldValue.getClass();
|
Class<C> containerType = (Class<C>) fieldValue.getClass();
|
||||||
C container = (C) fieldValue;
|
C container = (C) fieldValue;
|
||||||
return new ContainerConnectionSource<>("test", origin, containerType, container.getDockerImageName(),
|
// container.getDockerImageName() fails if there is no running docker environment
|
||||||
annotation, () -> container);
|
// When running tests that doesn't matter, but running AOT processing should be
|
||||||
|
// possible without a Docker environment
|
||||||
|
String dockerImageName = isAotProcessingInProgress() ? null : container.getDockerImageName();
|
||||||
|
return new ContainerConnectionSource<>("test", origin, containerType, dockerImageName, annotation,
|
||||||
|
() -> container);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getFieldValue(Field field) {
|
private Object getFieldValue(Field field) {
|
||||||
@ -83,4 +87,8 @@ class ServiceConnectionContextCustomizerFactory implements ContextCustomizerFact
|
|||||||
return ReflectionUtils.getField(field, null);
|
return ReflectionUtils.getField(field, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isAotProcessingInProgress() {
|
||||||
|
return Boolean.getBoolean("spring.aot.processing");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user