Java 无法创建JPA/Crudepository bean
我正在使用SpringDataJPA创建第一次SpringREST服务 并在误差以下Java 无法创建JPA/Crudepository bean,java,sql,spring,spring-mvc,spring-data,Java,Sql,Spring,Spring Mvc,Spring Data,我正在使用SpringDataJPA创建第一次SpringREST服务 并在误差以下 应用程序无法启动 说明: com.example.demo.controller.AddProduct中的字段product_repo需要一个类型为“com.example.demo.repository.ProductRepository”的bean,但找不到该bean 注入点具有以下注释: -@org.springframework.beans.factory.annotation.Autowired(
应用程序无法启动
说明: com.example.demo.controller.AddProduct中的字段product_repo需要一个类型为“com.example.demo.repository.ProductRepository”的bean,但找不到该bean 注入点具有以下注释: -@org.springframework.beans.factory.annotation.Autowired(必需=true) 行动: 考虑在配置中定义“com.example.demo.repository.ProductRepository”类型的bean 我的类和接口是:
在ProductRepository界面上添加@Repository注释。如果可能的话,也不要扩展CRUDEPOSITORY extendJpaRepository。。你能提到类的包名或添加你的项目结构吗?
@RestController
public class AddProduct {
@Autowired
private ProductRepositroy product_repo;
@GetMapping("/add")
public String addproduct() {
Product p1 = new Product();
p1.setId(1);
p1.setName("Amit");
Product p2 = new Product();
p1.setId(2);
p1.setName("Sumit");
product_repo.save(p1);
product_repo.save(p2);
return "added successfully the recod";
}
}
@Entity
public class Product {
@Id
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public interface ProductRepositroy extends CrudRepository<Product, Integer> {
}
@SpringBootApplication
public class Demo1Application {
public static void main(String[] args) {
SpringApplication.run(Demo1Application.class, args);
}
}