From 403dda7f0dd76b0d31b1ab5e52f98432c5420654 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 12 Aug 2021 18:07:42 +0100 Subject: [PATCH] Remove field inject and circular reference from Data Mongo smoke test Closes gh-27651 --- .../data/mongo/SampleMongoApplication.java | 54 +++++++++---------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/main/java/smoketest/data/mongo/SampleMongoApplication.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/main/java/smoketest/data/mongo/SampleMongoApplication.java index 84b2772cc0..10f9a81d68 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/main/java/smoketest/data/mongo/SampleMongoApplication.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/main/java/smoketest/data/mongo/SampleMongoApplication.java @@ -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"); * 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 org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -26,37 +25,36 @@ import org.springframework.boot.autoconfigure.mongo.MongoClientSettingsBuilderCu import org.springframework.context.annotation.Bean; @SpringBootApplication -public class SampleMongoApplication implements CommandLineRunner { +public class SampleMongoApplication { - @Autowired - private CustomerRepository repository; - - @Override - public void run(String... args) throws Exception { - this.repository.deleteAll(); + @Bean + public CommandLineRunner exampleRunner(CustomerRepository repository) { + return (args) -> { + repository.deleteAll(); - // save a couple of customers - this.repository.save(new Customer("Alice", "Smith")); - this.repository.save(new Customer("Bob", "Smith")); + // save a couple of customers + repository.save(new Customer("Alice", "Smith")); + repository.save(new Customer("Bob", "Smith")); - // fetch all customers - System.out.println("Customers found with findAll():"); - System.out.println("-------------------------------"); - for (Customer customer : this.repository.findAll()) { - System.out.println(customer); - } - System.out.println(); + // fetch all customers + System.out.println("Customers found with findAll():"); + System.out.println("-------------------------------"); + for (Customer customer : repository.findAll()) { + System.out.println(customer); + } + System.out.println(); - // fetch an individual customer - System.out.println("Customer found with findByFirstName('Alice'):"); - System.out.println("--------------------------------"); - System.out.println(this.repository.findByFirstName("Alice")); + // fetch an individual customer + System.out.println("Customer found with findByFirstName('Alice'):"); + System.out.println("--------------------------------"); + System.out.println(repository.findByFirstName("Alice")); - System.out.println("Customers found with findByLastName('Smith'):"); - System.out.println("--------------------------------"); - for (Customer customer : this.repository.findByLastName("Smith")) { - System.out.println(customer); - } + System.out.println("Customers found with findByLastName('Smith'):"); + System.out.println("--------------------------------"); + for (Customer customer : repository.findByLastName("Smith")) { + System.out.println(customer); + } + }; } @Bean