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
    • 最新
    • 标签
主页 / coding / 问题

问题[spring-boot](coding)

Martin Hope
Timo B.
Asked: 2025-04-24 23:11:41 +0800 CST

Spring Integration 中的虚拟线程用于长时间运行的外部服务调用

  • 6

我们目前正在开发一个 Spring Integration 流程,其中每条传入消息都需要触发对外部 HTTP 服务的调用。外部调用最多可能需要 20 秒才能完成,并且响应可能非常大——需要将其完全保存在内存中以便进一步处理。

为了提高可扩展性并减少阻塞的平台线程数量,我们希望利用 Java 的虚拟线程(Project Loom,Java 21+)。我们目前的方法是:

Executors.newVirtualThreadPerTaskExecutor()

作为集成流程中通道的执行者:

IntegrationFlow.from(adapter).channel(c -> c.executor(virtualThreadExecutor)).handle(processingService)

当消息到达时,我们已经可以在 processingService 中验证它们是由虚拟线程处理的。

我们想知道的是:

  • 这是在 Spring Integration 中使用虚拟线程的正确方法吗?或者是否有更好的方法将虚拟线程集成到这种流程中?

  • 在这种情况下使用虚拟线程时我们应该注意哪些潜在的陷阱、限制或性能问题?

  • Spring Integration 中是否存在某些特定组件(例如网关、服务激活器等)可能还不支持虚拟线程?

  • 为了避免内存耗尽,我们考虑过限制并发外部请求的数量。有什么最佳实践吗?

我们非常期待大家分享最佳实践或实际经验。提前致谢!

我们目前正在使用 SpringBoot 3.4.4 和 Java 21。

spring-boot
  • 1 个回答
  • 46 Views
Martin Hope
kake.38
Asked: 2025-04-15 06:47:36 +0800 CST

在 Docker 文件中运行 maven 命令并创建 Docker 镜像

  • 7

我需要从 Docker 文件创建 Docker 镜像,以便将我的 Spring Boot 应用程序 Docker 化。但我希望从 Docker 文件内部生成 JAR 文件,而不是通过mvn clean package用户执行。我尝试了以下代码,但无法生成 JAR 文件:

FROM openjdk:17-jdk-slim
COPY pom.xml pom.xml
COPY src src
RUN mvn clean package
COPY ./target/my-app.jar my-app.jar
ENTRYPOINT ["java","-jar","/my-app.jar"]
spring-boot
  • 1 个回答
  • 43 Views
Martin Hope
PAMPA ROY
Asked: 2025-04-10 21:14:32 +0800 CST

我们正在从 Spring 2.xx(Hibernate 5)迁移到 Spring 3.xx(Hibernate 6)。测试用例我们使用了 H2。但是遇到了唯一键约束问题。

  • 5

实体类

@Getter
@Setter
@NoArgsConstructor
@Entity
@ToString
@Table(name = "category_config")
public class CategoryConfig extends BaseEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NotNull(groups = Existing.class)
    @Null(groups = New.class)
    private Long categoryConfigId;

服务等级

公共 CategoryConfig 添加类别(CategoryConfig

categoryConfig,String tenantId) {
    log.info(" info categoryConfig {} ", categoryConfig);
    if (categoryConfig == null||categoryConfig.getDeptNbr()==null) {
        throw new AllocationRuntimeException(ErrorCodes.CATEGORY_NUMBER_MANDATORY.getError());
    }
    categoryConfig.setTenantId(tenantId);
    categoryConfig.setAllocationStatus(ItemSetupAllocationStatus.PROGRESS.getValue());
    categoryConfig.setItemType(ItemType.INSEASON.getValue());
    try {
        return categoryConfigRepository.save(categoryConfig);
    } catch (Exception e) {
        throw new AllocationRuntimeException(e,
                ErrorCodes.CATEGORY_NUMBER_ALREADY_CONFIGURED.getError(categoryConfig.getDeptNbr()));
    }
}

h2配置:

spring:
    cloud:
        gcp:
          core:
            enabled: false
          bigquery:
            datasetName: test
            project-id: test
            enabled: false
        azure:
           storage:
              blob:
                storage-url: https://test.blob.core.windows.net
    datasource:
        driver-class-name: org.h2.Driver
        url: jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE
        username:
        password:
    jpa:
        defer-datasource-initialization: true
        database-platform: org.hibernate.dialect.H2Dialect
        show-sql: true
        properties:
            hibernate:
                format_sql: true
                ddl-auto: update

h2内部的数据:

INSERT INTO category_config(category_config_id, dept_nbr, dept_desc, created_by, created_on, last_updated_by, last_updated_on, sum_need_qty_cdf, sum_need_qty_legacy, allocated_items, wk_supply, wk_supply_legacy, allocation_description, inherit_global_decile, isVLTRequired, tenant_id, allocation_status, item_type, current_doh) VALUES(1, 202, 'edit cat test', 's0k06wm', '2022-08-26', 's0k06wm', '2022-08-26', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'sams_us', 'Allocation available', 'inseason,preseason',7)
INSERT INTO category_config(category_config_id, dept_nbr, dept_desc, created_by, created_on, last_updated_by, last_updated_on, sum_need_qty_cdf, sum_need_qty_legacy, allocated_items, wk_supply, wk_supply_legacy, allocation_description, inherit_global_decile, isVLTRequired, tenant_id, allocation_status, item_type, current_doh) VALUES(2, 12, 'cat test 12', 's0k06wm', '2022-08-26', 's0k06wm', '2022-08-26', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'sams_mx', 'Allocation available', 'inseason',8)
INSERT INTO category_config(category_config_id, dept_nbr, dept_desc, created_by, created_on, last_updated_by, last_updated_on, sum_need_qty_cdf, sum_need_qty_legacy, allocated_items, wk_supply, wk_supply_legacy, allocation_description, inherit_global_decile, isVLTRequired, tenant_id, allocation_status, item_type, current_doh) VALUES(3, 14, 'cat test 14', 's0k06wm', '2022-08-26', 's0k06wm', '2022-08-26', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'sams_mx', 'Allocation available', 'inseason,preseason',8)
INSERT INTO category_config(category_config_id, dept_nbr, dept_desc, created_by, created_on, last_updated_by, last_updated_on, sum_need_qty_cdf, sum_need_qty_legacy, allocated_items, wk_supply, wk_supply_legacy, allocation_description, inherit_global_decile, isVLTRequired, tenant_id, allocation_status, item_type, current_doh) VALUES(4, 7, 'JUGUETES', 's0k06wm', '2022-08-26', 's0k06wm', '2022-08-26', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'sams_mx', 'Allocation available', 'inseason,preseason',8)
INSERT INTO category_config(category_config_id, dept_nbr, dept_desc, created_by, created_on, last_updated_by, last_updated_on, sum_need_qty_cdf, sum_need_qty_legacy, allocated_items, wk_supply, wk_supply_legacy, allocation_description, inherit_global_decile, isVLTRequired, tenant_id, allocation_status, item_type, current_doh) VALUES(5, 1990, 'edit cat test', 's0r0e4g', '2023-05-30', 's0r0e4g', '2023-05-30', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'sams_us', 'Allocation available', 'inseason',8)
INSERT INTO category_config(category_config_id, dept_nbr, dept_desc, created_by, created_on, last_updated_by, last_updated_on, sum_need_qty_cdf, sum_need_qty_legacy, allocated_items, wk_supply, wk_supply_legacy, allocation_description, inherit_global_decile, isVLTRequired, tenant_id, allocation_status, item_type, current_doh) VALUES(6, 5000, 'test cat', 's0k06wm', '2022-08-26', 's0k06wm', '2022-08-26', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'sams_mx', 'Allocation available', 'inseason,preseason',8)

它在 Spring 2.xx 中运行良好,但在 Spring 3.xx 中我得到了

could not execute statement [Unique index or primary key violation: "PRIMARY KEY ON PUBLIC.CATEGORY_CONFIG(CATEGORY_CONFIG_ID) ( /* key:1 */ NULL, 7, NULL, 202, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, CAST(1 AS BIGINT), TIMESTAMP '2022-08-26 00:00:00', TIMESTAMP '2022-08-26 00:00:00', NULL, 'Allocation available', 's0k06wm', 'edit cat test', 'inseason,preseason', 's0k06wm', 'sams_us')"; SQL statement:
insert into category_config (allocated_items,allocation_description,allocation_status,created_by,created_on,current_doh,current_stock_pct,dept_desc,dept_nbr,inherit_global_decile,isvltrequired,item_type,last_updated_by,last_updated_on,margin_onhand,profit,sales_amt,sales_qty,sum_need_qty_cdf,sum_need_qty_legacy,tenant_id,total_oh_qty,wk_supply,wk_supply_legacy,category_config_id) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,default) [23505-224]] [insert into category_config (allocated_items,allocation_description,allocation_status,created_by,created_on,current_doh,current_stock_pct,dept_desc,dept_nbr,inherit_global_decile,isvltrequired,item_type,last_updated_by,last_updated_on,margin_onhand,profit,sales_amt,sales_qty,sum_need_qty_cdf,sum_need_qty_legacy,tenant_id,total_oh_qty,wk_supply,wk_supply_legacy,category_config_id) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,default)]; SQL [insert into category_config (allocated_items,allocation_description,allocation_status,created_by,created_on,current_doh,current_stock_pct,dept_desc,dept_nbr,inherit_global_decile,isvltrequired,item_type,last_updated_by,last_updated_on,margin_onhand,profit,sales_amt,sales_qty,sum_need_qty_cdf,sum_need_qty_legacy,tenant_id,total_oh_qty,wk_supply,wk_supply_legacy,category_config_id) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,default)]; constraint [PRIMARY KEY]

使用 h2 版本 2.2.224

之前运行正常。在 Hibernate 6 中 GenerationType.IDENTITY 是否存在问题?顺便说一下,我们在调用 save 方法时将 categoryConfigId 设置为 null。另外,我没有在 H2 中显式声明创建表,因为之前的版本不需要这样做。

spring-boot
  • 1 个回答
  • 25 Views
Martin Hope
mikeb
Asked: 2025-04-09 10:46:58 +0800 CST

Gradle - 在哪里获取 Spring Boot 项目的“filesMatching”和“expand”

  • 5

尝试对我的 Spring Boot 3.4 项目使用以下 DSL,并且我的 build.gradle.kts 有以下内容 - 它抱怨在这里找不到filesMatching或expand方法。

tasks.named("processResources") {
    filesMatching("application.properties") {
        expand(project.properties)
    }
}

我需要什么插件?我有这个:

plugins {
    id("io.spring.dependency-management") version "1.1.7"
    id("org.springframework.boot") version "3.4.4"
    id("org.owasp.dependencycheck") version "12.1.0"
    kotlin("jvm") version "1.9.23"
    kotlin("plugin.spring") version "1.9.23"
}

我如何才能在这里使用这些方法?

spring-boot
  • 1 个回答
  • 38 Views
Martin Hope
Alfredo Morales
Asked: 2025-04-08 02:42:31 +0800 CST

容器中运行的 Spring 应用程序无法访问配置服务器

  • 6

我正在尝试在容器中运行我的 Spring 应用程序,

目前,我有 2 个容器,其中 1 个运行我的 Spring Config Server,运行在端口 8888 上,如果我打开浏览器,我确实可以获取属性,这没什么问题(我认为),

来自浏览器的请求

第二个容器是 Spring Eureka Discovery Server,运行在端口 8787 上,但是当我在 maven 中构建项目,然后构建映像并运行它时,我在日志中收到以下错误:

2025-04-07 12:03:56 2025-04-07T18:03:56.388Z  INFO 1 --- [app-seven-eureka] [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://10.1.10.220:8888
2025-04-07 12:03:59 2025-04-07T18:03:59.853Z  INFO 1 --- [app-seven-eureka] [           main] c.c.c.ConfigServicePropertySourceLocator : Exception on Url - http://10.1.10.220:8888:org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://10.1.10.220:8888/app-seven-eureka/default": No route to host. Will be trying the next url if available
2025-04-07 12:03:59 2025-04-07T18:03:59.853Z  WARN 1 --- [app-seven-eureka] [           main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://10.1.10.220:8888/app-seven-eureka/default": No route to host
2025-04-07 12:03:59 2025-04-07T18:03:59.857Z  INFO 1 --- [app-seven-eureka] [           main] .s.AppMSEurekaApplication : No active profile set, falling back to 1 default profile: "default"

并且应用程序没有响应并且引发了一些其他错误,正如我所看到的,那是因为它没有从配置服务器加载配置参数......

从 Eclipse 启动第二个应用程序或在终端中运行 jar 不会引发任何错误,服务器启动正常并在正确的端口响应,这是在容器内部时,

这是我的dockerfile:

FROM openjdk:25-oraclelinux8

WORKDIR /app

COPY target/app-seven-eureka-1.0.0.jar /app/app7.jar

EXPOSE 8787

ENTRYPOINT ["java", "-jar", "/app/app7.jar"]

我确实按照这个问题的建议将我的 application.properties 更改为 bootstrap.properties,但没有效果:Spring Cloud Config Client: Fetching config from wrong server

我运行容器的命令是:docker run -p 8787:8787 app-seven-eureka

那么,我是不是漏掉了什么?创建容器时是否需要传递其他参数?或者可能存在什么问题?

解决方案:

切换到 docker composer 来创建容器并在它们之间创建网络:

services:
    service-config:
        container_name: app-seven-config
        networks: 
          - app-seven-network
    
    service-eureka:
        container_name: app-seven-eureka
        networks: 
          - app-seven-network
        extra_hosts:
          - "docker.internal:127.0.0.1"
networks:
  app-seven-network:
    driver: bridge
spring-boot
  • 1 个回答
  • 34 Views
Martin Hope
jashan khangura
Asked: 2025-04-07 18:40:53 +0800 CST

了解 Kubernetes pod 中的多线程工作原理

  • 6

我在 Kubernetes Pod 中运行一个多线程 Spring Boot 微服务,其 CPU 限制为 1(1000m)。这是否意味着只能使用一个 CPU 核心逐个运行所有线程?还是说,只要总 CPU 使用率不超过 1 个 CPU 的限制,多个 CPU 核心可以并发运行我的线程?

spring-boot
  • 1 个回答
  • 29 Views
Martin Hope
Davi Davi
Asked: 2025-04-05 04:08:48 +0800 CST

将属性添加到 bean spring boot 而不是重新创建它

  • 5

我有一个由 spring boot 隐式设置的 objectMapper bean,我想添加

this.objectMapper.enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE);

没有:

@Bean
public ObjectMapper configure(){
    ObjectMapper om = new ObjectMapper();
    om.enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE);
}

因为它重新创建了 bean 然后对其进行配置,所以我只想对 bean 做一些小小的改变,而不需要从头开始重新创建它,从而弄乱 spring 所做的隐式配置。

spring-boot
  • 2 个回答
  • 24 Views
Martin Hope
Giovanni Lovato
Asked: 2025-03-28 17:08:55 +0800 CST

如何在 AOT 处理期间以编程方式设置 Spring 属性?

  • 5

我正在构建一个库模块,作为构建 Spring 应用原生镜像的助手,例如添加 AOT bean 处理器和过滤器。我还需要在 AOT 期间设置一些 Spring 属性,然后激活一些在 AOT 期间要查找和注册的 bean 定义。

由于这是一个库,我无法控制正在构建的应用程序,因此我无法使用属性文件或环境变量来设置属性。我尝试过使用,EnvironmentPostProcessor但看起来它在 AOT 处理期间没有被评估:

class EnableKubernetesEnvironemntPostProcessor implements EnvironmentPostProcessor {

    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
        environment.getPropertySources().addFirst(new MapPropertySource("enableKubernetes", Map.of(
                "spring.main.cloud.platform", "kubernetes",
                "spring.profiles.active", "kubernetes",
                "management.server.port", "9000"
        )));
    }
}

如何在 AOT 处理期间以编程方式设置 Spring 属性?是否可以EnvironmentPostProcessor在 AOT 期间触发?

具体来说,我需要设置spring.main.cloud.platform=kubernetes,以便spring.profiles.active=kubernetesAOT 选择符合这些属性条件的 bean,并且management.server.portAOT 知道为 Actuator 使用不同的容器。

spring-boot
  • 1 个回答
  • 75 Views
Martin Hope
IndigoParadise
Asked: 2025-03-23 08:17:51 +0800 CST

在 Kotlin+Springboot 中运行测试时出错

  • 6

我目前正在学习 Kotlin,并决定进行一些测试,看看我的进展是否有效,但在运行测试时遇到错误。我在网上找到的所有解决方案都无法成功解决我的具体问题。

我使用 IntelliJ IDEA 通过 spring 初始化程序创建了该项目。

数据类:

package com.refactorizando.RealState.model

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id

@Entity
 data class House(
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "houseId")
    val houseId : Long?=null,
    @Column(name = "height")
    val height : Long,
    @Column(name = "length")
    val length : Long,
    @Column(name = "neighbourhood")
    val neighbourhood : String,
    @Column(name = "price")
    val price : Long

    )
package com.refactorizando.RealState.repository

import com.refactorizando.RealState.model.House
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository


@Repository
interface HouseRepository : JpaRepository<House,Long> {
}

测试:

package com.refactorizando.RealState.repository

import com.refactorizando.RealState.model.House
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertNotNull
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest


@DataJpaTest
class HouseRepositoryTest{

    @Autowired
    lateinit var houseRepository: HouseRepository
    lateinit var house : House
    @BeforeEach
    fun init(){
         house  = House(height = 1, length = 1,  neighbourhood = "Somewhere", price = 10000)
    }
    @Test
    fun shouldSave(){
        val savedHouse = houseRepository.save(house)
        assertNotNull(savedHouse)
    }

}

我不断收到以下相同的错误:

Failed to load ApplicationContext for [MergedContextConfiguration@777d191f testClass = com.refactorizando.RealState.repository.HouseRepositoryTest, locations = [], classes = [com.refactorizando.RealState.RealStateApplication], contextInitializerClasses = [], activeProfiles = [], propertySourceDescriptors = [], propertySourceProperties = ["org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper=true"], contextCustomizers = [org.springframework.boot.test.autoconfigure.OnFailureConditionReportContextCustomizerFactory$OnFailureConditionReportContextCustomizer@c260bdc, org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurationContextCustomizer@3f363cf5, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@34be3d80, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@cc5747f7, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@7b64240d, [ImportsContextCustomizer@7fc420b8 key = [org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration, org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration, org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManagerAutoConfiguration, org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration, org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration, org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration, org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration, org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration, org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.JdbcClientAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@5049d8b2, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@2a3591c5, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.reactor.netty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactory$DisableReactorResourceFactoryGlobalResourcesContextCustomizerCustomizer@76ba13c, org.springframework.test.context.support.DynamicPropertiesContextCustomizer@0, org.springframework.boot.test.context.SpringBootTestAnnotation@d6b877fa], contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]
java.lang.IllegalStateException: Failed to load ApplicationContext for [MergedContextConfiguration@777d191f testClass = com.refactorizando.RealState.repository.HouseRepositoryTest, locations = [], classes = [com.refactorizando.RealState.RealStateApplication], contextInitializerClasses = [], activeProfiles = [], propertySourceDescriptors = [], propertySourceProperties = ["org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper=true"], contextCustomizers = [org.springframework.boot.test.autoconfigure.OnFailureConditionReportContextCustomizerFactory$OnFailureConditionReportContextCustomizer@c260bdc, org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurationContextCustomizer@3f363cf5, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@34be3d80, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@cc5747f7, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@7b64240d, [ImportsContextCustomizer@7fc420b8 key = [org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration, org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration, org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManagerAutoConfiguration, org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration, org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration, org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration, org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration, org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration, org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.JdbcClientAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@5049d8b2, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@2a3591c5, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.reactor.netty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactory$DisableReactorResourceFactoryGlobalResourcesContextCustomizerCustomizer@76ba13c, org.springframework.test.context.support.DynamicPropertiesContextCustomizer@0, org.springframework.boot.test.context.SpringBootTestAnnotation@d6b877fa], contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:180)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:130)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:155)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:111)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:260)
    at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:160)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:215)
    at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:197)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:215)
    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560)
    at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265)
    at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:636)
    at java.base/java.util.Optional.orElseGet(Optional.java:364)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testEntityManager' defined in class path resource [org/springframework/boot/test/autoconfigure/orm/jpa/TestEntityManagerAutoConfiguration.class]: Unsatisfied dependency expressed through method 'testEntityManager' parameter 0: No qualifying bean of type 'jakarta.persistence.EntityManagerFactory' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.ConstructorResolver
    .createArgumentArray(ConstructorResolver.java : 804) at org.springframework
    .beans.factory.support.ConstructorResolver
    .instantiateUsingFactoryMethod(ConstructorResolver.java : 546) at org
    .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
    .instantiateUsingFactoryMethod(
        AbstractAutowireCapableBeanFactory.java : 1361) at org.springframework
    .beans.factory.support.AbstractAutowireCapableBeanFactory
    .createBeanInstance(AbstractAutowireCapableBeanFactory.java : 1191) at org
    .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
    .doCreateBean(AbstractAutowireCapableBeanFactory.java : 563) at org
    .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
    .createBean(AbstractAutowireCapableBeanFactory.java : 523) at org
    .springframework.beans.factory.support.AbstractBeanFactory
    .lambda$doGetBean$0(AbstractBeanFactory.java : 339) at org.springframework
    .beans.factory.support.DefaultSingletonBeanRegistry
    .getSingleton(DefaultSingletonBeanRegistry.java : 347) at org
    .springframework.beans.factory.support.AbstractBeanFactory
    .doGetBean(
        AbstractBeanFactory.java : 337) at org.springframework.beans.factory
    .support.AbstractBeanFactory.getBean(AbstractBeanFactory.java : 202) at org
    .springframework.beans.factory.support.DefaultListableBeanFactory
    .instantiateSingleton(DefaultListableBeanFactory.java : 1155) at org
    .springframework.beans.factory.support.DefaultListableBeanFactory
    .preInstantiateSingleton(DefaultListableBeanFactory.java : 1121) at org
    .springframework.beans.factory.support.DefaultListableBeanFactory
    .preInstantiateSingletons(DefaultListableBeanFactory.java : 1056) at org
    .springframework.context.support.AbstractApplicationContext
    .finishBeanFactoryInitialization(AbstractApplicationContext.java : 987)
        at org.springframework.context.support.AbstractApplicationContext
    .refresh(AbstractApplicationContext.java : 627) at org.springframework.boot
    .SpringApplication.refresh(SpringApplication.java : 752) at org
    .springframework.boot.SpringApplication
    .refreshContext(SpringApplication.java : 439) at org.springframework.boot
    .SpringApplication.run(SpringApplication.java : 318) at org.springframework
    .boot.test.context.SpringBootContextLoader
    .lambda$loadContext$3(SpringBootContextLoader.java : 144) at org
    .springframework.util.function.ThrowingSupplier
    .get(ThrowingSupplier.java : 58) at org.springframework.util.function
    .ThrowingSupplier.get(ThrowingSupplier.java : 46) at org.springframework
    .boot.SpringApplication.withHook(SpringApplication.java : 1461) at org
    .springframework.boot.test.context.SpringBootContextLoader$ContextLoaderHook
    .run(SpringBootContextLoader.java : 563) at org.springframework.boot.test
    .context.SpringBootContextLoader
    .loadContext(SpringBootContextLoader.java : 144) at org.springframework.boot
    .test.context.SpringBootContextLoader
    .loadContext(SpringBootContextLoader.java : 110) at org.springframework.test
    .context.cache.DefaultCacheAwareContextLoaderDelegate
    .loadContextInternal(
        DefaultCacheAwareContextLoaderDelegate.java : 225) at org
    .springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate
    .loadContext(
        DefaultCacheAwareContextLoaderDelegate.java : 152)... 19 more Caused by
    : org.springframework.beans.factory
    .NoSuchBeanDefinitionException
    : No qualifying bean of type
      'jakarta.persistence.EntityManagerFactory' available
    : expected at least
      1 bean which qualifies as autowire candidate.Dependency annotations : {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory
    .raiseNoMatchingBeanFound(DefaultListableBeanFactory.java : 2207) at org
    .springframework.beans.factory.support.DefaultListableBeanFactory
    .doResolveDependency(DefaultListableBeanFactory.java : 1630) at org
    .springframework.beans.factory.support.DefaultListableBeanFactory
    .resolveDependency(DefaultListableBeanFactory.java : 1555) at org
    .springframework.beans.factory.support.ConstructorResolver
    .resolveAutowiredArgument(ConstructorResolver.java : 913) at org
    .springframework.beans.factory.support.ConstructorResolver
    .createArgumentArray(ConstructorResolver.java : 791)... 45 more

    Error creating bean with name 'testEntityManager' defined in
    class path resource[org / springframework / boot / test / autoconfigure /
                        orm / jpa / TestEntityManagerAutoConfiguration.class]
    : Unsatisfied dependency expressed through method
      'testEntityManager' parameter 0
    : No qualifying bean of type
      'jakarta.persistence.EntityManagerFactory' available
    : expected at least
      1 bean which qualifies as autowire candidate.Dependency annotations : {}
org.springframework.beans.factory
    .UnsatisfiedDependencyException
    : Error creating bean with name 'testEntityManager' defined in class path
          resource[org / springframework / boot / test / autoconfigure / orm /
                   jpa / TestEntityManagerAutoConfiguration.class]
    : Unsatisfied dependency expressed through
          method 'testEntityManager' parameter 0
    : No qualifying bean of
          type 'jakarta.persistence.EntityManagerFactory' available
    : expected at least 1 bean which qualifies
          as autowire candidate.Dependency annotations : {}
at app  // org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:804)
        at app  // org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:546)
            at app  // org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1361)
                at app  // org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1191)
                    at app  // org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:563)
                        at app  // org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:523)
                            at app  // org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:339)
                                at app  // org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:347)
                                    at app  // org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:337)
                                        at app  // org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
                                            at app  // org.springframework.beans.factory.support.DefaultListableBeanFactory.instantiateSingleton(DefaultListableBeanFactory.java:1155)
                                                at app  // org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingleton(DefaultListableBeanFactory.java:1121)
                                                    at app  // org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:1056)
                                                        at app  // org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:987)
                                                            at app  // org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:627)
                                                                at app  // org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752)
                                                                    at app  // org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439)
                                                                        at
                                                                            app  // org.springframework.boot.SpringApplication.run(SpringApplication.java:318)
                                                                                at
                                                                                    app  // org.springframework.boot.test.context.SpringBootContextLoader.lambda$loadContext$3(SpringBootContextLoader.java:144)
                                                                                        at
                                                                                            app  // org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:58)
                                                                                                at
                                                                                                    app  // org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:46)
                                                                                                        at
                                                                                                            app  // org.springframework.boot.SpringApplication.withHook(SpringApplication.java:1461)
                                                                                                                at
                                                                                                                    app  // org.springframework.boot.test.context.SpringBootContextLoader$ContextLoaderHook.run(SpringBootContextLoader.java:563)
                                                                                                                        at
                                                                                                                            app  // org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:144)
                                                                                                                                at
                                                                                                                                    app  // org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:110)
                                                                                                                                        at
                                                                                                                                            app  // org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:225)
                                                                                                                                                at
                                                                                                                                                    app  // org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:152)
                                                                                                                                                        at
                                                                                                                                                            app  // org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:130)
                                                                                                                                                                at app  // org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:155)
                                                                                                                                                                    at app  // org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:111)
                                                                                                                                                                        at app  // org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:260)
                                                                                                                                                                            at app  // org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:160)
                                                                                                                                                                                at java
                                                                                                                                                                                    .base
    @23.0.2 /
    java.util.stream.ForEachOps$ForEachOp$OfRef
        .accept(ForEachOps.java : 184) at java.base @23.0.2 /
    java.util.stream.ReferencePipeline$3$1
        .accept(ReferencePipeline.java : 215) at java.base @23.0.2 /
    java.util.stream.ReferencePipeline$2$1
        .accept(ReferencePipeline.java : 197) at java.base @23.0.2 /
    java.util.stream.ReferencePipeline$3$1
        .accept(ReferencePipeline.java : 215) at java.base @23.0.2 /
    java.util.ArrayList$ArrayListSpliterator
        .forEachRemaining(ArrayList.java : 1709) at java.base @23.0.2 /
    java.util.stream.AbstractPipeline
        .copyInto(AbstractPipeline.java : 570) at java.base @23.0.2 /
    java.util.stream.AbstractPipeline
        .wrapAndCopyInto(AbstractPipeline.java : 560) at java.base @23.0.2 /
    java.util.stream.ForEachOps$ForEachOp
        .evaluateSequential(ForEachOps.java : 151) at java.base @23.0.2 /
    java.util.stream.ForEachOps$ForEachOp$OfRef
        .evaluateSequential(ForEachOps.java : 174) at java.base @23.0.2 /
    java.util.stream.AbstractPipeline
        .evaluate(AbstractPipeline.java : 265) at java.base @23.0.2 /
    java.util.stream.ReferencePipeline
        .forEach(ReferencePipeline.java : 636) at java.base @23.0.2 /
    java.util.Optional.orElseGet(Optional.java : 364) at java.base @23.0.2 /
    java.util.ArrayList.forEach(ArrayList.java : 1597) at java.base @23.0.2 /
    java.util.ArrayList.forEach(ArrayList.java : 1597) Caused by
    : org.springframework.beans.factory
          .NoSuchBeanDefinitionException
    : No qualifying bean of type
      'jakarta.persistence.EntityManagerFactory' available
    : expected at least
      1 bean which qualifies as autowire candidate.Dependency annotations : {}
at app  // org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:2207)
    at app  // org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1630)
        at app  // org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1555)
            at app  // org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:913)
                at app  // org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)
    ... 45 more

这里是代码的存储库。

我知道我没有提供大量信息,但事实是我不知道还能说些什么,我尝试过在线发布的不同解决方案,但似乎没有人能解决这个问题。

spring-boot
  • 1 个回答
  • 38 Views
Martin Hope
kake.38
Asked: 2025-03-23 08:05:20 +0800 CST

使用 GraphQL 进行参数化查询

  • 5

在一些 Spring Boot 项目中,当带有参数的请求发送到 REST 控制器时,我使用 QueryDSL 来过滤结果。每个请求可能包含不同的参数来检索过滤后的结果。通过使用 QueryDSL,我可以实现这一点。我对 GraphQL 不太熟悉,这就是我问这个问题的原因:GraphQL 是否提供了一种类似于 QueryDSL 的实现参数化查询以检索过滤结果的方法?

spring-boot
  • 1 个回答
  • 44 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

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve