Skip to content

Commit 821ee0c

Browse files
committed
Ensure that @bean methods are only declared on @configuration classes
Closes spring-projectsgh-16190
1 parent 3fdf281 commit 821ee0c

File tree

20 files changed

+73
-24
lines changed

20 files changed

+73
-24
lines changed

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -334,6 +334,7 @@ public void contribute(Info.Builder builder) {
334334

335335
}
336336

337+
@Configuration
337338
static class DataSourceConfig {
338339

339340
@Bean

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcManagementContextConfigurationTests.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -198,6 +198,7 @@ public HealthMvcEndpoint testHealthMvcEndpoint(HealthEndpoint endpoint) {
198198

199199
}
200200

201+
@Configuration
201202
static class EnvConfiguration {
202203

203204
@Bean
@@ -208,6 +209,7 @@ public EnvironmentMvcEndpoint testEnvironmentMvcEndpoint(
208209

209210
}
210211

212+
@Configuration
211213
static class MetricsConfiguration {
212214

213215
@Bean
@@ -217,6 +219,7 @@ public MetricsMvcEndpoint testMetricsMvcEndpoint(MetricsEndpoint endpoint) {
217219

218220
}
219221

222+
@Configuration
220223
static class LoggersConfiguration {
221224

222225
@Bean
@@ -236,6 +239,7 @@ public void beforeInitialize() {
236239

237240
}
238241

242+
@Configuration
239243
static class LogFileConfiguration {
240244

241245
@Bean
@@ -245,6 +249,7 @@ public LogFileMvcEndpoint testLogFileMvcEndpoint() {
245249

246250
}
247251

252+
@Configuration
248253
static class AuditEventsConfiguration {
249254

250255
@Bean
@@ -264,6 +269,7 @@ static class TestAuditEventRepository extends InMemoryAuditEventRepository {
264269

265270
}
266271

272+
@Configuration
267273
static class HeapdumpConfiguration {
268274

269275
@Bean
@@ -273,6 +279,7 @@ public HeapdumpMvcEndpoint testHeapdumpMvcEndpoint() {
273279

274280
}
275281

282+
@Configuration
276283
static class ShutdownConfiguration {
277284

278285
@Bean

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -627,6 +627,7 @@ public CouchbaseOperations couchbaseOperations() {
627627

628628
}
629629

630+
@Configuration
630631
protected static class JestClientConfiguration {
631632

632633
@Bean

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/dao/PersistenceExceptionTranslationAutoConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -22,6 +22,7 @@
2222
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2323
import org.springframework.boot.bind.RelaxedPropertyResolver;
2424
import org.springframework.context.annotation.Bean;
25+
import org.springframework.context.annotation.Configuration;
2526
import org.springframework.core.env.Environment;
2627
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
2728

@@ -33,6 +34,7 @@
3334
* @author Stephane Nicoll
3435
* @since 1.2.0
3536
*/
37+
@Configuration
3638
@ConditionalOnClass(PersistenceExceptionTranslationPostProcessor.class)
3739
public class PersistenceExceptionTranslationAutoConfiguration {
3840

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hateoas/HypermediaHttpMessageConverterConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -29,6 +29,7 @@
2929
import org.springframework.beans.factory.config.BeanPostProcessor;
3030
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
3131
import org.springframework.context.annotation.Bean;
32+
import org.springframework.context.annotation.Configuration;
3233
import org.springframework.hateoas.mvc.TypeConstrainedMappingJackson2HttpMessageConverter;
3334
import org.springframework.http.MediaType;
3435
import org.springframework.http.converter.AbstractHttpMessageConverter;
@@ -41,6 +42,7 @@
4142
*
4243
* @author Andy Wilkinson
4344
*/
45+
@Configuration
4446
public class HypermediaHttpMessageConverterConfiguration {
4547

4648
@Bean

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -26,6 +26,7 @@
2626
import org.springframework.boot.context.properties.ConfigurationProperties;
2727
import org.springframework.boot.jdbc.DatabaseDriver;
2828
import org.springframework.context.annotation.Bean;
29+
import org.springframework.context.annotation.Configuration;
2930

3031
/**
3132
* Actual DataSource configurations imported by {@link DataSourceAutoConfiguration}.
@@ -45,6 +46,7 @@ protected static <T> T createDataSource(DataSourceProperties properties,
4546
/**
4647
* Tomcat Pool DataSource configuration.
4748
*/
49+
@Configuration
4850
@ConditionalOnClass(org.apache.tomcat.jdbc.pool.DataSource.class)
4951
@ConditionalOnMissingBean(DataSource.class)
5052
@ConditionalOnProperty(name = "spring.datasource.type", havingValue = "org.apache.tomcat.jdbc.pool.DataSource", matchIfMissing = true)
@@ -71,6 +73,7 @@ public org.apache.tomcat.jdbc.pool.DataSource dataSource(
7173
/**
7274
* Hikari DataSource configuration.
7375
*/
76+
@Configuration
7477
@ConditionalOnClass(HikariDataSource.class)
7578
@ConditionalOnMissingBean(DataSource.class)
7679
@ConditionalOnProperty(name = "spring.datasource.type", havingValue = "com.zaxxer.hikari.HikariDataSource", matchIfMissing = true)
@@ -89,6 +92,7 @@ public HikariDataSource dataSource(DataSourceProperties properties) {
8992
*
9093
* @deprecated as of 1.5 in favor of DBCP2
9194
*/
95+
@Configuration
9296
@ConditionalOnClass(org.apache.commons.dbcp.BasicDataSource.class)
9397
@ConditionalOnMissingBean(DataSource.class)
9498
@ConditionalOnProperty(name = "spring.datasource.type", havingValue = "org.apache.commons.dbcp.BasicDataSource", matchIfMissing = true)
@@ -116,6 +120,7 @@ public org.apache.commons.dbcp.BasicDataSource dataSource(
116120
/**
117121
* DBCP DataSource configuration.
118122
*/
123+
@Configuration
119124
@ConditionalOnClass(org.apache.commons.dbcp2.BasicDataSource.class)
120125
@ConditionalOnMissingBean(DataSource.class)
121126
@ConditionalOnProperty(name = "spring.datasource.type", havingValue = "org.apache.commons.dbcp2.BasicDataSource", matchIfMissing = true)
@@ -134,6 +139,7 @@ public org.apache.commons.dbcp2.BasicDataSource dataSource(
134139
/**
135140
* Generic DataSource configuration.
136141
*/
142+
@Configuration
137143
@ConditionalOnMissingBean(DataSource.class)
138144
@ConditionalOnProperty(name = "spring.datasource.type")
139145
static class Generic {

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -34,6 +34,7 @@
3434
import org.springframework.boot.jdbc.DatabaseDriver;
3535
import org.springframework.boot.jta.XADataSourceWrapper;
3636
import org.springframework.context.annotation.Bean;
37+
import org.springframework.context.annotation.Configuration;
3738
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
3839
import org.springframework.util.Assert;
3940
import org.springframework.util.ClassUtils;
@@ -46,6 +47,7 @@
4647
* @author Josh Long
4748
* @since 1.2.0
4849
*/
50+
@Configuration
4951
@AutoConfigureBefore(DataSourceAutoConfiguration.class)
5052
@EnableConfigurationProperties(DataSourceProperties.class)
5153
@ConditionalOnClass({ DataSource.class, TransactionManager.class,

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -371,6 +371,7 @@ public JobExplorer getJobExplorer() throws Exception {
371371
}
372372

373373
@EnableBatchProcessing
374+
@Configuration
374375
protected static class NamedJobConfigurationWithRegisteredJob {
375376

376377
@Autowired
@@ -413,6 +414,7 @@ protected void doExecute(JobExecution execution)
413414
}
414415

415416
@EnableBatchProcessing
417+
@Configuration
416418
protected static class NamedJobConfigurationWithLocalJob {
417419

418420
@Autowired
@@ -444,6 +446,7 @@ protected void doExecute(JobExecution execution)
444446

445447
}
446448

449+
@Configuration
447450
@EnableBatchProcessing
448451
protected static class JobConfiguration {
449452

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnPropertyTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -434,6 +434,7 @@ public String foo() {
434434

435435
}
436436

437+
@Configuration
437438
@ConditionalOnMyFeature
438439
protected static class MetaAnnotation {
439440

@@ -444,6 +445,7 @@ public String foo() {
444445

445446
}
446447

448+
@Configuration
447449
@ConditionalOnMyFeature
448450
@ConditionalOnProperty(prefix = "my.other.feature", name = "enabled", havingValue = "true", matchIfMissing = false)
449451
protected static class MetaAnnotationAndDirectAnnotation {

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JndiDataSourceAutoConfigurationTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -33,6 +33,7 @@
3333
import org.springframework.boot.test.util.EnvironmentTestUtils;
3434
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
3535
import org.springframework.context.annotation.Bean;
36+
import org.springframework.context.annotation.Configuration;
3637
import org.springframework.jmx.export.MBeanExporter;
3738

3839
import static org.assertj.core.api.Assertions.assertThat;
@@ -167,7 +168,8 @@ private void configureJndi(String name, DataSource dataSource)
167168
TestableInitialContextFactory.bind(name, dataSource);
168169
}
169170

170-
private static class MBeanExporterConfiguration {
171+
@Configuration
172+
static class MBeanExporterConfiguration {
171173

172174
@Bean
173175
MBeanExporter mbeanExporter() {
@@ -176,7 +178,8 @@ MBeanExporter mbeanExporter() {
176178

177179
}
178180

179-
private static class AnotherMBeanExporterConfiguration {
181+
@Configuration
182+
static class AnotherMBeanExporterConfiguration {
180183

181184
@Bean
182185
MBeanExporter anotherMbeanExporter() {

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationIntegrationTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -29,6 +29,7 @@
2929
import org.springframework.boot.test.util.EnvironmentTestUtils;
3030
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
3131
import org.springframework.context.annotation.Bean;
32+
import org.springframework.context.annotation.Configuration;
3233
import org.springframework.kafka.annotation.KafkaListener;
3334
import org.springframework.kafka.core.KafkaTemplate;
3435
import org.springframework.kafka.support.KafkaHeaders;
@@ -98,6 +99,7 @@ private boolean isWindows() {
9899
return File.separatorChar == '\\';
99100
}
100101

102+
@Configuration
101103
public static class KafkaConfig {
102104

103105
@Bean

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -324,6 +324,7 @@ public Object extractPrincipal(Map<String, Object> map) {
324324

325325
}
326326

327+
@Configuration
327328
@Import({ OAuth2RestOperationsConfiguration.class })
328329
protected static class ResourceNoClientConfiguration extends ResourceConfiguration {
329330

@@ -351,6 +352,7 @@ public ResourceServerProperties resourceServerProperties() {
351352

352353
}
353354

355+
@Configuration
354356
@Import({ FacebookAutoConfiguration.class, SocialWebAutoConfiguration.class })
355357
protected static class SocialResourceConfiguration extends ResourceConfiguration {
356358

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -373,6 +373,7 @@ WebController webController() {
373373

374374
}
375375

376+
@Configuration
376377
public static class ContainerWithCustomMultipartResolver {
377378

378379
@Bean
@@ -382,6 +383,7 @@ MultipartResolver multipartResolver() {
382383

383384
}
384385

386+
@Configuration
385387
public static class ContainerWithCommonsMultipartResolver {
386388

387389
@Bean

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketAutoConfigurationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -89,6 +89,7 @@ private void serverContainerIsAvailableFromTheServletContext(
8989

9090
}
9191

92+
@Configuration
9293
static class CommonConfiguration {
9394

9495
@Bean

0 commit comments

Comments
 (0)