在 Spring 启动中,当使用Java时,它可能将字符串数组作为参数传递给antMatchers
private static final String[] LINK_PBL = {
"/webjars/**",
"/css/**",
"/js/**",
"/images/**",
"/",
"/about/**",
"/contact/**",
"/error/**/*"
};
.antMatchers(LINK_PBL)
上面的示例在Java中有效,最下面的一个在kotlin中无效。
private val LINK_PBL = arrayOf(
"/webjars/**",
"/css/**",
"/js/**",
"/index",
"/images/**",
"/",
"/about/**",
"/contact/**",
"/error/**/*"
)
antMatchers(LINK_PBL)
它显示了一个错误,即给定参数无法调用任何函数。
最佳答案
可以使用spread operator — *
传递:
antMatchers(*LINK_PBL)
此函数使用
vararg
关键字定义可变数量的参数。 Kotlin明确区分了数组和变量参数。我认为这样做是为了防止错误的调用。
关于spring-boot - 数组作为Spring Boot Kotlin中 Ant 匹配器的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59803040/