Skip to content

Commit

Permalink
Resolve property replacement not working in constructor injection. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskleeh committed Feb 25, 2019
1 parent 46ae8a8 commit c52f8fb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ class ClientScopeSpec extends Specification {
myJavaService.rxHttpClient == myService.rxHttpClient
}

void "test client scope annotation constructor injection"() {
given:
MyServiceConstructor myService = context.getBean(MyServiceConstructor)

MyJavaService myJavaService = context.getBean(MyJavaService)

expect:
myService.get() == 'success'
myJavaService.client == myService.client
myJavaService.rxHttpClient == myService.rxHttpClient
}

@Controller('/scope')
static class ScopeController {
@Get(produces = MediaType.TEXT_PLAIN)
Expand Down Expand Up @@ -116,4 +128,24 @@ class ClientScopeSpec extends Specification {
)
}
}

@Singleton
static class MyServiceConstructor {

private final HttpClient client
private final RxHttpClient rxHttpClient

MyServiceConstructor(@Client('${from.config}')HttpClient client,
@Client('${from.config}') RxHttpClient rxHttpClient) {
this.rxHttpClient = rxHttpClient
this.client = client
}

String get() {
rxHttpClient != null
client.toBlocking().retrieve(
HttpRequest.GET('/scope'), String
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,10 @@ protected final Stream streamOfTypeForMethodArgument(BeanResolutionContext resol
protected final Object getBeanForConstructorArgument(BeanResolutionContext resolutionContext, BeanContext context, int argIndex) {
ConstructorInjectionPoint<T> constructorInjectionPoint = getConstructor();
Argument<?> argument = constructorInjectionPoint.getArguments()[argIndex];
if (argument instanceof DefaultArgument) {
argument = new EnvironmentAwareArgument((DefaultArgument) argument);
instrumentAnnotationMetadata(context, argument);
}
Class argumentType = argument.getType();
if (argumentType == BeanResolutionContext.class) {
return resolutionContext;
Expand Down

0 comments on commit c52f8fb

Please sign in to comment.