Browse Source

Merge branch '6.0.x'

pull/31025/head
Juergen Hoeller 2 years ago
parent
commit
f516431260
  1. 2
      framework-docs/modules/ROOT/pages/core/beans/annotation-config/autowired.adoc
  2. 4
      spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java
  3. 2
      spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java
  4. 53
      spring-context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java

2
framework-docs/modules/ROOT/pages/core/beans/annotation-config/autowired.adoc

@ -364,8 +364,6 @@ ignored if it cannot be autowired. This allows properties to be assigned default @@ -364,8 +364,6 @@ ignored if it cannot be autowired. This allows properties to be assigned default
that can be optionally overridden via dependency injection.
====
[[beans-autowired-annotation-constructor-resolution]]
Injected constructor and factory method arguments are a special case since the `required`
attribute in `@Autowired` has a somewhat different meaning due to Spring's constructor

4
spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java

@ -597,7 +597,7 @@ public class ScheduledAnnotationBeanPostProcessor @@ -597,7 +597,7 @@ public class ScheduledAnnotationBeanPostProcessor
}
if (tasks != null) {
for (ScheduledTask task : tasks) {
task.cancel();
task.cancel(false);
}
}
if (liveSubscriptions != null) {
@ -620,7 +620,7 @@ public class ScheduledAnnotationBeanPostProcessor @@ -620,7 +620,7 @@ public class ScheduledAnnotationBeanPostProcessor
Collection<Set<ScheduledTask>> allTasks = this.scheduledTasks.values();
for (Set<ScheduledTask> tasks : allTasks) {
for (ScheduledTask task : tasks) {
task.cancel();
task.cancel(false);
}
}
this.scheduledTasks.clear();

2
spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java

@ -575,7 +575,7 @@ public class ScheduledTaskRegistrar implements ScheduledTaskHolder, Initializing @@ -575,7 +575,7 @@ public class ScheduledTaskRegistrar implements ScheduledTaskHolder, Initializing
@Override
public void destroy() {
for (ScheduledTask task : this.scheduledTasks) {
task.cancel();
task.cancel(false);
}
if (this.localExecutor != null) {
this.localExecutor.shutdownNow();

53
spring-context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
package org.springframework.context.annotation;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Pattern;
import org.junit.jupiter.api.Test;
@ -104,19 +105,19 @@ class AnnotationConfigApplicationContextTests { @@ -104,19 +105,19 @@ class AnnotationConfigApplicationContextTests {
// attempt to retrieve a bean that does not exist
Class<?> targetType = Pattern.class;
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
context.getBean(targetType))
.withMessageContaining(format("No qualifying bean of type '%s'", targetType.getName()));
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> context.getBean(targetType))
.withMessageContaining(format("No qualifying bean of type '%s'", targetType.getName()));
}
@Test
void getBeanByTypeAmbiguityRaisesException() {
ApplicationContext context = new AnnotationConfigApplicationContext(TwoTestBeanConfig.class);
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
context.getBean(TestBean.class))
.withMessageContaining("No qualifying bean of type '" + TestBean.class.getName() + "'")
.withMessageContaining("tb1")
.withMessageContaining("tb2");
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> context.getBean(TestBean.class))
.withMessageContaining("No qualifying bean of type '" + TestBean.class.getName() + "'")
.withMessageContaining("tb1")
.withMessageContaining("tb2");
}
/**
@ -309,8 +310,8 @@ class AnnotationConfigApplicationContextTests { @@ -309,8 +310,8 @@ class AnnotationConfigApplicationContextTests {
assertThat(context.getBeansOfType(BeanB.class).values().iterator().next()).isSameAs(context.getBean(BeanB.class));
assertThat(context.getBeansOfType(BeanC.class).values().iterator().next()).isSameAs(context.getBean(BeanC.class));
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
context.getBeanFactory().resolveNamedBean(BeanA.class));
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> context.getBeanFactory().resolveNamedBean(BeanA.class));
assertThat(context.getBeanFactory().resolveNamedBean(BeanB.class).getBeanInstance()).isSameAs(context.getBean(BeanB.class));
assertThat(context.getBeanFactory().resolveNamedBean(BeanC.class).getBeanInstance()).isSameAs(context.getBean(BeanC.class));
}
@ -601,7 +602,6 @@ class AnnotationConfigApplicationContextTests { @@ -601,7 +602,6 @@ class AnnotationConfigApplicationContextTests {
BeanB b;
BeanC c;
@Autowired
BeanA(BeanB b, BeanC c) {
this.b = b;
@ -720,39 +720,18 @@ class AnnotationConfigApplicationContextTests { @@ -720,39 +720,18 @@ class AnnotationConfigApplicationContextTests {
}
}
class TestBean {
String name;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (name == null ? 0 : name.hashCode());
return result;
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof TestBean that && Objects.equals(this.name, that.name)));
}
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
TestBean other = (TestBean) obj;
if (name == null) {
if (other.name != null) {
return false;
}
}
else if (!name.equals(other.name)) {
return false;
}
return true;
public int hashCode() {
return this.name.hashCode();
}
}

Loading…
Cancel
Save