Polishing
This commit is contained in:
parent
8f286de773
commit
8fba4a448a
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
|
|
@ -321,8 +321,8 @@ class ConfigurationClassPostProcessorTests {
|
|||
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
|
||||
pp.setEnvironment(new StandardEnvironment());
|
||||
pp.postProcessBeanFactory(beanFactory);
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
|
||||
beanFactory.getBean(SimpleComponent.class));
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> beanFactory.getBean(SimpleComponent.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -372,11 +372,11 @@ class ConfigurationClassPostProcessorTests {
|
|||
beanFactory.registerBeanDefinition("config", new RootBeanDefinition(SingletonBeanConfig.class));
|
||||
beanFactory.setAllowBeanDefinitionOverriding(false);
|
||||
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
|
||||
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() ->
|
||||
pp.postProcessBeanFactory(beanFactory))
|
||||
.withMessageContaining("bar")
|
||||
.withMessageContaining("SingletonBeanConfig")
|
||||
.withMessageContaining(TestBean.class.getName());
|
||||
assertThatExceptionOfType(BeanDefinitionStoreException.class)
|
||||
.isThrownBy(() -> pp.postProcessBeanFactory(beanFactory))
|
||||
.withMessageContaining("bar")
|
||||
.withMessageContaining("SingletonBeanConfig")
|
||||
.withMessageContaining(TestBean.class.getName());
|
||||
}
|
||||
|
||||
@Test // gh-25430
|
||||
|
|
@ -429,12 +429,12 @@ class ConfigurationClassPostProcessorTests {
|
|||
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
|
||||
pp.postProcessBeanFactory(beanFactory);
|
||||
|
||||
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
|
||||
beanFactory.getBean(Bar.class))
|
||||
.withMessageContaining("OverridingSingletonBeanConfig.foo")
|
||||
.withMessageContaining(ExtendedFoo.class.getName())
|
||||
.withMessageContaining(Foo.class.getName())
|
||||
.withMessageContaining("InvalidOverridingSingletonBeanConfig");
|
||||
assertThatExceptionOfType(BeanCreationException.class)
|
||||
.isThrownBy(() -> beanFactory.getBean(Bar.class))
|
||||
.withMessageContaining("OverridingSingletonBeanConfig.foo")
|
||||
.withMessageContaining(ExtendedFoo.class.getName())
|
||||
.withMessageContaining(Foo.class.getName())
|
||||
.withMessageContaining("InvalidOverridingSingletonBeanConfig");
|
||||
}
|
||||
|
||||
@Test // SPR-15384
|
||||
|
|
@ -985,16 +985,16 @@ class ConfigurationClassPostProcessorTests {
|
|||
beanFactory.registerBeanDefinition("configClass1", new RootBeanDefinition(A.class));
|
||||
beanFactory.registerBeanDefinition("configClass2", new RootBeanDefinition(AStrich.class));
|
||||
new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
|
||||
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(
|
||||
beanFactory::preInstantiateSingletons)
|
||||
.withMessageContaining("Circular reference");
|
||||
assertThatExceptionOfType(BeanCreationException.class)
|
||||
.isThrownBy(beanFactory::preInstantiateSingletons)
|
||||
.withMessageContaining("Circular reference");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCircularDependencyWithApplicationContext() {
|
||||
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
|
||||
new AnnotationConfigApplicationContext(A.class, AStrich.class))
|
||||
.withMessageContaining("Circular reference");
|
||||
assertThatExceptionOfType(BeanCreationException.class)
|
||||
.isThrownBy(() -> new AnnotationConfigApplicationContext(A.class, AStrich.class))
|
||||
.withMessageContaining("Circular reference");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -1048,9 +1048,7 @@ class ConfigurationClassPostProcessorTests {
|
|||
void testCollectionArgumentOnBeanMethod() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class, TestBean.class);
|
||||
CollectionArgumentConfiguration bean = ctx.getBean(CollectionArgumentConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans).hasSize(1);
|
||||
assertThat(bean.testBeans.get(0)).isSameAs(ctx.getBean(TestBean.class));
|
||||
assertThat(bean.testBeans).containsExactly(ctx.getBean(TestBean.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
|
@ -1058,8 +1056,7 @@ class ConfigurationClassPostProcessorTests {
|
|||
void testEmptyCollectionArgumentOnBeanMethod() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class);
|
||||
CollectionArgumentConfiguration bean = ctx.getBean(CollectionArgumentConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.isEmpty()).isTrue();
|
||||
assertThat(bean.testBeans).isEmpty();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
|
@ -1067,9 +1064,7 @@ class ConfigurationClassPostProcessorTests {
|
|||
void testMapArgumentOnBeanMethod() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MapArgumentConfiguration.class, DummyRunnable.class);
|
||||
MapArgumentConfiguration bean = ctx.getBean(MapArgumentConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans).hasSize(1);
|
||||
assertThat(bean.testBeans.values().iterator().next()).isSameAs(ctx.getBean(Runnable.class));
|
||||
assertThat(bean.testBeans).hasSize(1).containsValue(ctx.getBean(Runnable.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
|
@ -1077,8 +1072,7 @@ class ConfigurationClassPostProcessorTests {
|
|||
void testEmptyMapArgumentOnBeanMethod() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MapArgumentConfiguration.class);
|
||||
MapArgumentConfiguration bean = ctx.getBean(MapArgumentConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans.isEmpty()).isTrue();
|
||||
assertThat(bean.testBeans).isEmpty();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
|
@ -1086,9 +1080,7 @@ class ConfigurationClassPostProcessorTests {
|
|||
void testCollectionInjectionFromSameConfigurationClass() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionInjectionConfiguration.class);
|
||||
CollectionInjectionConfiguration bean = ctx.getBean(CollectionInjectionConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans).hasSize(1);
|
||||
assertThat(bean.testBeans.get(0)).isSameAs(ctx.getBean(TestBean.class));
|
||||
assertThat(bean.testBeans).containsExactly(ctx.getBean(TestBean.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
|
@ -1096,25 +1088,21 @@ class ConfigurationClassPostProcessorTests {
|
|||
void testMapInjectionFromSameConfigurationClass() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MapInjectionConfiguration.class);
|
||||
MapInjectionConfiguration bean = ctx.getBean(MapInjectionConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans).hasSize(1);
|
||||
assertThat(bean.testBeans.get("testBean")).isSameAs(ctx.getBean(Runnable.class));
|
||||
assertThat(bean.testBeans).containsOnly(Map.entry("testBean", ctx.getBean(Runnable.class)));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBeanLookupFromSameConfigurationClass() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BeanLookupConfiguration.class);
|
||||
BeanLookupConfiguration bean = ctx.getBean(BeanLookupConfiguration.class);
|
||||
assertThat(bean.getTestBean()).isNotNull();
|
||||
assertThat(bean.getTestBean()).isSameAs(ctx.getBean(TestBean.class));
|
||||
assertThat(ctx.getBean(BeanLookupConfiguration.class).getTestBean()).isSameAs(ctx.getBean(TestBean.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNameClashBetweenConfigurationClassAndBean() {
|
||||
assertThatExceptionOfType(BeanDefinitionStoreException.class)
|
||||
.isThrownBy(() -> new AnnotationConfigApplicationContext(MyTestBean.class).getBean("myTestBean", TestBean.class));
|
||||
.isThrownBy(() -> new AnnotationConfigApplicationContext(MyTestBean.class).getBean("myTestBean", TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -1131,11 +1119,11 @@ class ConfigurationClassPostProcessorTests {
|
|||
@Order(1)
|
||||
static class SingletonBeanConfig {
|
||||
|
||||
public @Bean Foo foo() {
|
||||
@Bean public Foo foo() {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
public @Bean Bar bar() {
|
||||
@Bean public Bar bar() {
|
||||
return new Bar(foo());
|
||||
}
|
||||
}
|
||||
|
|
@ -1143,11 +1131,11 @@ class ConfigurationClassPostProcessorTests {
|
|||
@Configuration(proxyBeanMethods = false)
|
||||
static class NonEnhancedSingletonBeanConfig {
|
||||
|
||||
public @Bean Foo foo() {
|
||||
@Bean public Foo foo() {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
public @Bean Bar bar() {
|
||||
@Bean public Bar bar() {
|
||||
return new Bar(foo());
|
||||
}
|
||||
}
|
||||
|
|
@ -1155,11 +1143,13 @@ class ConfigurationClassPostProcessorTests {
|
|||
@Configuration
|
||||
static class StaticSingletonBeanConfig {
|
||||
|
||||
public static @Bean Foo foo() {
|
||||
@Bean
|
||||
public static Foo foo() {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
public static @Bean Bar bar() {
|
||||
@Bean
|
||||
public static Bar bar() {
|
||||
return new Bar(foo());
|
||||
}
|
||||
}
|
||||
|
|
@ -1168,11 +1158,11 @@ class ConfigurationClassPostProcessorTests {
|
|||
@Order(2)
|
||||
static class OverridingSingletonBeanConfig {
|
||||
|
||||
public @Bean ExtendedFoo foo() {
|
||||
@Bean public ExtendedFoo foo() {
|
||||
return new ExtendedFoo();
|
||||
}
|
||||
|
||||
public @Bean Bar bar() {
|
||||
@Bean public Bar bar() {
|
||||
return new Bar(foo());
|
||||
}
|
||||
}
|
||||
|
|
@ -1180,7 +1170,7 @@ class ConfigurationClassPostProcessorTests {
|
|||
@Configuration
|
||||
static class OverridingAgainSingletonBeanConfig {
|
||||
|
||||
public @Bean ExtendedAgainFoo foo() {
|
||||
@Bean public ExtendedAgainFoo foo() {
|
||||
return new ExtendedAgainFoo();
|
||||
}
|
||||
}
|
||||
|
|
@ -1188,7 +1178,7 @@ class ConfigurationClassPostProcessorTests {
|
|||
@Configuration
|
||||
static class InvalidOverridingSingletonBeanConfig {
|
||||
|
||||
public @Bean Foo foo() {
|
||||
@Bean public Foo foo() {
|
||||
return new Foo();
|
||||
}
|
||||
}
|
||||
|
|
@ -1200,11 +1190,11 @@ class ConfigurationClassPostProcessorTests {
|
|||
@Order(1)
|
||||
static class SingletonBeanConfig {
|
||||
|
||||
public @Bean Foo foo() {
|
||||
@Bean public Foo foo() {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
public @Bean Bar bar() {
|
||||
@Bean public Bar bar() {
|
||||
return new Bar(foo());
|
||||
}
|
||||
}
|
||||
|
|
@ -1213,11 +1203,11 @@ class ConfigurationClassPostProcessorTests {
|
|||
@Order(2)
|
||||
static class OverridingSingletonBeanConfig {
|
||||
|
||||
public @Bean ExtendedFoo foo() {
|
||||
@Bean public ExtendedFoo foo() {
|
||||
return new ExtendedFoo();
|
||||
}
|
||||
|
||||
public @Bean Bar bar() {
|
||||
@Bean public Bar bar() {
|
||||
return new Bar(foo());
|
||||
}
|
||||
}
|
||||
|
|
@ -1233,11 +1223,11 @@ class ConfigurationClassPostProcessorTests {
|
|||
public SingletonBeanConfig(ConfigWithOrderedInnerClasses other) {
|
||||
}
|
||||
|
||||
public @Bean Foo foo() {
|
||||
@Bean public Foo foo() {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
public @Bean Bar bar() {
|
||||
@Bean public Bar bar() {
|
||||
return new Bar(foo());
|
||||
}
|
||||
}
|
||||
|
|
@ -1250,11 +1240,11 @@ class ConfigurationClassPostProcessorTests {
|
|||
other.getObject();
|
||||
}
|
||||
|
||||
public @Bean ExtendedFoo foo() {
|
||||
@Bean public ExtendedFoo foo() {
|
||||
return new ExtendedFoo();
|
||||
}
|
||||
|
||||
public @Bean Bar bar() {
|
||||
@Bean public Bar bar() {
|
||||
return new Bar(foo());
|
||||
}
|
||||
}
|
||||
|
|
@ -1281,7 +1271,7 @@ class ConfigurationClassPostProcessorTests {
|
|||
@Configuration
|
||||
static class UnloadedConfig {
|
||||
|
||||
public @Bean Foo foo() {
|
||||
@Bean public Foo foo() {
|
||||
return new Foo();
|
||||
}
|
||||
}
|
||||
|
|
@ -1289,7 +1279,7 @@ class ConfigurationClassPostProcessorTests {
|
|||
@Configuration
|
||||
static class LoadedConfig {
|
||||
|
||||
public @Bean Bar bar() {
|
||||
@Bean public Bar bar() {
|
||||
return new Bar(new Foo());
|
||||
}
|
||||
}
|
||||
|
|
@ -1598,7 +1588,7 @@ class ConfigurationClassPostProcessorTests {
|
|||
public static class WildcardWithGenericExtendsConfiguration {
|
||||
|
||||
@Bean
|
||||
public Repository<? extends Object> genericRepo() {
|
||||
public Repository<?> genericRepo() {
|
||||
return new Repository<String>();
|
||||
}
|
||||
|
||||
|
|
@ -1707,7 +1697,7 @@ class ConfigurationClassPostProcessorTests {
|
|||
}
|
||||
|
||||
@Configuration
|
||||
public static abstract class AbstractConfig {
|
||||
public abstract static class AbstractConfig {
|
||||
|
||||
@Bean
|
||||
public ServiceBean serviceBean() {
|
||||
|
|
@ -1758,7 +1748,6 @@ class ConfigurationClassPostProcessorTests {
|
|||
}
|
||||
|
||||
public interface DefaultMethodsConfig extends BaseDefaultMethods {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
|
@ -1891,7 +1880,7 @@ class ConfigurationClassPostProcessorTests {
|
|||
}
|
||||
}
|
||||
|
||||
static abstract class FooFactory {
|
||||
abstract static class FooFactory {
|
||||
|
||||
abstract DependingFoo createFoo(BarArgument bar);
|
||||
}
|
||||
|
|
@ -2010,7 +1999,7 @@ class ConfigurationClassPostProcessorTests {
|
|||
}
|
||||
|
||||
@Configuration
|
||||
static abstract class BeanLookupConfiguration {
|
||||
abstract static class BeanLookupConfiguration {
|
||||
|
||||
@Bean
|
||||
public TestBean thing() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
|
|
@ -204,7 +204,7 @@ class ConfigurationClassProcessingTests {
|
|||
BeanFactory factory = initBeanFactory(ConfigWithNullReference.class);
|
||||
|
||||
TestBean foo = factory.getBean("foo", TestBean.class);
|
||||
assertThat(factory.getBean("bar").equals(null)).isTrue();
|
||||
assertThat(factory.getBean("bar")).isEqualTo(null);
|
||||
assertThat(foo.getSpouse()).isNull();
|
||||
}
|
||||
|
||||
|
|
@ -426,7 +426,7 @@ class ConfigurationClassProcessingTests {
|
|||
@Configuration
|
||||
static class ConfigWithFinalBean {
|
||||
|
||||
public final @Bean TestBean testBean() {
|
||||
@Bean public final TestBean testBean() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
|
@ -435,7 +435,7 @@ class ConfigurationClassProcessingTests {
|
|||
@Configuration
|
||||
static class SimplestPossibleConfig {
|
||||
|
||||
public @Bean String stringBean() {
|
||||
@Bean public String stringBean() {
|
||||
return "foo";
|
||||
}
|
||||
}
|
||||
|
|
@ -444,11 +444,11 @@ class ConfigurationClassProcessingTests {
|
|||
@Configuration
|
||||
static class ConfigWithNonSpecificReturnTypes {
|
||||
|
||||
public @Bean Object stringBean() {
|
||||
@Bean public Object stringBean() {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
public @Bean FactoryBean<?> factoryBean() {
|
||||
@Bean public FactoryBean<?> factoryBean() {
|
||||
ListFactoryBean fb = new ListFactoryBean();
|
||||
fb.setSourceList(Arrays.asList("element1", "element2"));
|
||||
return fb;
|
||||
|
|
@ -459,13 +459,13 @@ class ConfigurationClassProcessingTests {
|
|||
@Configuration
|
||||
static class ConfigWithPrototypeBean {
|
||||
|
||||
public @Bean TestBean foo() {
|
||||
@Bean public TestBean foo() {
|
||||
TestBean foo = new SpousyTestBean("foo");
|
||||
foo.setSpouse(bar());
|
||||
return foo;
|
||||
}
|
||||
|
||||
public @Bean TestBean bar() {
|
||||
@Bean public TestBean bar() {
|
||||
TestBean bar = new SpousyTestBean("bar");
|
||||
bar.setSpouse(baz());
|
||||
return bar;
|
||||
|
|
@ -605,15 +605,15 @@ class ConfigurationClassProcessingTests {
|
|||
void register(GenericApplicationContext ctx) {
|
||||
ctx.registerBean("spouse", TestBean.class,
|
||||
() -> new TestBean("functional"));
|
||||
Supplier<TestBean> testBeanSupplier = () -> new TestBean(ctx.getBean("spouse", TestBean.class));
|
||||
ctx.registerBean(TestBean.class,
|
||||
testBeanSupplier,
|
||||
Supplier<TestBean> testBeanSupplier =
|
||||
() -> new TestBean(ctx.getBean("spouse", TestBean.class));
|
||||
ctx.registerBean(TestBean.class, testBeanSupplier,
|
||||
bd -> bd.setPrimary(true));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public NestedTestBean nestedTestBean(TestBean testBean) {
|
||||
return new NestedTestBean(testBean.getSpouse().getName());
|
||||
public NestedTestBean nestedTestBean(TestBean spouse) {
|
||||
return new NestedTestBean(spouse.getSpouse().getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
|
|
@ -38,7 +38,7 @@ public abstract class OrderUtils {
|
|||
/** Cache marker for a non-annotated Class. */
|
||||
private static final Object NOT_ANNOTATED = new Object();
|
||||
|
||||
private static final String JAVAX_PRIORITY_ANNOTATION = "jakarta.annotation.Priority";
|
||||
private static final String JAKARTA_PRIORITY_ANNOTATION = "jakarta.annotation.Priority";
|
||||
|
||||
/** Cache for @Order value (or NOT_ANNOTATED marker) per Class. */
|
||||
static final Map<AnnotatedElement, Object> orderCache = new ConcurrentReferenceHashMap<>(64);
|
||||
|
|
@ -124,7 +124,7 @@ public abstract class OrderUtils {
|
|||
if (orderAnnotation.isPresent()) {
|
||||
return orderAnnotation.getInt(MergedAnnotation.VALUE);
|
||||
}
|
||||
MergedAnnotation<?> priorityAnnotation = annotations.get(JAVAX_PRIORITY_ANNOTATION);
|
||||
MergedAnnotation<?> priorityAnnotation = annotations.get(JAKARTA_PRIORITY_ANNOTATION);
|
||||
if (priorityAnnotation.isPresent()) {
|
||||
return priorityAnnotation.getInt(MergedAnnotation.VALUE);
|
||||
}
|
||||
|
|
@ -139,7 +139,7 @@ public abstract class OrderUtils {
|
|||
*/
|
||||
@Nullable
|
||||
public static Integer getPriority(Class<?> type) {
|
||||
return MergedAnnotations.from(type, SearchStrategy.TYPE_HIERARCHY).get(JAVAX_PRIORITY_ANNOTATION)
|
||||
return MergedAnnotations.from(type, SearchStrategy.TYPE_HIERARCHY).get(JAKARTA_PRIORITY_ANNOTATION)
|
||||
.getValue(MergedAnnotation.VALUE, Integer.class).orElse(null);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
|
|
@ -284,6 +284,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
|
|||
* @see #CACHE_CONNECTION
|
||||
* @see #CACHE_SESSION
|
||||
* @see #CACHE_CONSUMER
|
||||
* @see #CACHE_AUTO
|
||||
* @see #setCacheLevelName
|
||||
* @see #setTransactionManager
|
||||
*/
|
||||
|
|
@ -570,8 +571,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
|
|||
if (this.taskExecutor == null) {
|
||||
this.taskExecutor = createDefaultTaskExecutor();
|
||||
}
|
||||
else if (this.taskExecutor instanceof SchedulingTaskExecutor ste &&
|
||||
ste.prefersShortLivedTasks() &&
|
||||
else if (this.taskExecutor instanceof SchedulingTaskExecutor ste && ste.prefersShortLivedTasks() &&
|
||||
this.maxMessagesPerTask == Integer.MIN_VALUE) {
|
||||
// TaskExecutor indicated a preference for short-lived tasks. According to
|
||||
// setMaxMessagesPerTask javadoc, we'll use 10 message per task in this case
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
|
|
@ -19,7 +19,6 @@ package org.springframework.jms.annotation;
|
|||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import jakarta.jms.JMSException;
|
||||
import jakarta.jms.MessageListener;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
@ -103,24 +102,20 @@ class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
void containerAreStartedByDefault() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
EnableJmsDefaultContainerFactoryConfig.class, DefaultBean.class);
|
||||
JmsListenerContainerTestFactory factory =
|
||||
context.getBean(JmsListenerContainerTestFactory.class);
|
||||
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
|
||||
MessageListenerTestContainer container = factory.getListenerContainers().get(0);
|
||||
assertThat(container.isAutoStartup()).isTrue();
|
||||
assertThat(container.isStarted()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
void containerCanBeStarterViaTheRegistry() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
EnableJmsAutoStartupFalseConfig.class, DefaultBean.class);
|
||||
JmsListenerContainerTestFactory factory =
|
||||
context.getBean(JmsListenerContainerTestFactory.class);
|
||||
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
|
||||
MessageListenerTestContainer container = factory.getListenerContainers().get(0);
|
||||
assertThat(container.isAutoStartup()).isFalse();
|
||||
assertThat(container.isStarted()).isFalse();
|
||||
|
|
@ -131,13 +126,13 @@ class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
|||
|
||||
@Override
|
||||
@Test
|
||||
void jmsHandlerMethodFactoryConfiguration() throws JMSException {
|
||||
void jmsHandlerMethodFactoryConfiguration() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
EnableJmsHandlerMethodFactoryConfig.class, ValidationBean.class);
|
||||
|
||||
assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() ->
|
||||
testJmsHandlerMethodFactoryConfiguration(context))
|
||||
.withCauseInstanceOf(MethodArgumentNotValidException.class);
|
||||
assertThatExceptionOfType(ListenerExecutionFailedException.class)
|
||||
.isThrownBy(() -> testJmsHandlerMethodFactoryConfiguration(context))
|
||||
.withCauseInstanceOf(MethodArgumentNotValidException.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -159,19 +154,20 @@ class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
|||
@Test
|
||||
void composedJmsListeners() {
|
||||
try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
EnableJmsDefaultContainerFactoryConfig.class, ComposedJmsListenersBean.class)) {
|
||||
JmsListenerContainerTestFactory simpleFactory = context.getBean("jmsListenerContainerFactory",
|
||||
JmsListenerContainerTestFactory.class);
|
||||
EnableJmsDefaultContainerFactoryConfig.class, ComposedJmsListenersBean.class)) {
|
||||
|
||||
JmsListenerContainerTestFactory simpleFactory =
|
||||
context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
|
||||
assertThat(simpleFactory.getListenerContainers()).hasSize(2);
|
||||
|
||||
MethodJmsListenerEndpoint first = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer(
|
||||
"first").getEndpoint();
|
||||
MethodJmsListenerEndpoint first = (MethodJmsListenerEndpoint)
|
||||
simpleFactory.getListenerContainer("first").getEndpoint();
|
||||
assertThat(first.getId()).isEqualTo("first");
|
||||
assertThat(first.getDestination()).isEqualTo("orderQueue");
|
||||
assertThat(first.getConcurrency()).isNull();
|
||||
|
||||
MethodJmsListenerEndpoint second = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer(
|
||||
"second").getEndpoint();
|
||||
MethodJmsListenerEndpoint second = (MethodJmsListenerEndpoint)
|
||||
simpleFactory.getListenerContainer("second").getEndpoint();
|
||||
assertThat(second.getId()).isEqualTo("second");
|
||||
assertThat(second.getDestination()).isEqualTo("billingQueue");
|
||||
assertThat(second.getConcurrency()).isEqualTo("2-10");
|
||||
|
|
@ -179,12 +175,11 @@ class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
void unknownFactory() {
|
||||
// not found
|
||||
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
|
||||
new AnnotationConfigApplicationContext(EnableJmsSampleConfig.class, CustomBean.class))
|
||||
.withMessageContaining("customFactory");
|
||||
assertThatExceptionOfType(BeanCreationException.class)
|
||||
.isThrownBy(() -> new AnnotationConfigApplicationContext(EnableJmsSampleConfig.class, CustomBean.class))
|
||||
.withMessageContaining("customFactory");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
|
|
@ -28,15 +28,13 @@ public class JmsListenerContainerTestFactory implements JmsListenerContainerFact
|
|||
|
||||
private boolean autoStartup = true;
|
||||
|
||||
private final Map<String, MessageListenerTestContainer> listenerContainers =
|
||||
new LinkedHashMap<>();
|
||||
private final Map<String, MessageListenerTestContainer> listenerContainers = new LinkedHashMap<>();
|
||||
|
||||
|
||||
public void setAutoStartup(boolean autoStartup) {
|
||||
this.autoStartup = autoStartup;
|
||||
}
|
||||
|
||||
|
||||
public List<MessageListenerTestContainer> getListenerContainers() {
|
||||
return new ArrayList<>(this.listenerContainers.values());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
|
|
@ -70,13 +70,15 @@ public class SingleConnectionFactory extends DelegatingConnectionFactory
|
|||
private boolean suppressClose;
|
||||
|
||||
/** Override auto-commit state?. */
|
||||
private @Nullable Boolean autoCommit;
|
||||
@Nullable
|
||||
private Boolean autoCommit;
|
||||
|
||||
/** Wrapped Connection. */
|
||||
private final AtomicReference<Connection> target = new AtomicReference<>();
|
||||
|
||||
/** Proxy Connection. */
|
||||
private @Nullable Connection connection;
|
||||
@Nullable
|
||||
private Connection connection;
|
||||
|
||||
private final Mono<? extends Connection> connectionEmitter;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue