我希望以下代码值:
DriverClassName
、Url
、Username
、Password
从application.properties文件中读取,如何做到这一点?我正在使用Spring Boot、Mysql、Hibernate和Spring Rest。
DatasourceConfig.java
//This is working fine with inline value specified as below (DriverClassName, Url,Username,Password
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = "com.nouhoun.springboot.jwt.integration.repository")
public class DatasourceConfig {
@Bean
public DataSource datasource() throws PropertyVetoException {
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/fdb?createDatabaseIfNotExist=true");
dataSource.setUsername("root");
dataSource.setPassword("");
return dataSource;
}
....
....
....