Remove runComponents from SpringApplication
It was basically duplicating run(Object[], String[]) - unless there is some harm in registering a non-component with the context that I haven't seen yet.
This commit is contained in:
parent
5501adc862
commit
4d372bcc25
|
|
@ -47,8 +47,6 @@ import org.springframework.core.env.SimpleCommandLinePropertySource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.core.io.ResourceLoader;
|
import org.springframework.core.io.ResourceLoader;
|
||||||
import org.springframework.core.io.support.SpringFactoriesLoader;
|
import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||||
import org.springframework.core.type.StandardAnnotationMetadata;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.web.context.ConfigurableWebApplicationContext;
|
import org.springframework.web.context.ConfigurableWebApplicationContext;
|
||||||
|
|
@ -565,23 +563,4 @@ public class SpringApplication {
|
||||||
return new SpringApplication(sources).run(args);
|
return new SpringApplication(sources).run(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Static helper that can be used to run a {@link SpringApplication} from the
|
|
||||||
* specified {@code @Component} sources. Any class not annotated or meta-annotated
|
|
||||||
* with {@code @Component} will be ignored.
|
|
||||||
* @param classes the source classes to consider loading
|
|
||||||
* @param args the application arguments (usually passed from a Java main method)
|
|
||||||
* @return the running {@link ApplicationContext}
|
|
||||||
*/
|
|
||||||
public static ApplicationContext runComponents(Class<?>[] classes, String... args) {
|
|
||||||
List<Class<?>> componentClasses = new ArrayList<Class<?>>();
|
|
||||||
for (Class<?> candidate : classes) {
|
|
||||||
StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(
|
|
||||||
candidate);
|
|
||||||
if (metadata.isAnnotated(Component.class.getName())) {
|
|
||||||
componentClasses.add(candidate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new SpringApplication(componentClasses.toArray()).run(args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -274,8 +274,8 @@ public class SpringApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void runComponents() throws Exception {
|
public void runComponents() throws Exception {
|
||||||
this.context = SpringApplication.runComponents(new Class<?>[] {
|
this.context = SpringApplication.run(new Object[] { ExampleWebConfig.class,
|
||||||
ExampleWebConfig.class, Object.class });
|
Object.class }, new String[0]);
|
||||||
assertNotNull(this.context);
|
assertNotNull(this.context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue