Merge branch '2.5.x'

Closes gh-27654
This commit is contained in:
Andy Wilkinson 2021-08-12 18:09:04 +01:00
commit e737388f5c
1 changed files with 26 additions and 28 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,7 +18,6 @@ package smoketest.data.mongo;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -26,37 +25,36 @@ import org.springframework.boot.autoconfigure.mongo.MongoClientSettingsBuilderCu
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@SpringBootApplication @SpringBootApplication
public class SampleMongoApplication implements CommandLineRunner { public class SampleMongoApplication {
@Autowired @Bean
private CustomerRepository repository; public CommandLineRunner exampleRunner(CustomerRepository repository) {
return (args) -> {
repository.deleteAll();
@Override // save a couple of customers
public void run(String... args) throws Exception { repository.save(new Customer("Alice", "Smith"));
this.repository.deleteAll(); repository.save(new Customer("Bob", "Smith"));
// save a couple of customers // fetch all customers
this.repository.save(new Customer("Alice", "Smith")); System.out.println("Customers found with findAll():");
this.repository.save(new Customer("Bob", "Smith")); System.out.println("-------------------------------");
for (Customer customer : repository.findAll()) {
System.out.println(customer);
}
System.out.println();
// fetch all customers // fetch an individual customer
System.out.println("Customers found with findAll():"); System.out.println("Customer found with findByFirstName('Alice'):");
System.out.println("-------------------------------"); System.out.println("--------------------------------");
for (Customer customer : this.repository.findAll()) { System.out.println(repository.findByFirstName("Alice"));
System.out.println(customer);
}
System.out.println();
// fetch an individual customer System.out.println("Customers found with findByLastName('Smith'):");
System.out.println("Customer found with findByFirstName('Alice'):"); System.out.println("--------------------------------");
System.out.println("--------------------------------"); for (Customer customer : repository.findByLastName("Smith")) {
System.out.println(this.repository.findByFirstName("Alice")); System.out.println(customer);
}
System.out.println("Customers found with findByLastName('Smith'):"); };
System.out.println("--------------------------------");
for (Customer customer : this.repository.findByLastName("Smith")) {
System.out.println(customer);
}
} }
@Bean @Bean