在 Java 中,我们编写.class
(例如:)String.class
来获取有关给定类的信息。在 Kotlin 中,您可以编写::class
或::class.java
. 它们之间有什么区别?
我阅读了这个https://springdoc.github.io/springdoc-openapi-demos/文档以使用 springdoc-openapi-webflux-ui。正如文档所说,我刚刚springdoc-openapi-webflux-ui
在我的应用程序中添加了库:implementation('org.springdoc:springdoc-openapi-webflux-ui:1.2.26')
此外,我在 application.yml 中自定义了 API 的路径:
springdoc:
swagger-ui:
path: /swagger-ui.html
Run Code Online (Sandbox Code Playgroud)
当我启动应用程序并转到http://localhost:8080/swagger-ui.html 时,它会将我重定向到http://localhost:8080/webjars/swagger-ui/index.html?configUrl=/v3/api -docs/swagger-config。在该页面中,我收到一个错误:
Whitelabel Error Page
This application has no configured error view, so you are seeing this as a fallback.
Mon Jan 20 05:16:10 UTC 2020
[7192d9dc] There was an unexpected error (type=Not Found, status=404).
No matching handler
Run Code Online (Sandbox Code Playgroud)
问题是:我应该向我的应用程序添加其他配置以显示 API 文档吗?
PS:我使用 spring.boot 2.2.2:RELEASE
Lettuce Core API 有 RedisClient 类,其中包含以下方法:
public StatefulRedisConnection<String, String> connect() {
return this.connect(this.newStringStringCodec());
}
public <K, V> StatefulRedisConnection<K, V> connect(RedisCodec<K, V> codec) {
this.checkForRedisURI();
return (StatefulRedisConnection)this.getConnection(this.connectStandaloneAsync(codec, this.redisURI, this.timeout));
}
Run Code Online (Sandbox Code Playgroud)
我想调用 method connect(RedisCodec<K, V> codec)
,但我不知道如何配置我应该作为参数传递给该方法的编解码器对象。
我当前的代码:
val redisClient = RedisClient.create("redis://password@localhost:6379/0");
val connection = redisClient.connect();
// in this case type of connection is StatefulRedisConnection<String, String>
val redisCommands = connection.sync()
Run Code Online (Sandbox Code Playgroud)
我也有我的自定义数据类。
data class MyCustomDataClassName {
val id: UUID,
val something: String,
val foo: String,
val bar: String
}
Run Code Online (Sandbox Code Playgroud)
我想写这段代码:
val redisClient = …
Run Code Online (Sandbox Code Playgroud) 最近,我在我的应用程序中添加了Detekt分析器。
在我运行 detekt (./gradlew detekt) 后,我在我的主应用程序类中收到了 SpreadOperator 警告。
代码警告: runApplication<MessCallsApplication>(*args)
您可以在此处阅读有关 SpreadOperator 警告的信息: [SpreadOperator Warning][2]
我的主要课程:
@SpringBootApplication(exclude = [RedisAutoConfiguration::class])
@EnableCircuitBreaker
@EnableScheduling
class MyApplication {
companion object : KLogging()
}
fun main(args: Array<String>) {
Thread.setDefaultUncaughtExceptionHandler { _, exception ->
MessCallsApplication.logger.error(exception) { "Uncaught exception" }
}
runApplication<MessCallsApplication>(*args)
}
Run Code Online (Sandbox Code Playgroud)
问题是,摆脱 SpreadOperator 警告的最佳做法是什么?或者是不可能的?
TestContainers 有 Native.java 类,它从“jna.tmpdir”键获取 JNA 属性。如何覆盖该键的值?喜欢:
\n\njna.tmpdir=/data/builds/compose-tmp \njava.io.tmpdir=/data/builds/compose-tmp\n
Run Code Online (Sandbox Code Playgroud)\n\n获取 jna 属性的部分代码:\xc2\xa0
\n\n\npackage com.sun.jna;\n\npublic final class Native implements Version {\n\n...\n\n static File getTempDir() throws IOException {\n File jnatmp;\n String prop = System.getProperty("jna.tmpdir");\n if (prop != null) {\n jnatmp = new File(prop);\n jnatmp.mkdirs();\n }\n}\n
Run Code Online (Sandbox Code Playgroud)\n PS:代码将在 Koltin
例如,我的服务类可以执行某些操作并注入一些其他服务。
class MyService(
private val someOtherService: OtherService
) {
fun doSomething() {
someOtherService.someMethod("foo")
someOtherService.someMethod("bar")
someOtherService.someMethod("baz")
}
}
Run Code Online (Sandbox Code Playgroud)
这是我对模拟 OtherService 的 MyService 类的测试:
internal class MyServiceTest {
@MockkBean(relaxed = true)
private lateinit var someOtherService: OtherService
@Test
fun `my test description`() {
every { someOtherService.someMethod(any()) } just Runs
verify(exactly = 1) {
someOtherService.someMethod(
match {
it shouldBe "bar"
true
}
)
}
}
Run Code Online (Sandbox Code Playgroud)
结果,"bar"
参数将是预期的,但将是"foo"
参数,并且测试将失败。
原因:someOtherService.someMethod("foo")
之前会调用someOtherService.someMethod("bar")
。
但是,我想验证每个方法是否只调用了一次。我怎么能做到这一点?