Refine SpringApplication source types
Update `SpringApplication` so that the `run` methods and constructors now require `Class<?>` arguments, rather than `Objects`. String based sources can still be loaded, but must now be set on the `getSources()` collections. `Package` and `Resource` types are no longer directly supported. This change should help IDEs offer better content assist, and will help integrations with alternative languages such as Ceylon. Users currently passing in Class references or using the `spring.main.sources` property should not be affected by this change. If an XML resource is being used, some refactoring may be required (see the changes to `SampleSpringXmlApplication` in this commit). Fixes gh-9170
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package sample.xml;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import sample.xml.service.HelloWorldService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -24,6 +26,8 @@ import org.springframework.boot.SpringApplication;
|
||||
|
||||
public class SampleSpringXmlApplication implements CommandLineRunner {
|
||||
|
||||
private static final String CONTEXT_XML = "classpath:/META-INF/application-context.xml";
|
||||
|
||||
@Autowired
|
||||
private HelloWorldService helloWorldService;
|
||||
|
||||
@@ -33,7 +37,9 @@ public class SampleSpringXmlApplication implements CommandLineRunner {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run("classpath:/META-INF/application-context.xml", args);
|
||||
SpringApplication application = new SpringApplication();
|
||||
application.setSources(Collections.singleton(CONTEXT_XML));
|
||||
application.run(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user