Hibernate 使用数据JPA在Spring Boot中通过邮递员插入记录时出现空指针异常
我试图做的是使用SpringDataJPA使用postman发布一条记录,我得到的是空指针异常。 我不知道出了什么问题,请求中没有错误,代码中没有错误,但它显示了内部服务器错误。请任何人帮帮我 控制器--> -->JpaRepoitoryHibernate 使用数据JPA在Spring Boot中通过邮递员插入记录时出现空指针异常,hibernate,spring-boot,spring-mvc,jpa,spring-data-jpa,Hibernate,Spring Boot,Spring Mvc,Jpa,Spring Data Jpa,我试图做的是使用SpringDataJPA使用postman发布一条记录,我得到的是空指针异常。 我不知道出了什么问题,请求中没有错误,代码中没有错误,但它显示了内部服务器错误。请任何人帮帮我 控制器--> -->JpaRepoitory public interface EmployeeRepository extends JpaRepository<Employee,Integer>{ } -->邮递员要求 Url-->http://localhost:8082/a
public interface EmployeeRepository extends JpaRepository<Employee,Integer>{
}
-->邮递员要求
Url-->http://localhost:8082/api/postEmployee
body-->{
"id":1,
"name":"kanha"
}
错误堆栈帧-->
您必须使用依赖项注入。在这里,您的
私人雇员存储eRepository erepo
为null,这将导致java.lang.NullPointerException:null
改变
private EmployeeRepository erepo;
到
注意:使用@GeneratedValue(strategy=GenerationType.AUTO)
server.port=8082
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/ajax1
spring.datasource.username=root
spring.datasource.password=rajat
spring.jpa.hibernate.ddl-auto = update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
Url-->http://localhost:8082/api/postEmployee
body-->{
"id":1,
"name":"kanha"
}
java.lang.NullPointerException: null
at com.example.demo.controller.Controller1.post(Controller1.java:31) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_191]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_191]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_191]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
private EmployeeRepository erepo;
@Autowired private EmployeeRepository erepo;