Remove field inject and circular reference from Data Mongo smoke test

Closes gh-27651
pull/28061/head
Andy Wilkinson 3 years ago
parent 3bed23d9dc
commit 403dda7f0d

@ -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,23 +25,21 @@ 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) -> {
@Override repository.deleteAll();
public void run(String... args) throws Exception {
this.repository.deleteAll();
// save a couple of customers // save a couple of customers
this.repository.save(new Customer("Alice", "Smith")); repository.save(new Customer("Alice", "Smith"));
this.repository.save(new Customer("Bob", "Smith")); repository.save(new Customer("Bob", "Smith"));
// fetch all customers // fetch all customers
System.out.println("Customers found with findAll():"); System.out.println("Customers found with findAll():");
System.out.println("-------------------------------"); System.out.println("-------------------------------");
for (Customer customer : this.repository.findAll()) { for (Customer customer : repository.findAll()) {
System.out.println(customer); System.out.println(customer);
} }
System.out.println(); System.out.println();
@ -50,13 +47,14 @@ public class SampleMongoApplication implements CommandLineRunner {
// fetch an individual customer // fetch an individual customer
System.out.println("Customer found with findByFirstName('Alice'):"); System.out.println("Customer found with findByFirstName('Alice'):");
System.out.println("--------------------------------"); System.out.println("--------------------------------");
System.out.println(this.repository.findByFirstName("Alice")); System.out.println(repository.findByFirstName("Alice"));
System.out.println("Customers found with findByLastName('Smith'):"); System.out.println("Customers found with findByLastName('Smith'):");
System.out.println("--------------------------------"); System.out.println("--------------------------------");
for (Customer customer : this.repository.findByLastName("Smith")) { for (Customer customer : repository.findByLastName("Smith")) {
System.out.println(customer); System.out.println(customer);
} }
};
} }
@Bean @Bean

Loading…
Cancel
Save