Error during startup of Spring Boot JPA app with error that entity class is not a manged type


First I am quite new to Springboot, learning from examples, but I am struggling with a real simple one.

I have a very minimal Springboot App with 1 Main Class, 1 repository, 1 entity.
The database is PosgreSQL.

When starting the application the output contains the error message

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘cityRepository’ defined in com.d043114.minimalJPA.CityRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Not a managed type: class com.d043114.minimalJPA.City

The repository looks like this

package com.d043114.minimalJPA;

import org.springframework.stereotype.Repository;

public interface CityRepository extends CrudRepository<City, Long> {


The entity is like this:

package com.d043114.minimalJPA;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Table(name = "cities")
public class City {
    @GeneratedValue(strategy = GenerationType.AUTO )
    private long ID;
    public long getID() {
        return ID;

    public void setID(long iD) {
        ID = iD;

    public String getName() {
        return name;

    public void setName(String name) { = name;

    private String name;


The main class is basic as well

package com.d043114.minimalJPA;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan(basePackages = "com.d043114.minimalJPA")
public class MinimalJpaApplication {

    public static void main(String\[\] args) {, args);

        City berlin = new City();
        City duesseldorf = new City();
        CityRepository cityRepository =   appcontext.getBean(CityRepository.class);;;



I played around with the @EntityScan and @ComponentScan, but am suprised that it is not working, even though repository, main class and entity are under the same package.


Try adding this annotation as well, over ‘MinimalJpaApplication‘ class:


Answered By – JustQuest

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published