spring-boot - 数组作为Spring Boot Kotlin中 Ant 匹配器的参数

标签 spring-boot kotlin

在 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/

相关文章:

kotlin - Kotlin中的 `?.apply`, `?.run`和 `?.let`之间的null检查质量是否有区别?

java - 以下代码中 Spring Bean 的工作 - 如何保存/管理 Bean 属性?

java - 如果违反约束,CrudRepository saveAll 方法将引发异常

spring - 在 WS SoapFault : my custom ExceptionResolver is not used 中添加细节

android - 为什么文本在 Activity 中没有变化?

kotlin - 调用 Continuation.resumeX() 失败一定是个问题吗?

web-applications - 输出 jar 中没有 webapp 文件夹

spring - Spring Security 中的身份验证问题(仅检查用户名而不检查密码?)

android - 在 Jetpack Compose 中的 API 响应后更新 LazyColumn

kotlin - 使用挂起函数混淆内部类后的 ClassCastException