小编zum*_*000的帖子

如何使用 Kotlin 绑定属性值?

使用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 中使用它?

binding properties classpath kotlin

2
推荐指数
1
解决办法
6984
查看次数

标签 统计

binding ×1

classpath ×1

kotlin ×1

properties ×1