Created
September 11, 2021 14:18
-
-
Save sabljakovich/034f3626882962017cb25e11ff711f29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sabljakovic.mongospringdemo; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.boot.CommandLineRunner; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.context.annotation.Bean; | |
@SpringBootApplication | |
public class MongoSpringDemoApplication { | |
Logger log = LoggerFactory.getLogger(MongoSpringDemoApplication.class); | |
public static void main(String[] args) { | |
SpringApplication.run(MongoSpringDemoApplication.class, args); | |
} | |
@Bean | |
CommandLineRunner runner(final ProductsRepository productsRepository){ | |
return args -> { | |
log.info("Cleaning existing products from the database"); | |
productsRepository.deleteAll(); | |
log.info("Creating a new product"); | |
productsRepository.insert(new Product("A new product")); | |
log.info("Products in the database: {}", productsRepository.findAll()); | |
log.info("Total number of products in the database: {}", productsRepository.count()); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment