使用java,我可以从application.properties文件中获取“spring.datasource.url”键的值,如下所示:
@PropertySource("classpath:application.properties")
public class SpringJdbcConfig {
@Autowired
Environment environment;
private final String URL = "spring.datasource.url";
String dburl = environment.getProperty("spring.datasource.url");
}
Run Code Online (Sandbox Code Playgroud)
使用 kotlin,这是不可能的:
@PropertySource("classpath:application.properties")
open class WebController {
@Autowired
var env: Environment ? = null
}
Run Code Online (Sandbox Code Playgroud)
环境不会引用 PropertySource 文件。我如何在 kotlin 中使用它?