将Spring Boot版本从1.3升级到1.4.2.RELEASE后,项目无法在类路径中获取export.sql文件。
在我的properties.yml文件中,我有2个数据源(serviceapione,serviceapitwo),如下所示。
spring 1.3属性
spring:
config:
location: classpath:.
serviceapione:
datasource:
url: jdbc:h2:mem:app_db;Mode=Oracle;DB_CLOSE_ON_EXIT=FALSE
driverClassName: org.h2.Driver
username: sa
password:
testWhileIdle: true
validationQuery: SELECT sysdate FROM dual
maxWait: 1000
maxActive: 20
maxIdle: 9
minIdle: 2
testOnBorrow: false
jpa:
show-sql: true
database: H2
database-platform: org.hibernate.dialect.H2Dialect
generate-ddl: true
与serviceapitwo相同,这是从DataSourceConfig类加载的
@Configuration
public class ServiceApiOneDataSourceConfig {
@Bean
@Primary
@ConfigurationProperties(prefix = "serviceapione.datasource")
public DataSource serviceDataSource() {
return DataSourceBuilder
.create()
.build();
}
@Bean
public EntityManagerFactory serviceEntityManagerFactory() {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
factory.setPackagesToScan("package.path");
factory.setDataSource(serviceDataSource());
factory.afterPropertiesSet();
return factory.getObject();
}
}
迁移后,我有以下版本, 弹簧靴:1.4.2。发布 休眠状态:5.0.11.FINAL
因此,要使服务正常运行,我必须在.yml文件中添加以下配置 并从配置类中添加休眠属性(例如hibernate.hbm2ddl.auto)。
spring:
config:
location: classpath:.
jpa:
open-in-view: false
DataSource类
@Bean
public EntityManagerFactory commerceEntityManagerFactory() {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
factory.setPackagesToScan("package.path");
factory.setDataSource(serviceDataSource());
Map<String, Object> properties = new HashMap<>();
properties.put("hibernate.hbm2ddl.auto", "create");
factory.setJpaPropertyMap(properties);
factory.afterPropertiesSet();
return factory.getObject();
}
但是我不想在config类中定义这些休眠属性。我怎么能够 将其从属性文件直接加载到上下文中。
我尝试添加,
config:
location: classpath:.
jpa:
open-in-view: false
hibernate:
ddl-auto: create
并尝试通过将休眠属性添加到数据源部分,
serviceapione:
datasource:
//properties
jpa:
show-sql: true
database: H2
database-platform: org.hibernate.dialect.H2Dialect
generate-ddl: true
hibernate:
ddl-auto: create