小编Das*_*sma的帖子

测试中SpringBootTest.WebEnvironment.RANDOM_PORT时如何访问local.server.port

我正在尝试在 Spring Boot 应用程序的测试中为 Spock 测试设置 feign 客户端。

Spock 测试设置为

@ActiveProfiles("functional-test")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
Run Code Online (Sandbox Code Playgroud)

我有一个 application-function-test.yml ,其中我的 feign 客户端是 url 定义,我尝试过:

my.feign.client.example.url: localhost:${local.server.port}
Run Code Online (Sandbox Code Playgroud)

但本地服务器端口显示为 0,这不适合应用程序的随机端口。

我也尝试过,其中 randomServerPort 包含随机端口,但我无法覆盖该属性:

 @LocalServerPort
 int randomServerPort;

 @Value('${my.feign.client.example.url}')
 String feignTestClient

 void setup() {
     feignTestClient="localhost:${randomServerPort}"
 }
Run Code Online (Sandbox Code Playgroud)

有什么最佳实践的想法吗?我更喜欢在 application-function-test.yml 中设置 url,这样可以避免使用虚拟值进行初始化

我的 Feign 客户端如下所示:

@FeignClient(name = "myClient", url = "${my.feign.client.example.url}")
public interface FeignTestRestClient extends SomeControllerApi {}
Run Code Online (Sandbox Code Playgroud)

spring spock spring-boot spring-cloud-feign

5
推荐指数
0
解决办法
441
查看次数

Groovy vs Groovy ++

我刚刚阅读了一些关于Groovy ++的文章,似乎是Groovy本身的一个巨大改进.

有谁知道如何在Grails和IntelliJ中使用Groovy ++?我可以看到最新版本的IntelliJ支持Groovy和Groovy ++

groovy groovy++

4
推荐指数
1
解决办法
1471
查看次数

如何根据操作系统条件在 gradle 中应用插件

我已将插件ID“ua.eshepelyuk.ManifestClasspath”版本“1.0.0” 添加到 build.gradle 文件中的插件 {} 中。我**只想在使用 Windows 计算机时运行该插件。所以我尝试在插件周围添加一个 if 语句。我已将 Gradle 插件包含在下面的 if 语句中:

构建.gradle 文件:

plugins {
   if (System.getProperty("os.name").toLowerCase().contains("windows")) {
    id "ua.eshepelyuk.ManifestClasspath" version "1.0.0"
  }
}
Run Code Online (Sandbox Code Playgroud)

当使用上面的 if 语句时,我收到错误:“插件 {} 脚本块中只允许 id(String) 方法调用”。我怎样才能解决这个问题?

windows gradle

4
推荐指数
1
解决办法
1298
查看次数

带有 Spring Boot 的 Cloud Kafka 给我错误

嘿,我按照分步指南在 Spring Boot 中设置 kafka。

但现在我无法启动该应用程序。有什么建议 :)

日志中的错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'functionInitializer' defined in class path resource [org/springframework/cloud/stream/function/FunctionConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Found more then one function in BeanFactory: [persistentEntities, resourceMappings]. Consider providing 'spring.cloud.function.definition' property.
Run Code Online (Sandbox Code Playgroud)

什么是 spring.cloud.function.definition?以及如何设置呢?引起原因:java.lang.IllegalArgumentException:在 BeanFactory 中发现多个函数:[persistentEntities,resourceMappings]。考虑提供“spring.cloud.function.definition”属性。

java spring-boot spring-cloud spring-cloud-stream spring-cloud-function

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

如何在 vue.config.js 中为 node_modules 添加 sass 加载器

我正在尝试对节点模块使用 sass 加载器。但无论我尝试什么,都会出现以下错误:

SassError:找不到要导入的样式表。

我的 vue.config.js 看起来像这样:

module.exports = {
    css: {
        sourceMap: true,
        loaderOptions: {
            scss: {
                prependData: `
          @import "~@/my-node-module/theme/engine.scss"; 
        `
            }
        }
    },
};
Run Code Online (Sandbox Code Playgroud)

sass webpack vue.js sass-loader vue-cli

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

可以将 Flux 转换为 Mono

我正在使用 r2dc 作为 Spring Boot Java 应用程序。

我在想是否可以将 Flux 转换为 Mono 以进行某些计算。

伪示例:

static PseudoMagic calculate(List<Foo> foos) {
   return callTheMagicRutine(foos)
}

Mono<PseudoMagic> getMyMagic() {
   Flux<Foo> foos = getMyFoos()
   foos.transformToMagic(f -> calculator(f))
}
Run Code Online (Sandbox Code Playgroud)

java spring-boot spring-webflux webflux

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

Deeplearning4j应该如何对数据进行标准化

我的输入数据应如何针对 Deeplearning4j 中的 model.fit 进行标准化?

目前我对大量数据进行了迭代。

我可以看到有些人标准化了完整的数据集。

在我看来,每次迭代的数据集在之前进行标准化更为合乎逻辑model.fit

是否有一些在迭代器内编码规范化的最佳实践?

那么预测的输入呢?

java deep-learning deeplearning4j

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

如何检查列表是否包含Groovy中另一个列表中的值或键?

如何检查列表是否包含子列表(子列表...)或"根"中的键或值,是否可以获得"路径"?

这个containsValue或containsKey似乎只是查看列表的根目录

伪示例:

//This is my list
list = [languages:[_clazz:"basics.i18n.Language", messages:[_clazz:"basics.i18n.Message"]]] 

list.containsKey("languages") // return true
list.containsValue("basics.i18n.Language") // return false where I want true
list.containsKey("messages") // return false // return false where I want true
list.containsValue("basics.i18n.Message") // return false where I want true
Run Code Online (Sandbox Code Playgroud)

groovy

0
推荐指数
1
解决办法
157
查看次数

Groovy中变量的继承

也许是时候晚了:)但是,谁能说出父类确实从子类中提取变量的原因。

Foo {
   public String myString = "My test string of Foo"

   public printOutString () {
       println this.myString
   }
}

Bar extends Foo {
   public String myString = "My test string of Bar"
}

Foo.printOutString() //prints out "My test string of Foo" as expected

Bar.printOutString() //prints out "My test string of Foo" as not expected thought it would take the String from Bar instead 
Run Code Online (Sandbox Code Playgroud)

grails groovy

0
推荐指数
1
解决办法
258
查看次数

Spring security 注解预计将是内联常量

当我尝试在 @Secured 注释之外定义字符串时,我在 grails 中遇到以下错误。

我收到以下错误 Role.USER' to be an inline const of type java.lang.String not a property expression in @grails.plugin.springsecurity.annotation.Secured

class Role {
    final static String USER = "ROLE_USER"
    final static String ADMIN = "ROLE_ADMIN"


    public final static String[] LOGINED_USER = [USER, ADMIN].asImmutable()

}
Run Code Online (Sandbox Code Playgroud)

下面的控制器说明了我的问题..

class MyController {

    @Secured(["permitAll"]) //Works fine
    def action1() {
    }


    @Secured(LOGINED_USER) //Doesn't work
    def action2() {
    }

    @Secured([Role.ADMIN, Role.USER]) //Doesn't work
    def action3() {
    }


    @Secured(["ROLE_ADMIN", "ROLE_USER"]) //Works fine
    def action4() {
    }
}
Run Code Online (Sandbox Code Playgroud)

grails spring-security

0
推荐指数
1
解决办法
3477
查看次数