Merge branch '6.0.x'

# Conflicts:
#	spring-beans/src/test/java/org/springframework/beans/factory/annotation/LookupAnnotationTests.java
This commit is contained in:
Juergen Hoeller 2023-08-03 18:11:08 +02:00
commit d868f58e6e
3 changed files with 50 additions and 11 deletions

View File

@ -911,6 +911,11 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
// static factory method signature or from class inheritance hierarchy... // static factory method signature or from class inheritance hierarchy...
return getTypeForFactoryBeanFromMethod(mbd.getBeanClass(), factoryMethodName); return getTypeForFactoryBeanFromMethod(mbd.getBeanClass(), factoryMethodName);
} }
result = getFactoryBeanGeneric(mbd.targetType);
if (result.resolve() != null) {
return result;
}
result = getFactoryBeanGeneric(beanType); result = getFactoryBeanGeneric(beanType);
if (result.resolve() != null) { if (result.resolve() != null) {
return result; return result;

View File

@ -2032,6 +2032,16 @@ class DefaultListableBeanFactoryTests {
assertBeanNamesForType(FactoryBean.class, false, false); assertBeanNamesForType(FactoryBean.class, false, false);
} }
@Test // gh-30987
void getBeanNamesForTypeWithFactoryBeanDefinedAsTargetType() {
RootBeanDefinition beanDefinition = new RootBeanDefinition(TestRepositoryFactoryBean.class);
beanDefinition.setTargetType(ResolvableType.forClassWithGenerics(TestRepositoryFactoryBean.class,
CityRepository.class, Object.class, Object.class));
lbf.registerBeanDefinition("factoryBean", beanDefinition);
assertBeanNamesForType(TestRepositoryFactoryBean.class, true, false, "&factoryBean");
assertBeanNamesForType(CityRepository.class, true, false, "factoryBean");
}
/** /**
* Verifies that a dependency on a {@link FactoryBean} can <strong>not</strong> * Verifies that a dependency on a {@link FactoryBean} can <strong>not</strong>
* be autowired <em>by name</em>, as &amp; is an illegal character in * be autowired <em>by name</em>, as &amp; is an illegal character in
@ -3120,6 +3130,25 @@ class DefaultListableBeanFactoryTests {
} }
public static class TestRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable>
extends RepositoryFactoryBeanSupport<T, S, ID> {
@Override
public T getObject() throws Exception {
throw new IllegalArgumentException("Should not be called");
}
@Override
public Class<?> getObjectType() {
throw new IllegalArgumentException("Should not be called");
}
}
public record City(String name) {}
public static class CityRepository implements Repository<City, Long> {}
public static class LazyInitFactory implements FactoryBean<Object> { public static class LazyInitFactory implements FactoryBean<Object> {
public boolean initialized = false; public boolean initialized = false;

View File

@ -113,8 +113,9 @@ abstract class AbstractSockJsIntegrationTests {
this.baseUrl = "http://localhost:" + this.server.getPort(); this.baseUrl = "http://localhost:" + this.server.getPort();
} }
@AfterEach @AfterEach
void teardown() throws Exception { void teardown() {
try { try {
this.sockJsClient.stop(); this.sockJsClient.stop();
} }
@ -141,6 +142,7 @@ abstract class AbstractSockJsIntegrationTests {
} }
} }
protected abstract Class<?> upgradeStrategyConfigClass(); protected abstract Class<?> upgradeStrategyConfigClass();
protected abstract WebSocketTestServer createWebSocketTestServer(); protected abstract WebSocketTestServer createWebSocketTestServer();
@ -154,6 +156,7 @@ abstract class AbstractSockJsIntegrationTests {
this.sockJsClient.start(); this.sockJsClient.start();
} }
@Test @Test
void echoWebSocket() throws Exception { void echoWebSocket() throws Exception {
testEcho(100, createWebSocketTransport(), null); testEcho(100, createWebSocketTransport(), null);
@ -305,8 +308,8 @@ abstract class AbstractSockJsIntegrationTests {
try { try {
Thread.sleep(timeToSleep); Thread.sleep(timeToSleep);
} }
catch (InterruptedException e) { catch (InterruptedException ex) {
throw new IllegalStateException("Interrupted while waiting for " + description, e); throw new IllegalStateException("Interrupted while waiting for " + description, ex);
} }
} }
throw new IllegalStateException("Timed out waiting for " + description); throw new IllegalStateException("Timed out waiting for " + description);
@ -333,6 +336,7 @@ abstract class AbstractSockJsIntegrationTests {
} }
} }
private static class TestClientHandler extends TextWebSocketHandler { private static class TestClientHandler extends TextWebSocketHandler {
private final BlockingQueue<TextMessage> receivedMessages = new LinkedBlockingQueue<>(); private final BlockingQueue<TextMessage> receivedMessages = new LinkedBlockingQueue<>();
@ -341,7 +345,6 @@ abstract class AbstractSockJsIntegrationTests {
private volatile Throwable transportError; private volatile Throwable transportError;
@Override @Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception { public void afterConnectionEstablished(WebSocketSession session) throws Exception {
this.session = session; this.session = session;
@ -376,6 +379,7 @@ abstract class AbstractSockJsIntegrationTests {
} }
} }
private static class EchoHandler extends TextWebSocketHandler { private static class EchoHandler extends TextWebSocketHandler {
@Override @Override
@ -384,21 +388,23 @@ abstract class AbstractSockJsIntegrationTests {
} }
} }
private static class TestServerHandler extends TextWebSocketHandler { private static class TestServerHandler extends TextWebSocketHandler {
private WebSocketSession session; private WebSocketSession session;
@Override @Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception { public void afterConnectionEstablished(WebSocketSession session) {
this.session = session; this.session = session;
} }
public WebSocketSession awaitSession(long timeToWait) throws InterruptedException { public WebSocketSession awaitSession(long timeToWait) {
awaitEvent(() -> this.session != null, timeToWait, " session"); awaitEvent(() -> this.session != null, timeToWait, " session");
return this.session; return this.session;
} }
} }
private static class TestFilter implements Filter { private static class TestFilter implements Filter {
private final Map<String, HttpHeaders> requests = new HashMap<>(); private final Map<String, HttpHeaders> requests = new HashMap<>();
@ -407,7 +413,6 @@ abstract class AbstractSockJsIntegrationTests {
private final Map<String, Integer> sendErrorMap = new HashMap<>(); private final Map<String, Integer> sendErrorMap = new HashMap<>();
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException { throws IOException, ServletException {
@ -418,18 +423,18 @@ abstract class AbstractSockJsIntegrationTests {
this.requests.put(uri, headers); this.requests.put(uri, headers);
for (String suffix : this.sleepDelayMap.keySet()) { for (String suffix : this.sleepDelayMap.keySet()) {
if ((httpRequest).getRequestURI().endsWith(suffix)) { if (httpRequest.getRequestURI().endsWith(suffix)) {
try { try {
Thread.sleep(this.sleepDelayMap.get(suffix)); Thread.sleep(this.sleepDelayMap.get(suffix));
break; break;
} }
catch (InterruptedException e) { catch (InterruptedException ex) {
e.printStackTrace(); ex.printStackTrace();
} }
} }
} }
for (String suffix : this.sendErrorMap.keySet()) { for (String suffix : this.sendErrorMap.keySet()) {
if ((httpRequest).getRequestURI().endsWith(suffix)) { if (httpRequest.getRequestURI().endsWith(suffix)) {
((HttpServletResponse) response).sendError(this.sendErrorMap.get(suffix)); ((HttpServletResponse) response).sendError(this.sendErrorMap.get(suffix));
return; return;
} }