AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

    • 主页
    • 系统&网络
    • Ubuntu
    • Unix
    • DBA
    • Computer
    • Coding
    • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-1072187

John Little's questions

Martin Hope
John Little
Asked: 2025-03-06 19:45:07 +0800 CST

薄型 JDBC 驱动程序和厚型 JDBC 驱动程序之间有什么区别?我应该如何选择使用哪一个?

  • 5

Snowflake 有精简版、标准版(精简版?)和 FIPS Java JDBC 驱动程序。我不需要 FIPS。

我曾假设“薄”表示轻量级,不需要 jar,而“厚”表示重,包括任何依赖的 jar。

因此,如果您想让应用程序加载速度更快、依赖冲突更少,那么精简会更好。

然而,我看到有关 Oracle 类型 1 到 4 驱动程序的讨论似乎暗示了相反的意思。

有什么区别?对于通过 JDBC 直接连接到 Snowflake 的 Spring Boot 应用程序,我应该选择哪一个?

=== 更新 1 ===

我尝试了两种雪花驱动程序。Maven 无法解析“精简”驱动程序所需的所有依赖项,因此为了节省时间,我选择了“标准”驱动程序,该驱动程序可与 Maven + Spring Boot 配合使用。

java
  • 1 个回答
  • 66 Views
Martin Hope
John Little
Asked: 2025-02-11 23:16:56 +0800 CST

spring boot 无法注入服务,出现“无法找到”错误。@Autowired 不起作用

  • 5

@Autowired 不起作用,我们不知道原因。服务和控制器位于不同的模块和包中,但我们认为这并不重要。我们可以手动实例化服务,这样控制器模块就能够“看到”公共模块。

运行该应用程序会导致以下错误:

Parameter 0 of constructor in com.xx.campaign_api.controller.MyController required a bean of type 'com.xx.campaign.common.service.MyService' that could not be found.

我们有一个多模块 spring boot 3.4.2 项目,其 pom 如下:

<project xxx
    <groupId>org.springframework</groupId>
    <artifactId>our-service</artifactId>
    <version>0.1.0</version>
    <packaging>pom</packaging>

    <modules>
        <module>campaign-common</module>
        <module>campaign-api</module>
        <module>campaign-schedule</module>
    </modules>
</project>

在 api 模块中我们有一个像这样的休息控制器:

package com.xx.campaign_api.controller;
import com.xx.campaign.common.service.MyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MyController {

    private MyService testService;

    @Autowired
    public MyController(MyService testService) {  // THIS LINE IS FAILING
        this.testService = testService;
    }

    @GetMapping("/test")
    public String test() {
    return testService.test();
    }
}

该服务如下所示:

package com.xxx.campaign.common.service;
import org.springframework.stereotype.Service;

@Service
public class MyServiceImpl implements MyService {
    @Override
    public String test() {
        return "test3";
    }
}
package com.xxx.campaign.common.service;
public interface MyService {
    public String test();
}

主要类如下所示:

package com.xx.campaign_api;
@SpringBootApplication
public class CampaignApiApplication {
    public static void main(String[] args) {
        SpringApplication.run(CampaignApiApplication.class, args);
    }
}

在控制器模块的 pom 中,我们有:

    <dependency>
        <groupId>xx</groupId>
        <artifactId>campaign-common</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <scope>compile</scope>
    </dependency>

我也尝试过这个:

package com.xx.campaign_api.controller
@SpringBootApplication(scanBasePackages = "com.xx")
@RestController
public class GaController {

    private MyService myService;

    @Autowired
    public GaController(MyService myService) {  // THIS LINE IS FAILING
        this.myService = myService;
    }

但该应用程序无法启动并出现以下错误:

Web application could not be started as there was no org.springframework.boot.web.servlet.server.ServletWebServerFactory bean defined in the context.
spring-boot
  • 2 个回答
  • 22 Views
Martin Hope
John Little
Asked: 2025-01-07 01:56:44 +0800 CST

Spring Boot Kafka 消费者是异步的吗?如果不是,我们该如何实现?

  • 4

我们有 Spring Boot 2.7 + Kafka,可以这样使用消息:

@KafkaListener(topics = "${kafka.topic.stuff}")
public void consume(@Payload String message) {
    log.info("in kafka consumer");
   // process event
}

但是,我们不知道这些是否正在同步处理(因此,如果我们花太长时间处理一条消息,它将延迟处理下一条消息)。

通常,我们可以从日志输出中看到它是否正在使用新线程进行处理,但由于某种原因,缺少以下信息:

2025-01-06T17:40:00,143Z INFO  pool-2-thread-1 c.c.g.scheduler.SomemScheduler [correlationToken:ANP-06c003a1-d31c-42f6-9d2d-a9cdb5bfde96] => some event scheduler started..

2025-01-06T17:40:07,721Z INFO  org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1 c.c.g.s.cdm.consumer.MyConsumer [] => in kafka consumer
2025-01-06T17:40:14,665Z INFO  org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1 org.apache.kafka.clients.NetworkClient [] => [Consumer clientId=consumer-SWH-1, groupId=SWH] Node -1 disconnected.

在这里我们可以看到,我们的代码中记录的行显示了线程名称,但是 Kafka 监听器内部记录的行没有显示,所以我们看不到它是否正在创建新线程。

在我们的logback.xml中我们有:

<pattern>%date{"yyyy-MM-dd'T'HH:mm:ss,SSSXXX", UTC} %-5level %thread %logger{42} [%X{correlationTokenKV}] => %msg%n</pattern>

问题是:

  1. Kafka 消费者是 aysnc 吗?
  2. 如果没有的话,我们该如何做呢?
  3. 为什么我们的标准日志格式没有被使用?
  4. 我们如何让 Kafka 使用我们的日志格式化程序,或者至少输出线程?

我们像这样包含 Kafka:

    <dependency>
        <groupId>org.springframework.kafka</groupId>
        <artifactId>spring-kafka</artifactId>
    </dependency>
spring-boot
  • 2 个回答
  • 30 Views
Martin Hope
John Little
Asked: 2024-11-11 21:08:50 +0800 CST

如果我删除 BitBucket Cloud 上的合并分支,当前代码会发生什么?

  • 4

不久前,有人在我们的 BitBucket Cloud 存储库中意外创建了一个名为“bugfix”的分支,并将其合并到开发和主分支中。这意味着如果我们尝试推送以 bugfix 开头的任何分支,例如“bugfix/ABC-234_somefix”,就会出现引用错误

我们不知道它是如何合并的(例如,它是合并,还是压缩,还是重新定基或类似的)。

我们可以认为删除这个旧分支是安全的吗?

git
  • 1 个回答
  • 43 Views
Martin Hope
John Little
Asked: 2024-10-23 18:36:25 +0800 CST

如何知道 Spring Boot 应用程序是否正在使用 nio?

  • 5

如果我们搜索我们的spring boot 2.0.3项目源代码(所有文件),没有提到nio。

根据spring 文档,nio 默认是禁用的,所以我们预计不会使用 nio。

但是,当应用程序启动时,它会显示“restartedMain org.apache.coyote.http11.Http11NioProtocol [] => Initializing ProtocolHandler ["http-nio-8080"]”

这是否意味着我们正在使用 nio?如果是这样,那么文档中关于默认不使用它的说法是错误的吗?

2024-10-23T09:10:56,001Z INFO  restartedMain o.s.b.web.embedded.tomcat.TomcatWebServer [] => Tomcat initialized with port(s): 8080 (http)
2024-10-23T09:10:56,031Z INFO  restartedMain org.apache.coyote.http11.Http11NioProtocol [] => Initializing ProtocolHandler ["http-nio-8080"]
2024-10-23T09:10:56,052Z INFO  restartedMain org.apache.catalina.core.StandardService [] => Starting service [Tomcat]
2024-10-23T09:10:56,052Z INFO  restartedMain org.apache.catalina.core.StandardEngine [] => Starting Servlet Engine: Apache Tomcat/8.5.31
spring-boot
  • 1 个回答
  • 20 Views
Martin Hope
John Little
Asked: 2024-10-12 05:08:40 +0800 CST

spring cloud feign-如何找出其使用的http客户端?

  • 7

我们将 spring boot open feign 与我们的 java 8 spring boot 2.0.3 应用程序结合使用。Open feign 用于对其他服务进行 REST 调用。我们正尝试让 Ne​​w Relic java 代理将 feign 调用“视为”跟踪的一部分,但它根本没有对它们进行检测。

  1. open feign 是一个 Web 客户端吗,或者它是一个使用 Web 客户端的库?
  2. 我们如何知道它使用什么网络客户端?
  3. 我们应该怎样改变它?

我们被告知 New Relic 仅支持以下 http 客户端,我们只能猜测 Feign 没有使用其中之一:

Akka HTTP 2.4.5 to latest
Akka Http Core from 0.4 to latest
AsyncHttpClient 2.0.0-RC1 to latest
HttpAsyncClient 4.1 to latest
Apache Httpclient from 3.1 to 5.x
java.net.HttpURLConnection
OkHttp 3.6.0 to latest
Ning AsyncHttpClient 1.x
Spring webclient from 5.0.0.release to latest
STTP v2

以下是我们包含 feign 的方式:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <version>2.0.0.RELEASE</version>
        </dependency>
java
  • 1 个回答
  • 27 Views
Martin Hope
John Little
Asked: 2023-12-07 22:03:33 +0800 CST

spring boot WebTestClient 抛出“没有可用的 'org.springframework.test.web.reactive.server.WebTestClient' 类型的合格 bean”

  • 5

有几个人遇到了类似的问题,但标记为他们的解决方案并没有解决我的问题。

Pom.xml:

:
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
            <scope>test</scope>
        </dependency>
:

CustomerControllerTest2.java

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.reactive.server.WebTestClient;

import static org.springframework.http.HttpHeaders.ACCEPT;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureWebTestClient
public class CustomerControllerTest2 {

    @Autowired
    private WebTestClient webTestClient;

    @Test
    void shouldReturnManyCustomers(){
        this.webTestClient
                .get()
                .uri("/customers")
                .header(ACCEPT,APPLICATION_JSON_VALUE)
                .exchange()
                .expectStatus()
                .is2xxSuccessful()
                .expectHeader()
                .contentType(APPLICATION_JSON)
                .expectBody()
                .jsonPath("$.length()").isNumber()
                .jsonPath("$[0].id").isEqualTo(1);
    }
}

根据其他人的说法,解决方案是添加“@AutoConfigureWebTestClient”和“@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)”

但这并没有帮助。

当我使用 TestRestTemplate 时,我没有任何问题,例如下面的代码可以开箱即用:

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class CustomerControllerTest {

    @LocalServerPort
    private int port;

    @Autowired
    private TestRestTemplate restTemplate;

    @Test
    void greetingShouldReturnDefaultMessage() throws Exception {
        assertThat(this.restTemplate.getForObject("http://localhost:" + port + "/customers",
                String.class)).contains("[email protected]");

    }

}

这些文档:

https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.testing.spring-boot-applications.with-running-server

说以下内容会起作用:

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
class MyRandomPortWebTestClientTests {

    @Test
    void exampleTest(@Autowired WebTestClient webClient) {
        webClient
            .get().uri("/")
            .exchange()
            .expectStatus().isOk()
            .expectBody(String.class).isEqualTo("Hello World");
    }

}

但这也给出了相同的“没有可用的'org.springframework.test.web.reactive.server.WebTestClient'类型的合格bean:预计至少有1个符合自动装配候选资格的bean。”

有趣的是,如果我运行“mvn test”,TestRestTemplate 和 TesWebClient 测试都可以工作。如果我使用 intellij 运行测试,它会失败。在intellij中,默认情况下它似乎不知道如何运行任何东西,但是junit下有一个“All in package”运行配置,这是我可以看到运行测试的唯一方法,并且这运行所有TestRestTemplate测试没有问题,但所有 WebTestClient 基础测试都会因无合格 bean 问题而失败。

spring-boot
  • 1 个回答
  • 20 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助
subwaysurfers
my femboy roommate

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve