Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.aot.AotDetector;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.EmbeddedValueResolver;
import org.springframework.cglib.core.SpringNamingPolicy;
import org.springframework.cglib.proxy.Callback;
import org.springframework.cglib.proxy.Enhancer;
Expand All @@ -54,7 +55,6 @@
import org.springframework.util.ReflectionUtils;
import org.springframework.util.ReflectionUtils.MethodFilter;
import org.springframework.util.StringUtils;
import org.springframework.util.SystemPropertyUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.request.RequestAttributes;
Expand Down Expand Up @@ -629,14 +629,13 @@ private static CompositeUriComponentsContributor getUriComponentsContributor() {
}

private static String resolveEmbeddedValue(String value) {
if (value.contains(SystemPropertyUtils.PLACEHOLDER_PREFIX)) {
WebApplicationContext webApplicationContext = getWebApplicationContext();
if (webApplicationContext != null &&
webApplicationContext.getAutowireCapableBeanFactory() instanceof ConfigurableBeanFactory cbf) {
String resolvedEmbeddedValue = cbf.resolveEmbeddedValue(value);
if (resolvedEmbeddedValue != null) {
return resolvedEmbeddedValue;
}
WebApplicationContext webApplicationContext = getWebApplicationContext();
if (webApplicationContext != null &&
webApplicationContext.getAutowireCapableBeanFactory() instanceof ConfigurableBeanFactory cbf) {
EmbeddedValueResolver embeddedValueResolver = new EmbeddedValueResolver(cbf);
String resolvedEmbeddedValue = embeddedValueResolver.resolveStringValue(value);
if (resolvedEmbeddedValue != null) {
return resolvedEmbeddedValue;
}
}
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,22 @@ void fromMethodNameConfigurablePath() {
assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/something/custom/1/foo");
}

@Test
void fromMethodNameConfigurablePathSpEL() {
try {
System.setProperty("customMapping", "custom");
StandardEnvironment environment = new StandardEnvironment();
initWebApplicationContext(WebConfig.class, environment);
UriComponents uriComponents = fromMethodName(ControllerWithMethods.class,
"methodWithConfigurableMappingThroughSpEL", "1").build();
assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/something/custom/1/foo");
}
finally {
System.clearProperty("customMapping");
}

}

@Test
void fromMethodNameWithAnnotationsOnInterface() {
initWebApplicationContext(WebConfig.class);
Expand Down Expand Up @@ -703,6 +719,11 @@ HttpEntity<Void> methodWithOptionalNamedParam(@RequestParam("search") Optional<S
HttpEntity<Void> methodWithConfigurableMapping(@PathVariable String id) {
return null;
}

@RequestMapping("/#{systemProperties.customMapping}/{id}/foo")
HttpEntity<Void> methodWithConfigurableMappingThroughSpEL(@PathVariable String id) {
return null;
}
}


Expand Down