SpringBoot2.0.3 reference external configuration file cannot get a value

use @ Configuration to load the configuration file and cannot get the value defined in properties

@Configuration
@PropertySource(value = "classpath:jdbc.properties", encoding = "UTF-8")
@ConfigurationProperties(prefix = "jdbc")
public class DataSourceConfig {
  private String url;
  private String driverClassName;
  private String username;
  private String password;
  
  //  getter setter

  @Bean
  public DataSource dataSource() {
    DriverManagerDataSource ds = new DriverManagerDataSource();
    ds.setDriverClassName(driverClassName);
    ds.setUrl(url);
    ds.setUsername(username);
    ds.setPassword(password);
    return ds;
  }
}
< hr >

try to take the value directly using the injection Environment, or null;
is written directly in the global application.properties (yml), and then fetched, or null

< hr >

is currently solved by directly setting the custom properties property to the returned object using @ ConfigurationProperties (prefix= "mysql") on the method. The
test can be injected correctly when used in this way.

that is, the file name and path are correct.

Mar.23,2021

is the primary mechanism for configuring containers in the @ Configuration class, and it may still be necessary to use at least some XML. In these scenarios, you just need to use @ ImportResource and define as many XML as possible. Doing so enables a "Java-centric" approach to configuring containers and keeping XML to a minimum.
for example:

  

if you use ConfigurationProperties , you need to add the dependency spring-boot-configuration-processor and the setter method. If you directly use @ Value , I can do it here

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c1c9eb-3330b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c1c9eb-3330b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?