Issue
Hello I'm learning Spring Boot and I'm working on a simple project. I have this problem when I try to execute the tests. Please tell me what I'm doing wrong :(
My project Github is here: https://github.com/emicovi/GildedRose_SpringBoot
APPLICATION FAILED TO START
Description:
Field itemRepository in com.gildedrose.gildedRose.DBLoader required a bean of type 'com.gildedrose.gildedRose.ItemRepository' that could not be found.
The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true)
I tried many solution already posted on the net but I was not able to fix.
Solution
I can see you have excluded DataSourceAutoConfiguration.class
from @SpringBootApplication
annotation.
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
This is the issue. DatasourceAutoConfiguration.class is required for running integration test cases with H2 db. Please don't exclude it and also add H2 dependency in pom.xml.
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
Also, you need to add empty application.properties file in resources folder like this.
After this issue will be resolved.
Answered By - Rohit Agarwal
Answer Checked By - Mary Flores (JavaFixing Volunteer)