它是否连接到 Hibernate?
Is it connected to Hibernate or not?
最近我发现了一个Spring Boot CRUD的例子。在自述文件中写着:
This project is based on the Spring Boot project and uses these
packages :
- Maven
- Spring Core
- Spring Data (Hibernate & MySQL)
- Spring MVC (Tomcat)
- Thymleaf
在源代码中,我没有看到任何看起来像这个应用程序以某种方式连接到休眠的东西。你能帮我解决这个小问题吗?如果它没有连接到 Hibernate,我怎么能像那样连接 CRUD
到 Hibernate?
感谢您的帮助:)
对于 Spring 使用休眠启动你可以按照下面的步骤 link :-
https://github.com/netgloo/spring-boot-samples
您必须为数据库连接配置休眠 属性 和数据源 属性...但是例如我可以为 Spring 休眠和 JPA 共享一些代码但是 Spring 使用休眠启动你可以遵循 link:-
<bean id="hibernateJpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.amstech.mayal.entity" />
<property name="jpaDialect" ref="hibernateJpaDialect" />
<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" />
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.connection.driver_class" value="${database.jdbc.driver.class}" />
<entry key="hibernate.connection.url" value="${database.jdbc.url}" />
<entry key="hibernate.connection.username" value="${database.user}" />
<entry key="hibernate.connection.password" value="${database.password}" />
<entry key="hibernate.dialect" value="${hibernate.dialect}" />
<entry key="show_sql" value="true" />
<entry key="eclipselink.jdbc.exclusive-connection.is-lazy"
value="true" />
</map>
</property>
</bean>
我建议查看主文档的 Spring 启动数据部分。需要的配置要少得多,您可以流畅地进行配置并留下 xml 。 JPA + Hibernate 是 Spring 数据在引导中变得高度互连。
spring 引导与休眠交互有多种方式。在您分享的示例中,它从 application.properties 文件中获取数据库属性并设置配置。它将从 pom.xml.
中提供的依赖项中选择的其他内容
是的,它与hibernate相连。除了设置项目之外,您需要做的事情是使用一些用户名和密码设置数据库。而创建 db schema.Rest 的事情将由 spring boot 完成。确保您的数据库用户名密码与应用程序文件属性匹配。
在示例中,您提供的是 spring-boot-starter-data-jpa
,它已经包含预定义的休眠依赖项(参见 pom.xml)。
如何使用 documentation section 中描述的 SQL 数据库。
基本上,您使用 application.properties
使用以下前缀配置休眠:
spring.jpa.properties.hibernate.*
最近我发现了一个Spring Boot CRUD的例子。在自述文件中写着:
This project is based on the Spring Boot project and uses these packages :
- Maven
- Spring Core
- Spring Data (Hibernate & MySQL)
- Spring MVC (Tomcat)
- Thymleaf
在源代码中,我没有看到任何看起来像这个应用程序以某种方式连接到休眠的东西。你能帮我解决这个小问题吗?如果它没有连接到 Hibernate,我怎么能像那样连接 CRUD
到 Hibernate?
感谢您的帮助:)
对于 Spring 使用休眠启动你可以按照下面的步骤 link :-
https://github.com/netgloo/spring-boot-samples
您必须为数据库连接配置休眠 属性 和数据源 属性...但是例如我可以为 Spring 休眠和 JPA 共享一些代码但是 Spring 使用休眠启动你可以遵循 link:-
<bean id="hibernateJpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.amstech.mayal.entity" />
<property name="jpaDialect" ref="hibernateJpaDialect" />
<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" />
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.connection.driver_class" value="${database.jdbc.driver.class}" />
<entry key="hibernate.connection.url" value="${database.jdbc.url}" />
<entry key="hibernate.connection.username" value="${database.user}" />
<entry key="hibernate.connection.password" value="${database.password}" />
<entry key="hibernate.dialect" value="${hibernate.dialect}" />
<entry key="show_sql" value="true" />
<entry key="eclipselink.jdbc.exclusive-connection.is-lazy"
value="true" />
</map>
</property>
</bean>
我建议查看主文档的 Spring 启动数据部分。需要的配置要少得多,您可以流畅地进行配置并留下 xml 。 JPA + Hibernate 是 Spring 数据在引导中变得高度互连。
spring 引导与休眠交互有多种方式。在您分享的示例中,它从 application.properties 文件中获取数据库属性并设置配置。它将从 pom.xml.
中提供的依赖项中选择的其他内容是的,它与hibernate相连。除了设置项目之外,您需要做的事情是使用一些用户名和密码设置数据库。而创建 db schema.Rest 的事情将由 spring boot 完成。确保您的数据库用户名密码与应用程序文件属性匹配。
在示例中,您提供的是 spring-boot-starter-data-jpa
,它已经包含预定义的休眠依赖项(参见 pom.xml)。
如何使用 documentation section 中描述的 SQL 数据库。
基本上,您使用 application.properties
使用以下前缀配置休眠:
spring.jpa.properties.hibernate.*