3838import org .springframework .beans .BeansException ;
3939import org .springframework .beans .factory .config .BeanDefinition ;
4040import org .springframework .beans .factory .config .BeanDefinitionHolder ;
41+ import org .springframework .beans .factory .config .BeanPostProcessor ;
4142import org .springframework .beans .factory .config .ConfigurableListableBeanFactory ;
4243import org .springframework .beans .factory .support .BeanDefinitionRegistry ;
4344import org .springframework .beans .factory .support .BeanDefinitionRegistryPostProcessor ;
4445import org .springframework .beans .factory .support .RootBeanDefinition ;
46+ import org .springframework .boot .autoconfigure .flyway .FlywayProperties ;
4547import org .springframework .context .ApplicationContext ;
4648import org .springframework .context .ConfigurableApplicationContext ;
4749import org .springframework .context .EnvironmentAware ;
@@ -143,8 +145,6 @@ public int hashCode() {
143145
144146 protected static class EnvironmentPostProcessor implements BeanDefinitionRegistryPostProcessor {
145147
146- private static final NullPlaceholder NULL = new NullPlaceholder ();
147-
148148 private final ConfigurableEnvironment environment ;
149149
150150 public EnvironmentPostProcessor (ConfigurableEnvironment environment ) {
@@ -155,31 +155,31 @@ public EnvironmentPostProcessor(ConfigurableEnvironment environment) {
155155 public void postProcessBeanDefinitionRegistry (BeanDefinitionRegistry registry ) throws BeansException {
156156 environment .getPropertySources ().addFirst (new MapPropertySource (
157157 PreloadableEmbeddedPostgresContextCustomizer .class .getSimpleName (),
158- ImmutableMap .of (
159- "spring.test.database.replace" , "NONE" ,
160- "spring.flyway.url" , NULL ,
161- "spring.flyway.user" , NULL ,
162- "flyway.url" , NULL ,
163- "flyway.user" , NULL
164- )));
158+ ImmutableMap .of ("spring.test.database.replace" , "NONE" )));
165159 }
166160
167161 @ Override
168162 public void postProcessBeanFactory (ConfigurableListableBeanFactory beanFactory ) throws BeansException {
169163 // nothing to do
170164 }
165+ }
171166
172- protected static class NullPlaceholder {
167+ protected static class FlywayPropertiesPostProcessor implements BeanPostProcessor {
173168
174- // this method is required to hook up org.springframework.core.convert.support.FallbackObjectToStringConverter
175- public static NullPlaceholder valueOf ( String value ) {
176- throw new IllegalStateException ( "This method should never be called!" ) ;
177- }
169+ @ Override
170+ public Object postProcessBeforeInitialization ( Object bean , String beanName ) throws BeansException {
171+ return bean ;
172+ }
178173
179- @ Override
180- public String toString () {
181- return null ;
174+ @ Override
175+ public Object postProcessAfterInitialization (Object bean , String beanName ) throws BeansException {
176+ if (bean instanceof FlywayProperties ) {
177+ FlywayProperties properties = (FlywayProperties ) bean ;
178+ properties .setUrl (null );
179+ properties .setUser (null );
180+ properties .setPassword (null );
182181 }
182+ return bean ;
183183 }
184184 }
185185
@@ -218,6 +218,9 @@ public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) t
218218 if (ClassUtils .isPresent ("ru.yandex.qatools.embed.postgresql.EmbeddedPostgres" , null )) {
219219 registerBeanIfMissing (registry , "yandexPostgresProvider" , YandexPostgresDatabaseProvider .class );
220220 }
221+ if (ClassUtils .isPresent ("org.springframework.boot.autoconfigure.flyway.FlywayProperties" , null )) {
222+ registerBeanIfMissing (registry , "flywayPropertiesPostProcessor" , FlywayPropertiesPostProcessor .class );
223+ }
221224
222225 for (AutoConfigureEmbeddedDatabase databaseAnnotation : databaseAnnotations ) {
223226 DatabaseDescriptor databaseDescriptor = resolveDatabaseDescriptor (environment , databaseAnnotation );
0 commit comments