在Spring Boot中,我知道我可以用application.yml替换application.properties并使用YAML格式.但是,我的application.yml越来越拥挤,所以我需要将它分开一点.我怎样才能做到这一点?我想做这样的事情:
...
@Configuration
@EnableAutoConfiguration
@EnableWebMvc
@EnableScheduling
@PropertySource({"classpath:application.yml", "classpath:scheduling.yml"})
public class ApplicationConfig {
...
Run Code Online (Sandbox Code Playgroud) 我遇到了Java 8方法引用与泛型类型相结合的问题.我已经简化了我的问题,以明确问题所在.以下代码失败:
public static void main(String[] args) {
new Mapper(TestEvent::setId);
}
private static class Mapper<T> {
private BiConsumer<TestEvent, T> setter;
private Mapper(BiConsumer<TestEvent, T> setter) { this.setter = setter; }
}
private static class TestEvent {
public void setId(Long id) { }
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我将构造函数调用更改为
BiConsumer<TestEvent, Long> consumer = TestEvent::setId;
new Mapper(consumer);
Run Code Online (Sandbox Code Playgroud)
一切正常.有人可以解释原因吗?
我知道如果我删除泛型类型(T)并使用Long代替它可行,但在解决我的实际问题时这不起作用.