Flexible constructor resolution in AutowireCapableBeanFactory.createBean(Class)
Closes gh-29855 See gh-29823
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,7 +36,6 @@ import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.springframework.beans.factory.config.AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
@@ -174,8 +173,7 @@ public class RequestScopeTests {
|
||||
assertThat(beanProvider.getIfAvailable()).isNull();
|
||||
assertThat(beanProvider.getIfUnique()).isNull();
|
||||
|
||||
ObjectProvider<CountingTestBean> provider =
|
||||
((ProviderBean) this.beanFactory.createBean(ProviderBean.class, AUTOWIRE_CONSTRUCTOR, false)).provider;
|
||||
ObjectProvider<CountingTestBean> provider = this.beanFactory.createBean(ProviderBean.class).provider;
|
||||
assertThatExceptionOfType(ScopeNotActiveException.class).isThrownBy(provider::getObject);
|
||||
assertThat(provider.getIfAvailable()).isNull();
|
||||
assertThat(provider.getIfUnique()).isNull();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,7 +36,6 @@ import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.springframework.beans.factory.config.AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
@@ -209,13 +208,12 @@ public class RequestScopedProxyTests {
|
||||
assertThatExceptionOfType(ScopeNotActiveException.class).isThrownBy(
|
||||
() -> this.beanFactory.getBean(CountingTestBean.class).absquatulate());
|
||||
|
||||
final ObjectProvider<CountingTestBean> beanProvider = this.beanFactory.getBeanProvider(CountingTestBean.class);
|
||||
ObjectProvider<CountingTestBean> beanProvider = this.beanFactory.getBeanProvider(CountingTestBean.class);
|
||||
assertThatExceptionOfType(ScopeNotActiveException.class).isThrownBy(() -> beanProvider.getObject().absquatulate());
|
||||
beanProvider.ifAvailable(TestBean::absquatulate);
|
||||
beanProvider.ifUnique(TestBean::absquatulate);
|
||||
|
||||
final ObjectProvider<CountingTestBean> provider =
|
||||
((ProviderBean) this.beanFactory.createBean(ProviderBean.class, AUTOWIRE_CONSTRUCTOR, false)).provider;
|
||||
ObjectProvider<CountingTestBean> provider = this.beanFactory.createBean(ProviderBean.class).provider;
|
||||
assertThatExceptionOfType(ScopeNotActiveException.class).isThrownBy(() -> provider.getObject().absquatulate());
|
||||
provider.ifAvailable(TestBean::absquatulate);
|
||||
provider.ifUnique(TestBean::absquatulate);
|
||||
|
||||
Reference in New Issue
Block a user