Browse Source

Merge branch '2.2.x'

pull/828/head
spencergibb 4 years ago
parent
commit
f9bc96747d
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 7
      spring-cloud-commons/src/main/java/org/springframework/cloud/configuration/SpringBootVersionVerifier.java
  2. 4
      spring-cloud-commons/src/test/java/org/springframework/cloud/configuration/SpringBootDependencyTests.java
  3. 14
      spring-cloud-context/src/main/java/org/springframework/cloud/context/named/NamedContextFactory.java
  4. 36
      spring-cloud-context/src/test/java/org/springframework/cloud/context/named/NamedContextFactoryTests.java

7
spring-cloud-commons/src/main/java/org/springframework/cloud/configuration/SpringBootVersionVerifier.java

@ -87,8 +87,11 @@ class SpringBootVersionVerifier implements CompatibilityVerifier {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Version found in Boot manifest [" + version + "]"); log.debug("Version found in Boot manifest [" + version + "]");
} }
return StringUtils.hasText(version) if (!StringUtils.hasText(version)) {
&& version.startsWith(stripWildCardFromVersion(s)); log.info("Cannot check Boot version");
return true;
}
return version.startsWith(stripWildCardFromVersion(s));
} }
String getVersionFromManifest() { String getVersionFromManifest() {

4
spring-cloud-commons/src/test/java/org/springframework/cloud/configuration/SpringBootDependencyTests.java

@ -132,7 +132,7 @@ public class SpringBootDependencyTests {
acceptedVersions) { acceptedVersions) {
@Override @Override
String getVersionFromManifest() { String getVersionFromManifest() {
return ""; return "2.1";
} }
}; };
versionVerifier.ACCEPTED_VERSIONS.clear(); versionVerifier.ACCEPTED_VERSIONS.clear();
@ -207,7 +207,7 @@ public class SpringBootDependencyTests {
acceptedVersions) { acceptedVersions) {
@Override @Override
String getVersionFromManifest() { String getVersionFromManifest() {
return ""; return "2.0";
} }
}; };
versionVerifier.ACCEPTED_VERSIONS.remove("2.1"); versionVerifier.ACCEPTED_VERSIONS.remove("2.1");

14
spring-cloud-context/src/main/java/org/springframework/cloud/context/named/NamedContextFactory.java

@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@ -143,10 +144,12 @@ public abstract class NamedContextFactory<C extends NamedContextFactory.Specific
public <T> T getInstance(String name, Class<T> type) { public <T> T getInstance(String name, Class<T> type) {
AnnotationConfigApplicationContext context = getContext(name); AnnotationConfigApplicationContext context = getContext(name);
if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors(context, try {
type).length > 0) {
return context.getBean(type); return context.getBean(type);
} }
catch (NoSuchBeanDefinitionException e) {
// ignore
}
return null; return null;
} }
@ -181,11 +184,8 @@ public abstract class NamedContextFactory<C extends NamedContextFactory.Specific
public <T> Map<String, T> getInstances(String name, Class<T> type) { public <T> Map<String, T> getInstances(String name, Class<T> type) {
AnnotationConfigApplicationContext context = getContext(name); AnnotationConfigApplicationContext context = getContext(name);
if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors(context,
type).length > 0) { return BeanFactoryUtils.beansOfTypeIncludingAncestors(context, type);
return BeanFactoryUtils.beansOfTypeIncludingAncestors(context, type);
}
return null;
} }
/** /**

36
spring-cloud-context/src/test/java/org/springframework/cloud/context/named/NamedContextFactoryTests.java

@ -54,6 +54,18 @@ public class NamedContextFactoryTests {
Bar foobar = factory.getInstance("foo", Bar.class); Bar foobar = factory.getInstance("foo", Bar.class);
then(foobar).as("bar was not null").isNull(); then(foobar).as("bar was not null").isNull();
Baz fooBaz = factory.getInstance("foo", Baz.class);
then(fooBaz).as("fooBaz was null").isNotNull();
Object fooContainerFoo = factory.getInstance("foo", Container.class, Foo.class);
then(fooContainerFoo).as("fooContainerFoo was null").isNotNull();
Object fooContainerBar = factory.getInstance("foo", Container.class, Bar.class);
then(fooContainerBar).as("fooContainerBar was not null").isNull();
Object barContainerBar = factory.getInstance("bar", Container.class, Bar.class);
then(barContainerBar).as("barContainerBar was null").isNotNull();
Map<String, Baz> fooBazes = factory.getInstances("foo", Baz.class); Map<String, Baz> fooBazes = factory.getInstances("foo", Baz.class);
then(fooBazes).as("fooBazes was null").isNotNull(); then(fooBazes).as("fooBazes was null").isNotNull();
then(fooBazes.size()).as("fooBazes size was wrong").isEqualTo(1); then(fooBazes.size()).as("fooBazes size was wrong").isEqualTo(1);
@ -146,6 +158,11 @@ public class NamedContextFactoryTests {
return new Foo(); return new Foo();
} }
@Bean
Container<Foo> fooContainer() {
return new Container<>(new Foo());
}
} }
static class Foo { static class Foo {
@ -164,10 +181,29 @@ public class NamedContextFactoryTests {
return new Baz(); return new Baz();
} }
@Bean
Container<Bar> barContainer() {
return new Container<>(new Bar());
}
} }
static class Bar { static class Bar {
} }
static class Container<T> {
private final T item;
Container(T item) {
this.item = item;
}
public T getItem() {
return this.item;
}
}
} }

Loading…
Cancel
Save