I have a Java Spring boot project that I'm creating a post request in. The code looks like this:
Main:
@SpringBootApplication
public class Main
{
public static void main(String[] args)
{
SpringApplication.run(Main.class,args);
}
}
Java bean:
@Data
@Entity
public class Image {
private @Id @GeneratedValue Long id;
private String imageNo;
private String name;
private Image(){}
public Image(String imageNo, String name){
this.imageNo = imageNo;
this.name = name;
}
}
Repository:
public interface ImageRepository extends CrudRepository<Image, Long> {
}
DatabaseLoader:
@Component
public class DatabaseLoader implements CommandLineRunner {
private final ImageRepository repository;
@Autowired
public DatabaseLoader(ImageRepository repository) {
this.repository = repository;
}
@Override
public void run(String... strings) throws Exception {
this.repository.save(new Image("1", "Baggins"));
}
}
However when I run the project I get the following error:
Description:
Parameter 0 of constructor in com.face.DatabaseLoader required a bean of type 'com.face.ImageRepository' that could not be found.
Action:
Consider defining a bean of type 'com.face.ImageRepository' in your configuration.
Grateful for any help with this! Many thanks,