我正在将一个旧的Spring应用程序转换为Spring启动。所以我仍然使用现有的xml配置而不是注释。在appContext.xml中,我已经配置了从应用程序属性中读取的Hibernate属性,如下所示。
<bean id="appSessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${spring.jpa.database-platform}</prop>
<prop key="hibernate.show_sql">${spring.jpa.show-sql}</prop>
<prop key="hibernate.format_sql">${spring.jpa.format-sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${spring.jpa.hibernate.ddl-auto}</prop>
<prop key="hibernate.generate_statistics">true</prop>
</props>
</property>
否则,这些Hibernate属性不会仅通过使用application.properties.但数据源是通过读取application.properties文件自动创建的。有人能告诉我Hibernate属性缺少什么吗?我肯定想保留appContext.xml,因为将其更改为使用注释只需要大量重构。
这是我的application.properties.
spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource
spring.datasource.url=xxxxxx
spring.datasource.username=xxxx
spring.datasource.password=xxxxx
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.tomcat.initial-size=15
spring.datasource.tomcat.max-wait=20000
spring.datasource.tomcat.max-active=50
spring.datasource.tomcat.max-idle=15
spring.datasource.tomcat.min-idle=8
spring.datasource.tomcat.default-auto-commit=true
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.jpa.hibernate.ddl-auto=none
spring.jpa.show-sql=true
spring.jpa.format-sql=false
它只能由application.properties设置。
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${spring.jpa.database-platform}</prop>
...
</props>
</property>
到
spring.jpa.properties.hibernate.dialect=${spring.jpa.database-platform}
...
祝您好运