From 35bca8efd4bbc2b65c24f166c96c60b5b1373845 Mon Sep 17 00:00:00 2001 From: Eugene Date: Sat, 13 Jul 2019 12:38:43 +0300 Subject: [PATCH] Add proper component scanning --- .../com/test/springboot/springboot/Application.java | 12 +++++------- .../test/springboot/springboot/ApplicationTests.java | 8 ++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/test/springboot/springboot/Application.java b/src/main/java/com/test/springboot/springboot/Application.java index a0728b6..de00456 100644 --- a/src/main/java/com/test/springboot/springboot/Application.java +++ b/src/main/java/com/test/springboot/springboot/Application.java @@ -2,17 +2,15 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ComponentScan; +import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; - -@SpringBootApplication -@EnableJpaRepositories -@ComponentScan(basePackages = "com.test") +@SpringBootApplication(scanBasePackages = "com.test") +@EnableJpaRepositories(basePackages = "com.test") +@EntityScan(basePackages = "com.test") public class Application { - public static void main(String[] args) { SpringApplication.run(Application.class, args); } - } + diff --git a/src/test/java/com/test/springboot/springboot/ApplicationTests.java b/src/test/java/com/test/springboot/springboot/ApplicationTests.java index f13ab83..9d93991 100644 --- a/src/test/java/com/test/springboot/springboot/ApplicationTests.java +++ b/src/test/java/com/test/springboot/springboot/ApplicationTests.java @@ -1,16 +1,24 @@ package com.test.springboot.springboot; +import com.test.repository.ProductRepository; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import static org.junit.Assert.assertNotNull; + @RunWith(SpringRunner.class) @SpringBootTest public class ApplicationTests { + @Autowired + private ProductRepository productRepository; + @Test public void contextLoads() { + assertNotNull(productRepository); } }