Remove use of `@PostConstruct` from main code

When running on Java 11 (where `@PostConstruct` is no longer part of
the JRE) and without a dependency on jakarta-annotation-api,
`@PostContruct` annotions are silently dropped. This leads to obscure and
hard-to-track down changes in the behaviour of our auto-configuration
as the `@PostConstruct`-annotated methods are not invoked.

To allow users to run on Java 11 without having jakarta-annotation-api
on the classpath, this commit removes use of `@PostConstruct` from main
code. A Checkstyle rule has also been added to prevent its usage in
main code from being reintroduced.

Closes gh-23723
pull/24789/head
Andy Wilkinson 4 years ago
parent 622606d85a
commit 30a0ccab02

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,8 +21,6 @@ import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import javax.annotation.PostConstruct;
import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.model.Resource; import org.glassfish.jersey.server.model.Resource;
@ -112,10 +110,10 @@ class JerseyWebEndpointManagementContextConfiguration {
this.mediaTypes = endpointMediaTypes; this.mediaTypes = endpointMediaTypes;
this.basePath = basePath; this.basePath = basePath;
this.shouldRegisterLinks = shouldRegisterLinks; this.shouldRegisterLinks = shouldRegisterLinks;
register();
} }
@PostConstruct private void register() {
void register() {
// We can't easily use @ConditionalOnBean because @AutoConfigureBefore is // We can't easily use @ConditionalOnBean because @AutoConfigureBefore is
// not an option for management contexts. Instead we manually check if // not an option for management contexts. Instead we manually check if
// the resource config bean exists // the resource config bean exists

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,8 +19,6 @@ package org.springframework.boot.actuate.autoconfigure.metrics.cache;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import javax.annotation.PostConstruct;
import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.Tag;
@ -56,6 +54,7 @@ class CacheMetricsRegistrarConfiguration {
this.registry = registry; this.registry = registry;
this.cacheManagers = cacheManagers; this.cacheManagers = cacheManagers;
this.cacheMetricsRegistrar = new CacheMetricsRegistrar(this.registry, binderProviders); this.cacheMetricsRegistrar = new CacheMetricsRegistrar(this.registry, binderProviders);
bindCachesToRegistry();
} }
@Bean @Bean
@ -63,8 +62,7 @@ class CacheMetricsRegistrarConfiguration {
return this.cacheMetricsRegistrar; return this.cacheMetricsRegistrar;
} }
@PostConstruct private void bindCachesToRegistry() {
void bindCachesToRegistry() {
this.cacheManagers.forEach(this::bindCacheManagerToRegistry); this.cacheManagers.forEach(this::bindCacheManagerToRegistry);
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,6 @@
package org.springframework.boot.autoconfigure.batch; package org.springframework.boot.autoconfigure.batch;
import javax.annotation.PostConstruct;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.springframework.batch.core.configuration.annotation.BatchConfigurer; import org.springframework.batch.core.configuration.annotation.BatchConfigurer;
@ -26,6 +25,7 @@ import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.launch.support.SimpleJobLauncher; import org.springframework.batch.core.launch.support.SimpleJobLauncher;
import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers; import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.DataSourceTransactionManager;
@ -40,7 +40,7 @@ import org.springframework.transaction.PlatformTransactionManager;
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 1.0.0 * @since 1.0.0
*/ */
public class BasicBatchConfigurer implements BatchConfigurer { public class BasicBatchConfigurer implements BatchConfigurer, InitializingBean {
private final BatchProperties properties; private final BatchProperties properties;
@ -90,7 +90,11 @@ public class BasicBatchConfigurer implements BatchConfigurer {
return this.jobExplorer; return this.jobExplorer;
} }
@PostConstruct @Override
public void afterPropertiesSet() {
initialize();
}
public void initialize() { public void initialize() {
try { try {
this.transactionManager = buildTransactionManager(); this.transactionManager = buildTransactionManager();

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,8 +19,6 @@ package org.springframework.boot.autoconfigure.freemarker;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.annotation.PostConstruct;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -57,9 +55,9 @@ public class FreeMarkerAutoConfiguration {
public FreeMarkerAutoConfiguration(ApplicationContext applicationContext, FreeMarkerProperties properties) { public FreeMarkerAutoConfiguration(ApplicationContext applicationContext, FreeMarkerProperties properties) {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
this.properties = properties; this.properties = properties;
checkTemplateLocationExists();
} }
@PostConstruct
public void checkTemplateLocationExists() { public void checkTemplateLocationExists() {
if (logger.isWarnEnabled() && this.properties.isCheckTemplateLocation()) { if (logger.isWarnEnabled() && this.properties.isCheckTemplateLocation()) {
List<TemplateLocation> locations = getLocations(); List<TemplateLocation> locations = getLocations();

@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.groovy.template;
import java.security.CodeSource; import java.security.CodeSource;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
import javax.annotation.PostConstruct;
import javax.servlet.Servlet; import javax.servlet.Servlet;
import groovy.text.markup.MarkupTemplateEngine; import groovy.text.markup.MarkupTemplateEngine;
@ -77,9 +76,9 @@ public class GroovyTemplateAutoConfiguration {
public GroovyMarkupConfiguration(ApplicationContext applicationContext, GroovyTemplateProperties properties) { public GroovyMarkupConfiguration(ApplicationContext applicationContext, GroovyTemplateProperties properties) {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
this.properties = properties; this.properties = properties;
checkTemplateLocationExists();
} }
@PostConstruct
public void checkTemplateLocationExists() { public void checkTemplateLocationExists() {
if (this.properties.isCheckTemplateLocation() && !isUsingGroovyAllJar()) { if (this.properties.isCheckTemplateLocation() && !isUsingGroovyAllJar()) {
TemplateLocation location = new TemplateLocation(this.properties.getResourceLoaderPath()); TemplateLocation location = new TemplateLocation(this.properties.getResourceLoaderPath());

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,11 +20,10 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import javax.annotation.PostConstruct;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@ -60,12 +59,13 @@ public class HypermediaHttpMessageConverterConfiguration {
* {@code Jackson2ModuleRegisteringBeanPostProcessor} has registered the converter and * {@code Jackson2ModuleRegisteringBeanPostProcessor} has registered the converter and
* it is unordered. * it is unordered.
*/ */
private static class HalMessageConverterSupportedMediaTypesCustomizer implements BeanFactoryAware { private static class HalMessageConverterSupportedMediaTypesCustomizer
implements BeanFactoryAware, InitializingBean {
private volatile BeanFactory beanFactory; private volatile BeanFactory beanFactory;
@PostConstruct @Override
void configureHttpMessageConverters() { public void afterPropertiesSet() {
if (this.beanFactory instanceof ListableBeanFactory) { if (this.beanFactory instanceof ListableBeanFactory) {
configureHttpMessageConverters(((ListableBeanFactory) this.beanFactory) configureHttpMessageConverters(((ListableBeanFactory) this.beanFactory)
.getBeansOfType(RequestMappingHandlerAdapter.class).values()); .getBeansOfType(RequestMappingHandlerAdapter.class).values());

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.jdbc;
import java.sql.SQLException; import java.sql.SQLException;
import javax.annotation.PostConstruct;
import javax.sql.DataSource; import javax.sql.DataSource;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
@ -59,10 +58,10 @@ class DataSourceJmxConfiguration {
Hikari(DataSource dataSource, ObjectProvider<MBeanExporter> mBeanExporter) { Hikari(DataSource dataSource, ObjectProvider<MBeanExporter> mBeanExporter) {
this.dataSource = dataSource; this.dataSource = dataSource;
this.mBeanExporter = mBeanExporter; this.mBeanExporter = mBeanExporter;
validateMBeans();
} }
@PostConstruct private void validateMBeans() {
void validateMBeans() {
HikariDataSource hikariDataSource = DataSourceUnwrapper.unwrap(this.dataSource, HikariDataSource.class); HikariDataSource hikariDataSource = DataSourceUnwrapper.unwrap(this.dataSource, HikariDataSource.class);
if (hikariDataSource != null && hikariDataSource.isRegisterMbeans()) { if (hikariDataSource != null && hikariDataSource.isRegisterMbeans()) {
this.mBeanExporter.ifUnique((exporter) -> exporter.addExcludedBean("dataSource")); this.mBeanExporter.ifUnique((exporter) -> exporter.addExcludedBean("dataSource"));

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.jersey;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import javax.annotation.PostConstruct;
import javax.servlet.DispatcherType; import javax.servlet.DispatcherType;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -95,22 +94,11 @@ public class JerseyAutoConfiguration implements ServletContextAware {
private final ResourceConfig config; private final ResourceConfig config;
private final ObjectProvider<ResourceConfigCustomizer> customizers;
public JerseyAutoConfiguration(JerseyProperties jersey, ResourceConfig config, public JerseyAutoConfiguration(JerseyProperties jersey, ResourceConfig config,
ObjectProvider<ResourceConfigCustomizer> customizers) { ObjectProvider<ResourceConfigCustomizer> customizers) {
this.jersey = jersey; this.jersey = jersey;
this.config = config; this.config = config;
this.customizers = customizers; customizers.orderedStream().forEach((customizer) -> customizer.customize(this.config));
}
@PostConstruct
public void path() {
customize();
}
private void customize() {
this.customizers.orderedStream().forEach((customizer) -> customizer.customize(this.config));
} }
@Bean @Bean

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,6 @@
package org.springframework.boot.autoconfigure.mail; package org.springframework.boot.autoconfigure.mail;
import javax.annotation.PostConstruct;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
@ -44,9 +43,9 @@ public class MailSenderValidatorAutoConfiguration {
public MailSenderValidatorAutoConfiguration(JavaMailSenderImpl mailSender) { public MailSenderValidatorAutoConfiguration(JavaMailSenderImpl mailSender) {
this.mailSender = mailSender; this.mailSender = mailSender;
validateConnection();
} }
@PostConstruct
public void validateConnection() { public void validateConnection() {
try { try {
this.mailSender.testConnection(); this.mailSender.testConnection();

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,8 +16,6 @@
package org.springframework.boot.autoconfigure.mustache; package org.springframework.boot.autoconfigure.mustache;
import javax.annotation.PostConstruct;
import com.samskivert.mustache.Mustache; import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Mustache.Collector; import com.samskivert.mustache.Mustache.Collector;
import com.samskivert.mustache.Mustache.TemplateLoader; import com.samskivert.mustache.Mustache.TemplateLoader;
@ -57,9 +55,9 @@ public class MustacheAutoConfiguration {
public MustacheAutoConfiguration(MustacheProperties mustache, ApplicationContext applicationContext) { public MustacheAutoConfiguration(MustacheProperties mustache, ApplicationContext applicationContext) {
this.mustache = mustache; this.mustache = mustache;
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
checkTemplateLocationExists();
} }
@PostConstruct
public void checkTemplateLocationExists() { public void checkTemplateLocationExists() {
if (this.mustache.isCheckTemplateLocation()) { if (this.mustache.isCheckTemplateLocation()) {
TemplateLocation location = new TemplateLocation(this.mustache.getPrefix()); TemplateLocation location = new TemplateLocation(this.mustache.getPrefix());

@ -20,8 +20,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.annotation.PostConstruct; import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -35,7 +34,7 @@ import org.springframework.util.StringUtils;
* @since 2.0.0 * @since 2.0.0
*/ */
@ConfigurationProperties(prefix = "spring.security.oauth2.client") @ConfigurationProperties(prefix = "spring.security.oauth2.client")
public class OAuth2ClientProperties { public class OAuth2ClientProperties implements InitializingBean {
/** /**
* OAuth provider details. * OAuth provider details.
@ -55,7 +54,11 @@ public class OAuth2ClientProperties {
return this.registration; return this.registration;
} }
@PostConstruct @Override
public void afterPropertiesSet() {
validate();
}
public void validate() { public void validate() {
this.getRegistration().values().forEach(this::validateRegistration); this.getRegistration().values().forEach(this::validateRegistration);
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,8 +19,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import javax.annotation.PostConstruct; import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException; import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
@ -35,7 +34,7 @@ import org.springframework.util.StreamUtils;
* @since 2.1.0 * @since 2.1.0
*/ */
@ConfigurationProperties(prefix = "spring.security.oauth2.resourceserver") @ConfigurationProperties(prefix = "spring.security.oauth2.resourceserver")
public class OAuth2ResourceServerProperties { public class OAuth2ResourceServerProperties implements InitializingBean {
private final Jwt jwt = new Jwt(); private final Jwt jwt = new Jwt();
@ -49,7 +48,11 @@ public class OAuth2ResourceServerProperties {
return this.opaqueToken; return this.opaqueToken;
} }
@PostConstruct @Override
public void afterPropertiesSet() throws Exception {
validate();
}
public void validate() { public void validate() {
if (this.getOpaquetoken().getIntrospectionUri() != null) { if (this.getOpaquetoken().getIntrospectionUri() != null) {
if (this.getJwt().getJwkSetUri() != null) { if (this.getJwt().getJwkSetUri() != null) {

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,8 +21,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import javax.annotation.PostConstruct; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.WebApplicationType; import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
@ -226,10 +225,10 @@ public class SessionAutoConfiguration {
this.classLoader = applicationContext.getClassLoader(); this.classLoader = applicationContext.getClassLoader();
this.sessionProperties = sessionProperties; this.sessionProperties = sessionProperties;
this.candidates = candidates; this.candidates = candidates;
checkAvailableImplementations();
} }
@PostConstruct private void checkAvailableImplementations() {
void checkAvailableImplementations() {
List<Class<?>> availableCandidates = new ArrayList<>(); List<Class<?>> availableCandidates = new ArrayList<>();
for (String candidate : this.candidates) { for (String candidate : this.candidates) {
addCandidateIfAvailable(availableCandidates, candidate); addCandidateIfAvailable(availableCandidates, candidate);
@ -291,7 +290,7 @@ public class SessionAutoConfiguration {
/** /**
* Base class for validating that a (reactive) session repository bean exists. * Base class for validating that a (reactive) session repository bean exists.
*/ */
abstract static class AbstractSessionRepositoryValidator { abstract static class AbstractSessionRepositoryValidator implements InitializingBean {
private final SessionProperties sessionProperties; private final SessionProperties sessionProperties;
@ -303,8 +302,8 @@ public class SessionAutoConfiguration {
this.sessionRepositoryProvider = sessionRepositoryProvider; this.sessionRepositoryProvider = sessionRepositoryProvider;
} }
@PostConstruct @Override
void checkSessionRepository() { public void afterPropertiesSet() {
StoreType storeType = this.sessionProperties.getStoreType(); StoreType storeType = this.sessionProperties.getStoreType();
if (storeType != StoreType.NONE && this.sessionRepositoryProvider.getIfAvailable() == null if (storeType != StoreType.NONE && this.sessionRepositoryProvider.getIfAvailable() == null
&& storeType != null) { && storeType != null) {

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.thymeleaf;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import javax.annotation.PostConstruct;
import javax.servlet.DispatcherType; import javax.servlet.DispatcherType;
import com.github.mxab.thymeleaf.extras.dataattribute.dialect.DataAttributeDialect; import com.github.mxab.thymeleaf.extras.dataattribute.dialect.DataAttributeDialect;
@ -95,10 +94,10 @@ public class ThymeleafAutoConfiguration {
DefaultTemplateResolverConfiguration(ThymeleafProperties properties, ApplicationContext applicationContext) { DefaultTemplateResolverConfiguration(ThymeleafProperties properties, ApplicationContext applicationContext) {
this.properties = properties; this.properties = properties;
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
checkTemplateLocationExists();
} }
@PostConstruct private void checkTemplateLocationExists() {
void checkTemplateLocationExists() {
boolean checkTemplateLocation = this.properties.isCheckTemplateLocation(); boolean checkTemplateLocation = this.properties.isCheckTemplateLocation();
if (checkTemplateLocation) { if (checkTemplateLocation) {
TemplateLocation location = new TemplateLocation(this.properties.getPrefix()); TemplateLocation location = new TemplateLocation(this.properties.getPrefix());

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -48,7 +48,7 @@ class SessionAutoConfigurationIntegrationTests extends AbstractSessionAutoConfig
void severalCandidatesWithNoSessionStore() { void severalCandidatesWithNoSessionStore() {
this.contextRunner.withUserConfiguration(HazelcastConfiguration.class).run((context) -> { this.contextRunner.withUserConfiguration(HazelcastConfiguration.class).run((context) -> {
assertThat(context).hasFailed(); assertThat(context).hasFailed();
assertThat(context).getFailure().hasCauseInstanceOf(NonUniqueSessionRepositoryException.class); assertThat(context).getFailure().hasRootCauseInstanceOf(NonUniqueSessionRepositoryException.class);
assertThat(context).getFailure() assertThat(context).getFailure()
.hasMessageContaining("Multiple session repository candidates are available"); .hasMessageContaining("Multiple session repository candidates are available");
assertThat(context).getFailure() assertThat(context).getFailure()

@ -62,7 +62,7 @@ class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurationTest
void contextFailsIfMultipleStoresAreAvailable() { void contextFailsIfMultipleStoresAreAvailable() {
this.contextRunner.run((context) -> { this.contextRunner.run((context) -> {
assertThat(context).hasFailed(); assertThat(context).hasFailed();
assertThat(context).getFailure().hasCauseInstanceOf(NonUniqueSessionRepositoryException.class); assertThat(context).getFailure().hasRootCauseInstanceOf(NonUniqueSessionRepositoryException.class);
assertThat(context).getFailure() assertThat(context).getFailure()
.hasMessageContaining("Multiple session repository candidates are available"); .hasMessageContaining("Multiple session repository candidates are available");
}); });

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,8 +20,6 @@ import java.lang.reflect.Modifier;
import java.util.Map; import java.util.Map;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import javax.annotation.PostConstruct;
import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.KeyDeserializer; import com.fasterxml.jackson.databind.KeyDeserializer;
@ -33,6 +31,7 @@ import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.HierarchicalBeanFactory; import org.springframework.beans.factory.HierarchicalBeanFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.boot.jackson.JsonComponent.Scope; import org.springframework.boot.jackson.JsonComponent.Scope;
import org.springframework.core.ResolvableType; import org.springframework.core.ResolvableType;
@ -51,7 +50,7 @@ import org.springframework.util.ObjectUtils;
* @since 1.4.0 * @since 1.4.0
* @see JsonComponent * @see JsonComponent
*/ */
public class JsonComponentModule extends SimpleModule implements BeanFactoryAware { public class JsonComponentModule extends SimpleModule implements BeanFactoryAware, InitializingBean {
private BeanFactory beanFactory; private BeanFactory beanFactory;
@ -60,7 +59,11 @@ public class JsonComponentModule extends SimpleModule implements BeanFactoryAwar
this.beanFactory = beanFactory; this.beanFactory = beanFactory;
} }
@PostConstruct @Override
public void afterPropertiesSet() {
registerJsonComponents();
}
public void registerJsonComponents() { public void registerJsonComponents() {
BeanFactory beanFactory = this.beanFactory; BeanFactory beanFactory = this.beanFactory;
while (beanFactory != null) { while (beanFactory != null) {

@ -18,9 +18,9 @@ package org.springframework.boot.jdbc;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import javax.annotation.PostConstruct;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils; import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
@ -35,7 +35,7 @@ import org.springframework.util.Assert;
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 1.5.0 * @since 1.5.0
*/ */
public abstract class AbstractDataSourceInitializer { public abstract class AbstractDataSourceInitializer implements InitializingBean {
private static final String PLATFORM_PLACEHOLDER = "@@platform@@"; private static final String PLATFORM_PLACEHOLDER = "@@platform@@";
@ -50,7 +50,11 @@ public abstract class AbstractDataSourceInitializer {
this.resourceLoader = resourceLoader; this.resourceLoader = resourceLoader;
} }
@PostConstruct @Override
public void afterPropertiesSet() {
initialize();
}
protected void initialize() { protected void initialize() {
if (!isEnabled()) { if (!isEnabled()) {
return; return;

@ -13,12 +13,14 @@
<suppress files="[\\/]src[\\/]main[\\/]java[\\/]sample[\\/]" checks="ImportControl" /> <suppress files="[\\/]src[\\/]main[\\/]java[\\/]sample[\\/]" checks="ImportControl" />
<suppress files="[\\/]src[\\/]test[\\/]java[\\/]sample[\\/]" checks="ImportControl" /> <suppress files="[\\/]src[\\/]test[\\/]java[\\/]sample[\\/]" checks="ImportControl" />
<suppress files="[\\/]src[\\/]test[\\/]java[\\/]" checks="Javadoc*" /> <suppress files="[\\/]src[\\/]test[\\/]java[\\/]" checks="Javadoc*" />
<suppress files="[\\/]src[\\/]test[\\/]java[\\/]" id="mainCodeIllegalImportCheck" />
<suppress files="[\\/]src[\\/]test[\\/]java[\\/]" checks="NonEmptyAtclauseDescription" /> <suppress files="[\\/]src[\\/]test[\\/]java[\\/]" checks="NonEmptyAtclauseDescription" />
<suppress files="[\\/]autoconfigure[\\/]" checks="JavadocType" /> <suppress files="[\\/]autoconfigure[\\/]" checks="JavadocType" />
<suppress files="[\\/]autoconfigure[\\/]" checks="JavadocVariable" /> <suppress files="[\\/]autoconfigure[\\/]" checks="JavadocVariable" />
<suppress files="[\\/]spring-boot-docs[\\/]" checks="JavadocType" /> <suppress files="[\\/]spring-boot-docs[\\/]" checks="JavadocType" />
<suppress files="[\\/]spring-boot-smoke-tests[\\/]" checks="JavadocType" /> <suppress files="[\\/]spring-boot-smoke-tests[\\/]" checks="JavadocType" />
<suppress files="[\\/]spring-boot-smoke-tests[\\/]" checks="ImportControl" /> <suppress files="[\\/]spring-boot-smoke-tests[\\/]" checks="ImportControl" />
<suppress files="[\\/]spring-boot-smoke-tests[\\/]" id="mainCodeIllegalImportCheck" />
<suppress files="[\\/]spring-boot-deployment-tests[\\/]" checks="JavadocType" /> <suppress files="[\\/]spring-boot-deployment-tests[\\/]" checks="JavadocType" />
<suppress files="[\\/]spring-boot-integration-tests[\\/]" checks="JavadocType" /> <suppress files="[\\/]spring-boot-integration-tests[\\/]" checks="JavadocType" />
<suppress files="Ansi.*\.java" checks="JavadocVariable" /> <suppress files="Ansi.*\.java" checks="JavadocVariable" />

@ -15,7 +15,14 @@
<property name="illegalPkgs" <property name="illegalPkgs"
value="^sun.*, ^org\.apache\.commons\.(?!compress|dbcp2|logging|pool2).*, ^com\.google\.common.*, ^io\.micrometer\.shaded.*, ^org\.flywaydb\.core\.internal.*, ^org\.testcontainers\.shaded.*" /> value="^sun.*, ^org\.apache\.commons\.(?!compress|dbcp2|logging|pool2).*, ^com\.google\.common.*, ^io\.micrometer\.shaded.*, ^org\.flywaydb\.core\.internal.*, ^org\.testcontainers\.shaded.*" />
<property name="illegalClasses" <property name="illegalClasses"
value="^com\.hazelcast\.util\.Base64, ^org\.junit\.rules\.ExpectedException, ^org\.mockito\.InjectMocks, ^org\.slf4j\.LoggerFactory, ^org.springframework.context.annotation.ScannedGenericBeanDefinition, ^reactor\.core\.support\.Assert" /> value="^com\.hazelcast\.util\.Base64, ^org\.junit\.rules\.ExpectedException, ^org\.mockito\.InjectMocks, ^org\.slf4j\.LoggerFactory, ^org.springframework.context.annotation.ScannedGenericBeanDefinition, ^reactor\.core\.support\.Assert"/>
</module>
<module
name="com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck">
<property name="id" value="mainCodeIllegalImportCheck"/>
<property name="regexp" value="true" />
<property name="illegalClasses"
value="^javax.annotation.PostConstruct"/>
</module> </module>
<module <module
name="com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheck"> name="com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheck">

Loading…
Cancel
Save