因此,我在评论中被告知,它不会隐式工作,因为Tomcat的数据库池以某种方式优先,这对我来说很奇怪。
可以像下面这样显式配置它:
@Configuration@ConfigurationProperties//: so that the conf properties are supplied here@SpringBootApplication//: so that it can be run as war file...public class Application extends SpringBootServletInitializer { @Value("${spring.datasource.username}") private String user; @Value("${spring.datasource.password}") private String password; @Value("${spring.datasource.url}") private String dataSourceUrl; @Value("${spring.datasource.driver-class-name}") private String driverClassName; @Bean public DataSource primaryDataSource() { Properties dsProps = new Properties(); dsProps.setProperty("url", dataSourceUrl); dsProps.setProperty("user", user); dsProps.setProperty("password", password); Properties configProps = new Properties(); configProps.setProperty("driverClassName", driverClassName); configProps.setProperty("jdbcUrl", dataSourceUrl); HikariConfig hc = new HikariConfig(configProps); hc.setDataSourceProperties(dsProps); return new HikariDataSource(hc); }}


