Skip to content

Commit 90de82a

Browse files
committed
Merge pull request #43065 from quaff
* gh-43065: Polish "Use constants for well-known scope names" Use constants for well-known scope names Closes gh-43065
2 parents 2fa28fb + 5d63335 commit 90de82a

File tree

12 files changed

+33
-23
lines changed

12 files changed

+33
-23
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/beans/BeansEndpoint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -160,7 +160,7 @@ public static final class BeanDescriptor {
160160

161161
private BeanDescriptor(String[] aliases, String scope, Class<?> type, String resource, String[] dependencies) {
162162
this.aliases = aliases;
163-
this.scope = (StringUtils.hasText(scope) ? scope : BeanDefinition.SCOPE_SINGLETON);
163+
this.scope = (StringUtils.hasText(scope) ? scope : ConfigurableBeanFactory.SCOPE_SINGLETON);
164164
this.type = type;
165165
this.resource = resource;
166166
this.dependencies = dependencies;

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.typesafe.config.ConfigFactory;
4040

4141
import org.springframework.beans.factory.ObjectProvider;
42+
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
4243
import org.springframework.boot.autoconfigure.AutoConfiguration;
4344
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
4445
import org.springframework.boot.autoconfigure.cassandra.CassandraProperties.Connection;
@@ -111,7 +112,7 @@ public CqlSession cassandraSession(CqlSessionBuilder cqlSessionBuilder) {
111112

112113
@Bean
113114
@ConditionalOnMissingBean
114-
@Scope("prototype")
115+
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
115116
public CqlSessionBuilder cassandraSessionBuilder(DriverConfigLoader driverConfigLoader,
116117
CassandraConnectionDetails connectionDetails,
117118
ObjectProvider<CqlSessionBuilderCustomizer> builderCustomizers, ObjectProvider<SslBundles> sslBundles) {

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/rsocket/RSocketGraphQlClientAutoConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020
import io.rsocket.RSocket;
2121
import io.rsocket.transport.netty.client.TcpClientTransport;
2222

23+
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
2324
import org.springframework.boot.autoconfigure.AutoConfiguration;
2425
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2526
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -47,7 +48,7 @@
4748
public class RSocketGraphQlClientAutoConfiguration {
4849

4950
@Bean
50-
@Scope("prototype")
51+
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
5152
@ConditionalOnMissingBean
5253
public RSocketGraphQlClient.Builder<?> rsocketGraphQlClientBuilder(
5354
RSocketRequester.Builder rsocketRequesterBuilder) {

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,6 +44,7 @@
4444
import org.springframework.aot.hint.RuntimeHintsRegistrar;
4545
import org.springframework.beans.BeanUtils;
4646
import org.springframework.beans.factory.ObjectProvider;
47+
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
4748
import org.springframework.boot.autoconfigure.AutoConfiguration;
4849
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
4950
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -150,7 +151,7 @@ ParameterNamesModule parameterNamesModule() {
150151
static class JacksonObjectMapperBuilderConfiguration {
151152

152153
@Bean
153-
@Scope("prototype")
154+
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
154155
@ConditionalOnMissingBean
155156
Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder(ApplicationContext applicationContext,
156157
List<Jackson2ObjectMapperBuilderCustomizer> customizers) {

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketRequesterAutoConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020
import reactor.netty.http.server.HttpServer;
2121

2222
import org.springframework.beans.factory.ObjectProvider;
23+
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
2324
import org.springframework.boot.autoconfigure.AutoConfiguration;
2425
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2526
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -46,7 +47,7 @@
4647
public class RSocketRequesterAutoConfiguration {
4748

4849
@Bean
49-
@Scope("prototype")
50+
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
5051
@ConditionalOnMissingBean
5152
public RSocketRequester.Builder rSocketRequesterBuilder(RSocketStrategies strategies,
5253
ObjectProvider<RSocketConnectorConfigurer> connectorConfigurers) {

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/client/RestClientAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.autoconfigure.web.client;
1818

1919
import org.springframework.beans.factory.ObjectProvider;
20+
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
2021
import org.springframework.boot.autoconfigure.AutoConfiguration;
2122
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2223
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -77,7 +78,7 @@ RestClientBuilderConfigurer restClientBuilderConfigurer(ObjectProvider<RestClien
7778
}
7879

7980
@Bean
80-
@Scope("prototype")
81+
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
8182
@ConditionalOnMissingBean
8283
RestClient.Builder restClientBuilder(RestClientBuilderConfigurer restClientBuilderConfigurer) {
8384
RestClient.Builder builder = RestClient.builder()

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientAutoConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.autoconfigure.web.reactive.function.client;
1818

1919
import org.springframework.beans.factory.ObjectProvider;
20+
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
2021
import org.springframework.boot.autoconfigure.AutoConfiguration;
2122
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2223
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -48,7 +49,7 @@
4849
public class WebClientAutoConfiguration {
4950

5051
@Bean
51-
@Scope("prototype")
52+
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
5253
@ConditionalOnMissingBean
5354
public WebClient.Builder webClientBuilder(ObjectProvider<WebClientCustomizer> customizerProvider) {
5455
WebClient.Builder builder = WebClient.builder();

spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ The following example uses HtmlUnit:
407407
include::code:MyHtmlUnitTests[]
408408

409409
NOTE: By default, Spring Boot puts `WebDriver` beans in a special "`scope`" to ensure that the driver exits after each test and that a new instance is injected.
410-
If you do not want this behavior, you can add `@Scope("singleton")` to your `WebDriver` `@Bean` definition.
410+
If you do not want this behavior, you can add `@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)` to your `WebDriver` `@Bean` definition.
411411

412412
WARNING: The `webDriver` scope created by Spring Boot will replace any user defined scope of the same name.
413413
If you define your own `webDriver` scope you may find it stops working when you use `@WebMvcTest`.

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestersAutoConfiguration.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
3232
import org.springframework.beans.BeansException;
3333
import org.springframework.beans.factory.FactoryBean;
3434
import org.springframework.beans.factory.config.BeanPostProcessor;
35+
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
3536
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
3637
import org.springframework.boot.autoconfigure.AutoConfiguration;
3738
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -73,7 +74,7 @@ public static JsonMarshalTestersBeanPostProcessor jsonMarshalTestersBeanPostProc
7374
}
7475

7576
@Bean
76-
@Scope("prototype")
77+
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
7778
@ImportRuntimeHints(BasicJsonTesterRuntimeHints.class)
7879
public FactoryBean<BasicJsonTester> basicJsonTesterFactoryBean() {
7980
return new JsonTesterFactoryBean<BasicJsonTester, Void>(BasicJsonTester.class, null);
@@ -84,7 +85,7 @@ public FactoryBean<BasicJsonTester> basicJsonTesterFactoryBean() {
8485
static class JacksonJsonTestersConfiguration {
8586

8687
@Bean
87-
@Scope("prototype")
88+
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
8889
@ConditionalOnBean(ObjectMapper.class)
8990
@ImportRuntimeHints(JacksonTesterRuntimeHints.class)
9091
FactoryBean<JacksonTester<?>> jacksonTesterFactoryBean(ObjectMapper mapper) {
@@ -106,7 +107,7 @@ static class JacksonTesterRuntimeHints extends AbstractJsonMarshalTesterRuntimeH
106107
static class GsonJsonTestersConfiguration {
107108

108109
@Bean
109-
@Scope("prototype")
110+
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
110111
@ConditionalOnBean(Gson.class)
111112
@ImportRuntimeHints(GsonTesterRuntimeHints.class)
112113
FactoryBean<GsonTester<?>> gsonTesterFactoryBean(Gson gson) {
@@ -128,7 +129,7 @@ static class GsonTesterRuntimeHints extends AbstractJsonMarshalTesterRuntimeHint
128129
static class JsonbJsonTesterConfiguration {
129130

130131
@Bean
131-
@Scope("prototype")
132+
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
132133
@ConditionalOnBean(Jsonb.class)
133134
@ImportRuntimeHints(JsonbJsonTesterRuntimeHints.class)
134135
FactoryBean<JsonbTester<?>> jsonbTesterFactoryBean(Jsonb jsonb) {

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/mockmvc/WebMvcTestWebDriverCustomScopeIntegrationTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
2424

2525
import org.springframework.beans.factory.FactoryBean;
2626
import org.springframework.beans.factory.annotation.Autowired;
27+
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
2728
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
2829
import org.springframework.context.annotation.Bean;
2930
import org.springframework.context.annotation.Configuration;
@@ -63,7 +64,7 @@ void shouldBeTheSameWebClient() {
6364
static class Config {
6465

6566
@Bean
66-
@Scope("singleton")
67+
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
6768
WebDriverFactory webDriver(MockMvc mockMvc) {
6869
return new WebDriverFactory(mockMvc);
6970
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.springframework.beans.factory.ObjectProvider;
4949
import org.springframework.beans.factory.annotation.Autowired;
5050
import org.springframework.beans.factory.annotation.Value;
51+
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
5152
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
5253
import org.springframework.beans.factory.support.AbstractBeanDefinition;
5354
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
@@ -1497,7 +1498,7 @@ static PropertySourcesPlaceholderConfigurer configurer2() {
14971498
static class PrototypePropertiesConfiguration {
14981499

14991500
@Bean
1500-
@Scope("prototype")
1501+
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
15011502
@ConfigurationProperties("example")
15021503
PrototypeBean prototypeBean() {
15031504
return new PrototypeBean();

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContextTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@
3535
import org.springframework.context.annotation.ScopedProxyMode;
3636
import org.springframework.stereotype.Component;
3737
import org.springframework.web.context.ServletContextAware;
38+
import org.springframework.web.context.WebApplicationContext;
3839
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
3940

4041
import static org.assertj.core.api.Assertions.assertThat;
@@ -154,7 +155,7 @@ public void service(ServletRequest req, ServletResponse res) {
154155
}
155156

156157
@Component
157-
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
158+
@Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
158159
static class SessionScopedComponent {
159160

160161
}

0 commit comments

Comments
 (0)