Java Code Examples for org.springframework.boot.SpringApplication#addPrimarySources()

The following examples show how to use org.springframework.boot.SpringApplication#addPrimarySources() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleQuery.java    From micronaut-data with Apache License 2.0 6 votes vote down vote up
@Setup
public void prepare() {
    SpringApplication springApplication = new SpringApplication();
    springApplication.addPrimarySources(Collections.singletonList(Application.class));
    springApplication.setLazyInitialization(true);
    applicationContext = springApplication.run();
    this.bookRepository = applicationContext.getBean(BookRepository.class);
    this.bookRepository.saveAll(Arrays.asList(
            new Book("The Stand", 1000),
            new Book("The Shining", 600),
            new Book("The Power of the Dog", 500),
            new Book("The Border", 700),
            new Book("Along Came a Spider", 300),
            new Book("Pet Cemetery", 400),
            new Book("A Game of Thrones", 900),
            new Book("A Clash of Kings", 1100)
    ));
}
 
Example 2
Source File: FunctionalInstallerListener.java    From spring-init with Apache License 2.0 6 votes vote down vote up
private void findInitializers(SpringApplication application) {
	for (Object source : application.getAllSources()) {
		if (source instanceof Class<?>) {
			Class<?> type = (Class<?>) source;
			String cls = type.getName().replace("$", "_") + "Initializer";
			if (ClassUtils.isPresent(cls, application.getClassLoader())) {
				@SuppressWarnings("unchecked")
				Class<? extends ApplicationContextInitializer<?>> initializer = (Class<? extends ApplicationContextInitializer<?>>) ClassUtils
						.resolveClassName(cls, application.getClassLoader());
				addInitializer(initializer);
				remove(application, source);
			}
		}
	}
	if (application.getAllSources().isEmpty()) {
		// Spring Boot is fussy and doesn't like to run with no sources
		application.addPrimarySources(Arrays.asList(Object.class));
	}
}
 
Example 3
Source File: MongoDbFixture.java    From spring-data-dev-tools with Apache License 2.0 6 votes vote down vote up
MongoDbFixture() {

		SpringApplication application = new SpringApplication();
		application.addPrimarySources(Collections.singletonList(MongoDbApplication.class));
		application.setAdditionalProfiles("jpa");
		application.setLazyInitialization(true);

		this.context = application.run();
		
		MongoOperations operations = context.getBean(MongoOperations.class);
		
		operations.dropCollection(Book.class);
		
		IntStream.range(0, Constants.NUMBER_OF_BOOKS) //
			.mapToObj(it -> new Book("title" + it, it)) //
			.forEach(operations::save);
	}
 
Example 4
Source File: Benchmarks.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Setup
public void setup() {
	Map<String, Object> neo4jConfig = prepareNeo4j();

	SpringApplication springApplication = new SpringApplication();
	springApplication.addPrimarySources(Collections.singletonList(Application.class));
	springApplication.setLazyInitialization(true);
	springApplication.setDefaultProperties(neo4jConfig);

	this.applicationContext = springApplication.run();
	this.movieRepository = applicationContext.getBean(MovieRepository.class);
	this.driver = applicationContext.getBean(Driver.class);
}
 
Example 5
Source File: Benchmarks.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Setup
public void setup() {
	Map<String, Object> neo4jConfig = prepareNeo4j();

	SpringApplication springApplication = new SpringApplication();
	springApplication.addPrimarySources(Collections.singletonList(Application.class));
	springApplication.setLazyInitialization(true);
	springApplication.setDefaultProperties(neo4jConfig);

	this.applicationContext = springApplication.run();
	this.movieRepository = applicationContext.getBean(MovieRepository.class);
	this.driver = applicationContext.getBean(Driver.class);
}
 
Example 6
Source File: Benchmarks.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Setup
public void setup() {
	Map<String, Object> neo4jConfig = prepareNeo4j();

	SpringApplication springApplication = new SpringApplication();
	springApplication.addPrimarySources(Collections.singletonList(Application.class));
	springApplication.setLazyInitialization(true);
	springApplication.setDefaultProperties(neo4jConfig);

	this.applicationContext = springApplication.run();
	this.movieRepository = applicationContext.getBean(MovieRepository.class);
	this.driver = applicationContext.getBean(Driver.class);
}
 
Example 7
Source File: Benchmarks.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Setup
public void setup() {
	Map<String, Object> neo4jConfig = prepareNeo4j();

	SpringApplication springApplication = new SpringApplication();
	springApplication.addPrimarySources(Collections.singletonList(Application.class));
	springApplication.setLazyInitialization(true);
	springApplication.setDefaultProperties(neo4jConfig);

	this.applicationContext = springApplication.run();
	this.movieRepository = applicationContext.getBean(MovieRepository.class);
	this.driver = applicationContext.getBean(SessionFactory.class).unwrap(Driver.class);
}
 
Example 8
Source File: SimpleQuery.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
@Setup
public void prepare() {
	SpringApplication springApplication = new SpringApplication();
	springApplication.addPrimarySources(Collections.singletonList(Application.class));
	springApplication.setLazyInitialization(true);
	applicationContext = springApplication.run();
	this.bookRepository = applicationContext.getBean(BookRepository.class);
	this.bookRepository.saveAll(Arrays.asList(new Book("The Stand", 1000), new Book("The Shining", 600),
			new Book("The Power of the Dog", 500), new Book("The Border", 700), new Book("Along Came a Spider", 300),
			new Book("Pet Cemetery", 400), new Book("A Game of Thrones", 900), new Book("A Clash of Kings", 1100)));
}
 
Example 9
Source File: FixtureUtils.java    From spring-data-dev-tools with Apache License 2.0 5 votes vote down vote up
public static ConfigurableApplicationContext createContext(Class<?> configuration, String api, String database) {

		SpringApplication application = new SpringApplication();
		application.addPrimarySources(Collections.singletonList(configuration));
		application.setLazyInitialization(true);
		application.setAdditionalProfiles(api, database);

		System.out.println("Activating profiles: " + Arrays.asList(api, database).toString());

		return application.run();
	}
 
Example 10
Source File: BootstrapApplicationListener.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void apply(ConfigurableApplicationContext context,
		SpringApplication application, ConfigurableEnvironment environment) {
	if (application.getAllSources().contains(BootstrapMarkerConfiguration.class)) {
		return;
	}
	application.addPrimarySources(Arrays.asList(BootstrapMarkerConfiguration.class));
	@SuppressWarnings("rawtypes")
	Set target = new LinkedHashSet<>(application.getInitializers());
	target.addAll(
			getOrderedBeansOfType(context, ApplicationContextInitializer.class));
	application.setInitializers(target);
	addBootstrapDecryptInitializer(application);
}