Merge branch '3.1.x'

This commit is contained in:
Ryan Baxter
2023-06-13 20:36:11 -04:00
3 changed files with 24 additions and 1 deletions

View File

@@ -33,6 +33,7 @@ import org.springframework.cloud.config.server.environment.EnvironmentController
import org.springframework.cloud.config.server.environment.EnvironmentEncryptorEnvironmentRepository;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.cloud.config.server.resource.ResourceController;
import org.springframework.cloud.config.server.resource.ResourceControllerAdvice;
import org.springframework.cloud.config.server.resource.ResourceRepository;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
@@ -99,6 +100,12 @@ public class ConfigServerMvcConfiguration implements WebMvcConfigurer {
return controller;
}
@Bean
@ConditionalOnBean(ResourceController.class)
public ResourceControllerAdvice resourceControllerAdvice() {
return new ResourceControllerAdvice();
}
private EnvironmentRepository encrypted(EnvironmentRepository envRepository, ConfigServerProperties server) {
EnvironmentEncryptorEnvironmentRepository encrypted = new EnvironmentEncryptorEnvironmentRepository(
envRepository, this.environmentEncryptors, this.observationRegistry);

View File

@@ -31,7 +31,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
*/
@RestControllerAdvice(basePackages = { "org.springframework.cloud.config.server.resource" })
@Order
class ResourceControllerAdvice {
public class ResourceControllerAdvice {
private static Log logger = LogFactory.getLog(ResourceControllerAdvice.class);

View File

@@ -119,6 +119,17 @@ public class ResourceControllerIntegrationTests {
verify(this.resources).findOne("foo", "default", "master", "foo.txt");
}
@Test
public void resourceHttpDoesNotExist() throws Exception {
when(this.resources.findOne("foo", "default", "master", "doesNotExist.txt"))
.thenThrow(new NoSuchResourceException("Does not exist"));
ResponseEntity<String> response = new TestRestTemplate()
.getForEntity("http://localhost:" + port + "/foo/default/master/doesNotExist.txt", String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
verify(this.resources).findOne("foo", "default", "master", "doesNotExist.txt");
}
@Test
public void resourceNoLabel() throws Exception {
when(this.repository.findOne("foo", "default", null, false))
@@ -184,6 +195,11 @@ public class ResourceControllerIntegrationTests {
return repository;
}
@Bean
public ResourceControllerAdvice resourceControllerAdvice() {
return new ResourceControllerAdvice();
}
@Bean
public EnvironmentController environmentController() {
return new EnvironmentController(environmentRepository());