java junit spring spring-boot spring-data

Unable to find a @SpringBootConfiguration when doing a JpaTest

I’m new to frameworks (just passed the class) and this is my first time using Spring Boot.

I’m trying to run a simple Junit test to see if my CrudRepositories are indeed working.

The error I keep getting is:

Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=…) with your test

Doesn’t Spring Boot configure itself?

My Test Class:

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class JpaTest {
private AccountRepository repository;
public void clearDb(){
public void createAccount(){
long id = 12;
Account u = new Account(id,"Tim Viz");;
public void findAccountByUsername(){
long id = 12;
String username = "Tim Viz";
Account u = new Account(id,username);;

My Spring Boot application starter:

@EnableJpaRepositories(basePackages = {"domain.repositories"})
@ComponentScan(basePackages = {"controllers","domain"})
@PropertySources(value {@PropertySource("")})
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
ApplicationContext ctx =, args);

My Repository:

public interface AccountRepository extends CrudRepository<Account,Long> {
public Account findByUsername(String username);