Skip to content

Commit

Permalink
[bs-175] Generic dispatcher features for SpringApplication
Browse files Browse the repository at this point in the history
* Move Spring.main into SpringApplication.main
* User can bind command line or application.properties into
SpringApplication
* User can provide sources dynamically with --spring.main.sources
(a CSV list of class names, package names or XML resource locations)
* One side effect was to make DocumentMatchers stateless

[#52830829]
  • Loading branch information
dsyer committed Jul 16, 2013
1 parent d75c1e4 commit 4ce6b64
Show file tree
Hide file tree
Showing 21 changed files with 531 additions and 414 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.springframework.autoconfigure.main.SimpleMainTests;
import org.springframework.bootstrap.SimpleMainTests;
import org.springframework.bootstrap.context.embedded.jetty.JettyEmbeddedServletContainerFactoryTests;

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.type.filter.AbstractTypeHierarchyTraversingFilter;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;

/**
* Loads bean definitions from underlying sources, including XML and JavaConfig. Acts as a
Expand Down Expand Up @@ -162,13 +166,37 @@ private int load(CharSequence source) {
if (loadedResource != null && loadedResource.exists()) {
return load(loadedResource);
}
Package packageResource = Package.getPackage(source.toString());
Package packageResource = findPackage(source);
if (packageResource != null) {
return load(packageResource);
}
throw new IllegalArgumentException("Invalid source '" + source + "'");
}

private Package findPackage(CharSequence source) {
Package pkg = Package.getPackage(source.toString());
if (pkg != null) {
return pkg;
}
try {
// Attempt to find a class in this package
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(
getClass().getClassLoader());
Resource[] resources = resolver.getResources(ClassUtils
.convertClassNameToResourcePath(source.toString()) + "/*.class");
for (Resource resource : resources) {
String className = StringUtils.stripFilenameExtension(resource
.getFilename());
load(Class.forName(source.toString() + "." + className));
break;
}
}
catch (Exception ex) {
// swallow exception and continue
}
return Package.getPackage(source.toString());
}

private boolean isComponent(Class<?> type) {
// This has to be a bit of a guess. The only way to be sure that this type is
// eligible is to make a bean definition out of it and try to instantiate it.
Expand Down
Loading

0 comments on commit 4ce6b64

Please sign in to comment.