目前,它已用于Spring Boot应用程序以及类似这样的自定义数据源配置
之前
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class, MongoAutoConfiguration.class})
public class SpringBootAppInitializer {
public static void main(String[] args) {
System.setProperty("java.awt.headless", "false");
SpringApplication.run(SpringBootAppInitializer.class);
}
}
@Bean
public BasicDataSource getDataSource() {
BasicDataSource basicDataSource = new BasicDataSource();
basicDataSource.setDriverClassName(env.getProperty("spring.datasource.driver-class-name"));
basicDataSource.setUsername(env.getProperty("spring.datasource.username"));
basicDataSource.setPassword(env.getProperty("spring.datasource.password"));
basicDataSource.setUrl(env.getProperty("spring.datasource.url"));
return basicDataSource;
}
上面的代码正在工作
之后(要使用嵌入式数据源,请删除DataSourceAutoConfiguration排除项或vs)
@SpringBootApplication(exclude={MongoAutoConfiguration.class})
public class SpringBootAppInitializer {
public static void main(String[] args) {
System.setProperty("java.awt.headless", "false");
SpringApplication.run(SpringBootAppInitializer.class);
}
}
而且,我实际上试图使用两组相同的属性来使它正常工作,一组用于整个教程,而第二组-来自Spring boot的嵌入式Hikari impl。Octava项目的Business子模块中的D:\ Projects \ Octava \ Business \ src \ main \ resources \ application-businessProduction.properties文件的一部分
spring.datasource.platform=postgresql
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.data=data-postgresql.sql
spring.datasource.url=jdbc:postgresql://localhost:5432/octavadb
spring.datasource.initialization-mode=always
spring.datasource.username=postgres
spring.datasource.password=1
duplicated props for HIkari impl
spring.datasource.hikari.connectionTimeout=30000
spring.datasource.hikari.idleTimeout=600000
spring.datasource.hikari.maxLifetime=1800000
spring.datasource.hikari.driver-class-name=org.postgresql.Driver
spring.datasource.hikari.data-source-properties.hibernate.hbm2ddl.import_files=classpath:data-postgresql.sql
spring.datasource.hikari.jdbc-url=jdbc:postgresql://localhost:5432/octavadb
spring.datasource.hikari.username=postgres
spring.datasource.hikari.password=1
现在,我正在尝试删除自定义数据源的创建并使用嵌入式数据源。但是两组属性均不起作用。
2020-05-11 20:35:23.922 ERROR 20064 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Disconnected from the target VM, address: '127.0.0.1:54586', transport: 'socket'
Process finished with exit code 1
为什么这种方法行不通,也许有其他选择?
对于您要做什么,我还不太清楚。您的属性显示未嵌入的PostgreSQL数据库的配置。从调试断点来看,好像没有加载您的属性。如果您实际上是在尝试配置嵌入式数据库(而不是postgres),请检查以下内容:在运行时类路径上有嵌入式数据库(H2,HSQL,Derby等),对吗?如果您找不到有用的答案,则可能要尝试澄清问题。