使用 WebFlux 的 Spring Boot 在测试中总是抛出 403 状态

2024-02-23

非常感谢您查看我的问题)我有一些奇怪的主题:我的 Spring Boot 测试不起作用。它们启动成功,但在向任何控制器发出请求时总是抛出 403 HTTP 状态 我有一些具有下一个依赖项的项目:

buildscript {
    ext.kotlin_version = '1.3.71'

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.71"
        classpath "org.springframework.boot:spring-boot-gradle-plugin:2.2.1.RELEASE"
        classpath "com.google.cloud.tools.jib:com.google.cloud.tools.jib.gradle.plugin:1.8.0"
    }
}

plugins {
    id "org.springframework.boot" version "2.2.5.RELEASE"
    id "io.spring.dependency-management" version "1.0.9.RELEASE"
    id "com.google.cloud.tools.jib" version "1.8.0"
    id "org.jetbrains.kotlin.jvm" version "1.3.71"
    id "org.jetbrains.kotlin.plugin.spring" version "1.3.71"
    id "org.jetbrains.kotlin.plugin.jpa" version "1.3.71"
}

apply plugin: 'kotlin'

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
}

repositories {
    maven {
        url "https://plugins.gradle.org/m2/"
    }
    maven {
        url "http://oss.jfrog.org/artifactory/oss-snapshot-local/"
    }
    mavenCentral()
}

kotlin {
    sourceSets {
        main.kotlin.srcDirs += 'src/main/myKotlin'
    }
}

dependencies {
    implementation "joda-time:joda-time:2.10.5"
    implementation "org.springframework.boot:spring-boot-starter-security"
    implementation "org.springframework.boot:spring-boot-starter-actuator"
    implementation "org.springframework.boot:spring-boot-starter-batch"
    implementation "org.springframework.boot:spring-boot-starter-jdbc"
    implementation "org.springframework.boot:spring-boot-starter-data-jpa"
    implementation "org.springframework.boot:spring-boot-starter-data-mongodb-reactive"
    implementation "org.springframework.boot:spring-boot-starter-mail"
    implementation "org.springframework.boot:spring-boot-starter-quartz"
    implementation "org.springframework.boot:spring-boot-starter-webflux"
    implementation "com.fasterxml.jackson.module:jackson-module-kotlin"
    implementation "io.springfox:springfox-swagger2:3.0.0-SNAPSHOT"
    implementation "io.springfox:springfox-swagger-ui:3.0.0-SNAPSHOT"
    implementation "io.springfox:springfox-spring-webflux:3.0.0-SNAPSHOT"
    implementation "org.flywaydb:flyway-core"
    implementation "org.jetbrains.kotlin:kotlin-reflect"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-reactor"
    developmentOnly "org.springframework.boot:spring-boot-devtools"
    runtimeOnly "org.postgresql:postgresql"
    testImplementation("org.springframework.boot:spring-boot-starter-test") {
        exclude group: "org.junit.vintage", module: "junit-vintage-engine"
    }
    testImplementation("de.flapdoodle.embed:de.flapdoodle.embed.mongo")
    testImplementation("io.projectreactor:reactor-test")
    testImplementation("org.springframework.batch:spring-batch-test")
    testImplementation("com.ninja-squad:springmockk:2.0.0")
    testImplementation('com.h2database:h2')
}

test {
    useJUnitPlatform()
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
    kotlinOptions {
        freeCompilerArgs = ["-Xjsr305=strict"]
        jvmTarget = "1.8"
    }
}

我实现了一些功能,然后开始通过测试覆盖它。但是,当我启动它们时,spring 总是抛出 403 响应状态的异常。 以下是报告:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.5.RELEASE)

2020-03-26 11:24:23.345  INFO 38406 --- [    Test worker] r.m.b.web.signin.SignInControllerTest    : Starting SignInControllerTest on MacBook-Pro-Apple with PID 38406 (started by alexscrobot in /Users/alexscrobot/development/backends/medissima)
2020-03-26 11:24:23.347  INFO 38406 --- [    Test worker] r.m.b.web.signin.SignInControllerTest    : No active profile set, falling back to default profiles: default
2020-03-26 11:24:26.418  INFO 38406 --- [    Test worker] ctiveUserDetailsServiceAutoConfiguration : 

Using generated security password: 499ec504-7b25-484f-87b3-d6b6d2f7cc06

2020-03-26 11:24:26.553 DEBUG 38406 --- [    Test worker] s.w.r.r.m.a.RequestMappingHandlerMapping : 1 mappings in 'requestMappingHandlerMapping'
2020-03-26 11:24:26.671 DEBUG 38406 --- [    Test worker] o.s.w.r.handler.SimpleUrlHandlerMapping  : Patterns [/swagger-ui.html**, /webjars/**] in 'resourceHandlerMapping'
2020-03-26 11:24:26.765 DEBUG 38406 --- [    Test worker] o.s.w.r.r.m.a.ControllerMethodResolver   : ControllerAdvice beans: none
2020-03-26 11:24:27.338 DEBUG 38406 --- [    Test worker] o.s.w.s.adapter.HttpWebHandlerAdapter    : enableLoggingRequestDetails='false': form data and headers will be masked to prevent unsafe logging of potentially sensitive data
2020-03-26 11:24:27.390  INFO 38406 --- [    Test worker] r.m.b.web.signin.SignInControllerTest    : Started SignInControllerTest in 4.384 seconds (JVM running for 6.038)
2020-03-26 11:24:28.628 DEBUG 38406 --- [    Test worker] o.s.w.r.f.client.ExchangeFunctions       : [48fcb68c] HTTP POST /api/sign-in
2020-03-26 11:24:28.759 DEBUG 38406 --- [     parallel-1] o.s.http.codec.json.Jackson2JsonEncoder  : [48fcb68c] Encoding [RequestCredentials([email protected] /cdn-cgi/l/email-protection, password=123456)]
2020-03-26 11:24:28.797 DEBUG 38406 --- [     parallel-1] o.s.w.s.adapter.HttpWebHandlerAdapter    : [6997f224] HTTP POST "/api/sign-in"
2020-03-26 11:24:28.911 DEBUG 38406 --- [oundedElastic-1] o.s.w.s.s.DefaultWebSessionManager       : Created new WebSession.
2020-03-26 11:24:28.926 DEBUG 38406 --- [oundedElastic-1] o.s.w.s.adapter.HttpWebHandlerAdapter    : [6997f224] Completed 403 FORBIDDEN
2020-03-26 11:24:28.930 DEBUG 38406 --- [oundedElastic-1] o.s.w.r.f.client.ExchangeFunctions       : [48fcb68c] Response 403 FORBIDDEN

Status expected:<200 OK> but was:<403 FORBIDDEN>

> POST /api/sign-in
> WebTestClient-Request-Id: [1]
> Accept: [application/json]
> Content-Type: [application/json]
> Content-Length: [45]

{"email":"[email protected] /cdn-cgi/l/email-protection","password":"123456"}

< 403 FORBIDDEN Forbidden
< Content-Type: [text/plain]
< Cache-Control: [no-cache, no-store, max-age=0, must-revalidate]
< Pragma: [no-cache]
< Expires: [0]
< X-Content-Type-Options: [nosniff]
< X-Frame-Options: [DENY]
< X-XSS-Protection: [1 ; mode=block]
< Referrer-Policy: [no-referrer]

CSRF Token has been associated to this client

java.lang.AssertionError: Status expected:<200 OK> but was:<403 FORBIDDEN>

> POST /api/sign-in
> WebTestClient-Request-Id: [1]
> Accept: [application/json]
> Content-Type: [application/json]
> Content-Length: [45]

{"email":"[email protected] /cdn-cgi/l/email-protection","password":"123456"}

< 403 FORBIDDEN Forbidden
< Content-Type: [text/plain]
< Cache-Control: [no-cache, no-store, max-age=0, must-revalidate]
< Pragma: [no-cache]
< Expires: [0]
< X-Content-Type-Options: [nosniff]
< X-Frame-Options: [DENY]
< X-XSS-Protection: [1 ; mode=block]
< Referrer-Policy: [no-referrer]

CSRF Token has been associated to this client

    at org.springframework.test.web.reactive.server.ExchangeResult.assertWithDiagnostics(ExchangeResult.java:209)
    at org.springframework.test.web.reactive.server.StatusAssertions.assertStatusAndReturn(StatusAssertions.java:227)
    at org.springframework.test.web.reactive.server.StatusAssertions.isOk(StatusAssertions.java:67)
    at ru.medissima.backend.web.signin.SignInControllerTest.success authentication(SignInControllerTest.kt:80)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:675)
    at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:125)
    at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:132)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:124)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:74)
    at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:104)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:62)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:43)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:35)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:202)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:198)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)
    at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)
    at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
    at com.sun.proxy.$Proxy2.stop(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:132)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:412)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.AssertionError: Status expected:<200 OK> but was:<403 FORBIDDEN>
    at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:59)
    at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:122)
    at org.springframework.test.web.reactive.server.StatusAssertions.lambda$assertStatusAndReturn$4(StatusAssertions.java:227)
    at org.springframework.test.web.reactive.server.ExchangeResult.assertWithDiagnostics(ExchangeResult.java:206)
    ... 91 more

2020-03-26 11:24:28.990 DEBUG 38406 --- [    Test worker] o.s.w.r.f.client.ExchangeFunctions       : [5ee937d3] HTTP POST /api/sign-in
2020-03-26 11:24:28.991 DEBUG 38406 --- [     parallel-2] o.s.w.s.adapter.HttpWebHandlerAdapter    : [5fe66132] HTTP POST "/api/sign-in"
2020-03-26 11:24:28.992 DEBUG 38406 --- [oundedElastic-1] o.s.w.s.s.DefaultWebSessionManager       : Created new WebSession.
2020-03-26 11:24:28.994 DEBUG 38406 --- [oundedElastic-1] o.s.w.s.adapter.HttpWebHandlerAdapter    : [5fe66132] Completed 403 FORBIDDEN
2020-03-26 11:24:28.994 DEBUG 38406 --- [oundedElastic-1] o.s.w.r.f.client.ExchangeFunctions       : [5ee937d3] Response 403 FORBIDDEN
SignInControllerTest > success authentication() FAILED
    java.lang.AssertionError at SignInControllerTest.kt:80
        Caused by: java.lang.AssertionError at SignInControllerTest.kt:80
2 tests completed, 1 failed

这是测试实现的代码

@RunWith(value = SpringRunner::class)
@WebFluxTest(value = [SignInController::class])
class SignInControllerTest(
    @Autowired val webTestClient: WebTestClient
) {

    @MockkBean
    private lateinit var service: AuthorizationService

    @MockkBean
    private lateinit var validationService: ValidationService

    @MockkBean
    private lateinit var repository: AuthRepository

    @Test
    fun `failed sign in test`() {
        webTestClient
            .post()
            .uri("/api/sign-in")
            .accept(MediaType.APPLICATION_JSON)
            .exchange()
            .expectStatus().isForbidden
    }

    @Test
    fun `success authentication`() {
        val user = createTestUser()

        val request = RequestCredentials(
            "[email protected] /cdn-cgi/l/email-protection",
            "123456"
        )

        val response = Mono.just(user)

        every { repository.findByEmail("") }.returns(Optional.of(user))
        every { validationService.matchPasswords("", "") }.returns(Unit)
        every { service.authorize("", "") } returns response

        webTestClient
            .post()
            .uri("/api/sign-in")
            .bodyValue(request)
            .accept(MediaType.APPLICATION_JSON)
            .exchange()
            .expectStatus().isOk
    }
}

我看到,需要 csrf 令牌,但我尝试像这样调整配置:

@Configuration
class SecurityConfiguration {

    @Bean
    fun springWebFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
        return http
            .csrf().disable()
            .authorizeExchange()
            .pathMatchers("/api/**").permitAll()
            .anyExchange().permitAll()
            .and()
            .httpBasic()
            .and()
            .build()
    }
}

没用啊请帮助我理解为什么测试环境未正确启动。


这是因为您正在发出 POST 请求跨站请求伪造保护 https://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#csrf已启用。 PUT 请求也是如此。有关于此行为的一个悬而未决的问题 https://github.com/spring-projects/spring-boot/issues/16088。目前,作为解决方法,只需修改您的测试代码(如下所示)即可绕过 403 响应

webClient.mutateWith(csrf()).post()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 WebFlux 的 Spring Boot 在测试中总是抛出 403 状态 的相关文章

随机推荐

  • GDB:捕获信号并继续调试

    我试图在 GDB 中捕获浮点异常 SIGFPE 而不是将其传递给进程并继续调试 我已经给了 gdb 这个 handle SIGFPE stop nopass 当 SIGFPE 发生时 GDB 会停在正确的位置 问题是我不能也不知道如何继续调
  • 创建相对于 jetpack 中其他元素的垂直链组成 ConstraintLayout?

    我想使用 chainStyle Packed 将标题和描述文本链接到以图像为中心的位置 如何在 jetpack compose 中实现此目的 当我使用时createVerticalChain 它相对于父容器的创建链不是我想要的 有没有办法实
  • 使用 Visual Studio 2013 构建 64 位 Live555

    我正在尝试在 Windows 7 上使用 Visual Studio 2013 64 位构建 Live555 的组件 我尝试编辑 win32config 和 mak 文件 但没有成功 我已经在互联网上搜索了几个小时 并使用命令提示符尝试了各
  • 在 Code Igniter 2.02 中设置电子邮件

    我收到很多错误 我已经在不同的站点尝试了几个建议 删除了父函数 删除了数组 更新了我的 php ini 文件 但没有运气 这是我收到的 13 个错误中的第一个 遇到 PHP 错误 严重性 警告 消息 fsockopen function f
  • std::list 析构函数不阻塞

    我有一个多线程应用程序 有一个循环作为主线程等待用户输入 在正确的输入上 它应该停止循环并等待所有其他线程正确结束 为此 我创建了一个 std list 其中放置了为创建线程而创建的 std future 对象 std list
  • 如何在Silverlight中创建类似WPF的数据触发器?

    我如何为 Silverlight 数据网格创建一个触发器 其中单元格背景颜色根据单元格值而变化 我前段时间参与过一个 WPF 项目 我记得通过 xaml 中的 DataTriggers 实现这一点非常简单 然而 此功能似乎在 Silverl
  • 实体框架数据库第一次重新生成让我失去了手动更改

    我正在使用 MVC NET 制作一个网站 由于我是一名老派程序员 首先学习设计数据库 所以我选择了数据库优先方法 我还使用 代码生成 来创建具有扩展名的文件 tt 到目前为止 除了一件让我困扰的事情之外 一切都正常 经典场景 我意识到我缺少
  • 如何在类库项目中正确定义 DBContext?

    我正在使用实体框架 7 并创建了两个项目 一个项目是 ASP NET 5 Web API 项目 另一个是类库项目 包 我想在其中存储所有数据访问层逻辑 这样我就可以将此包用于另一个报告项目 并且我可能提供的其他附加服务 基本上 我在 Web
  • 假设自动线程化的 scipy 和 numpy 函数没有利用多核

    我正在运行 Mac OS X 10 6 8 并使用 Enthought Python 发行版 我希望 numpy 函数能够利用我的两个核心 我遇到了与这篇文章类似的问题 python numpy 中的多线程 blas https stack
  • Android getResources().getDrawable() 已弃用 API 22

    使用新的 Android API 22getResources getDrawable 现已弃用 现在最好的方法是只使用getDrawable 发生了什么变化 您可以选择一些选项来正确处理此弃用 并且未来证明 方式 具体取决于您正在加载哪种
  • QLineEdit 的背景图像

    如何设置背景图片QLineEdit 以下样式表不起作用 QLineEdit background image url images 13 png QLineEdit border 1px solid 000000 image work wi
  • 如何在Python中记录源文件名和行号

    是否可以装饰 扩展Python标准日志记录系统 以便在调用日志记录方法时它还记录文件和调用它的行号或者调用它的方法 当然 检查一下格式化程序 http docs python org library logging html formatt
  • Jenkins 多分支 - 如何扫描 jenkinsfile 放置在子模块上的分支?

    我有一个主存储库 其中包含一个子模块 其中包含 Jenkinsfile 有了这个 我想为该主存储库创建一个多分支管道作业 但这不起作用 当 Jenkinsfile 不在子模块中时它可以工作 但当 Jenkinsfile 位于子模块中时它不会
  • 在 HERE 地图中的标记上悬停时显示内容 Div

    我是这里的地图新手 需要在标记悬停时显示一个 div 我已经能够放置带有图标的标记 但现在需要显示带有一些额外信息的 div HERE 地图 API 是否提供此功能 任何文档 URL 或一段代码都将受到赞赏 注意 我正在使用 HERE 网络
  • 如何在 Twitter Bootstrap 中使用 CSS 将文本对齐到元素的中间?

    我在用引导程序 http twitter github com bootstrap javascript html alerts警报 这是我的成功警报消息 div class alert alert success a class clos
  • 调度程序未在 Spring Boot 中运行

    我创建了一个 Spring Boot 应用程序 我已经配置了包含调度程序方法的类startService 下面是我的代码 服务等级 package com mk service import org springframework bean
  • CSS 使文本左对齐并同时对齐

    有没有办法让文本左对齐并同时对齐 意思是左对齐之类的 有什么办法可以实现这一点吗 感谢帮助 您可能正在寻找最后一行的左对齐 text align justify text align last left
  • 如何让用户输入不区分大小写?

    我想创建一个函数来过滤我要打开的文件以及具体的月份和日期 这样 用户需要输入他们想要在哪个特定月份或日期分析哪个城市 文件 但是 我希望用户能够输入不区分大小写的内容 例如 用户可以输入 chicago CHICAGO ChIcAgO 它仍
  • 如何设置shell脚本的进程组

    如何设置shell脚本的进程组 我还希望所有子进程都位于同一个进程组中 我期望类似的东西setpgid in C As 普斯科西克指出 https stackoverflow com a 45112755在大多数 shell 中 通过激活作
  • 使用 WebFlux 的 Spring Boot 在测试中总是抛出 403 状态

    非常感谢您查看我的问题 我有一些奇怪的主题 我的 Spring Boot 测试不起作用 它们启动成功 但在向任何控制器发出请求时总是抛出 403 HTTP 状态 我有一些具有下一个依赖项的项目 buildscript ext kotlin