[英]My Java Spring Boot Maven REST API doesn't work
I'm starting in Java J2E and I'm following this tutorial to develop a REST API with Java, Spring Boot and Maven.
我不明白以下错误,请有人给我解释一下?....:/我的代码: https://github.com/AngierRomain/API-REST-Spring-Java-Maven
错误在 ERROR.txt 文件中
预先感谢您的帮助!
我可以看到您在 pom 中添加了依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
您还创建了一个Repository
class。 我假设您想使用 Postgres Db 来获取/存储博客详细信息。
在运行此 spring 应用程序时,出现此错误
org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
这是因为您尝试使用 data-Jpa(pom 依赖项)和 postgres(pom 中存在依赖项),但您没有在 application.properties 中提供方言和连接详细信息。
在 application.properties 添加这个
spring.datasource.url=jdbc:postgresql://localhost:5432/blog
spring.datasource.username= root
spring.datasource.password= root
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
现在,从实体管理器收到此错误:
java.lang.IllegalArgumentException: Not a managed type: class me.romain.Blog
在您的存储库 class 中,您的实体 class 已指定为Blog.java
public interface BlogRepository extends JpaRepository<Blog, Integer>
如果你看到你的Blog
class,它是一个普通的 POJO class。 它不是 DTO。 DTO 负责与数据库交互。 要使 POJO 成为实体 class,您必须指定它。
您可以使用javax.persistence
package 的Entity
和Id
注释来执行此操作
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Blog {
@Id
private int id;
}
现在,您已经遵循了所有这些并且所有数据源连接细节都是正确的,我认为它应该适合您。
注意:您应该尝试在 DB 中保存一些示例数据并从那里获取它以检查它是否真的有效。
如果您只想让当前代码正常工作,请删除存储库 class,从 pom.xml 中删除spring-boot-starter-data-jpa
依赖项。 你应该能够运行你的应用程序。
非常感谢您的回复:;)非常有帮助;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.