SimpleTaskConfiguration ignores proxy beans when validating datasources

If a user adds spring-cloud-starter-config to the dependencies it has to add a proxy for the datasource else the Hikari connection pool pukes.

resolves #407
This commit is contained in:
Glenn Renfro
2018-03-15 09:18:47 -04:00
committed by Michael Minella
parent 09ff552b8d
commit 5672b326ed
2 changed files with 75 additions and 12 deletions

View File

@@ -16,7 +16,9 @@
package org.springframework.cloud.task.configuration;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
@@ -24,6 +26,7 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.scope.ScopedProxyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -175,9 +178,11 @@ public class SimpleTaskConfiguration {
}
}
private void verifyEnvironment(){
private void verifyEnvironment() {
int configurers = this.context.getBeanNamesForType(TaskConfigurer.class).length;
int dataSources = this.context.getBeanNamesForType(DataSource.class).length;
// retrieve the count of dataSources (without instantiating them) excluding DataSource proxy beans
long dataSources = Arrays.stream(this.context.getBeanNamesForType(DataSource.class))
.filter((name -> !ScopedProxyUtils.isScopedTarget(name))).collect(Collectors.counting());
if(configurers == 0 && dataSources > 1) {
throw new IllegalStateException("To use the default TaskConfigurer the context must contain no more than" +