spring-boot 相关问题

Spring Boot可以轻松创建Spring驱动的生产级应用程序和服务,并且可以轻松实现。它采用了Spring平台的观点,以便新用户和现有用户可以快速获得他们需要的位。

Spring 调度程序 - 获取下一个事件的时间

我有一个 SpringBoot Scheduler,如下所示: @Scheduled(cron = "*/10 * * * * * ") // 每 10 秒一次 公共无效scheduleTaskUsingCronExpression(){ 现在很长= Sy...

回答 3 投票 0

如何在没有springsecurity的情况下使用BycrpytEncoder?

所以之前我在springboot中使用bcrpytEncoder/passwordEncoder在JPA中使用加密密码注册用户,如下所示: 导入 org.springframework.context.annotation.Bean;

回答 1 投票 0

为什么后端构建镜像时无法连接mysql

当我使用 docker compose up 构建所有服务并在构建阶段后端(spring-boot)无法连接 MySQL 数据库时运行时,它无法为后端构建和运行映像。 我尝试设置所有服务...

回答 1 投票 0

尤里卡豆Springboot 3

我的服务器尤里卡已启动。 但我的应用程序无法工作,因为我有一个错误 *无法启动 bean 'eurekaAutoServiceRegistration'* 你好, 我的环境是 Java 17 和 Springboot 3.2.1 我启动我的电子...

回答 1 投票 0

使用 Spring JpaRepository 时,请考虑在 Spring Boot 的配置中定义一个类型的 bean

美好的一天, 我正在我的 Eclipse IDE 中做一个 Spring Boot 应用程序。当我右键单击 SpringBoot 应用程序文件并作为 Java 应用程序运行时,出现如下错误: 应用程序失败...

回答 1 投票 0

出现错误无法构建kafka消费者

引起:org.apache.common.config.ConfigException:bootstrap.server 中没有给出可解析的引导 URL 当我在配置中添加此内容时: @配置 类主题配置{ 公关...

回答 1 投票 0

实体之间的关系

我是一个简单的初学者,想学习编程,但我有点困惑 我有三个实体:管理员(唯一的卖家)、客户和产品。这些实体之间必须是...

回答 1 投票 0

Access-Control-Allow-Origin 未添加到 Spring Boot 应用程序的 Rest API 中

我创建了一个具有“Spring web”依赖项的新 Spring boot 应用程序。该模板使用Spring boot 3.2.5版本。相关依赖有: 我创建了一个具有“Spring web”依赖项的新 Spring boot 应用程序。该模板使用Spring boot 3.2.5版本。相关依赖项是: <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> 创建休息控制器后,我在 Dart / Flutter 客户端中收到 Error: ClientException: XMLHttpRequest error.。在浏览器中访问 URL 工作正常并返回 JSON。 阅读完问题后,我认为服务器配置中缺少 Access-Control-Allow-Origin 标头。 我尝试将其添加到控制器中: package com.vogella.spring.jsonserver; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.vogella.spring.jsonserver.controller.TutorialCategoryProvider; import com.vogella.spring.jsonserver.model.TutorialCategory; import com.vogella.spring.jsonserver.model.TutorialLink; import java.util.List; @RestController @CrossOrigin(origins = "*") public class CategoryController { private final TutorialCategoryProvider provider; @Autowired public CategoryController(TutorialCategoryProvider yourService) { this.provider = yourService; } @CrossOrigin(origins = "*") @GetMapping("/categories") public List<TutorialCategory> get() { // Your implementation to fetch all links from your data source // For example, from a database or a service return provider.getTutorialCategories(); } } 还尝试将其添加到应用程序的配置中: package com.vogella.spring.jsonserver; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @SpringBootApplication public class RestServiceApplication { public static void main(String[] args) { SpringApplication.run(RestServiceApplication.class, args); } @Bean public WebMvcConfigurer corsConfigurer() { return new WebMvcConfigurer() { @Override public void addCorsMappings(CorsRegistry registry) { System.out.println("Called"); registry.addMapping("/**") .allowedOrigins("*") .maxAge(4800) .allowCredentials(false) .allowedMethods("POST", "GET", "OPTIONS", "DELETE", "PUT") .allowedHeaders("origin", "Content-Type", "X-Requested-With", "X-File-Name", "x-mime-type", "Accept-Encoding", "Authorization", "Content-Range", "Content-Disposition", "Content-Description", "Access-Control-Request-Method", "Access-Control-Request-Headers"); } }; } } 但是如果我通过curl 检查此标头,我看不到它: curl -I http://localhost:8080/categories HTTP/1.1 200 Vary: Origin Vary: Access-Control-Request-Method Vary: Access-Control-Request-Headers Content-Type: application/json Transfer-Encoding: chunked Date: Thu, 25 Apr 2024 11:37:39 GMT 有什么我错过的建议吗? 您找错地方了。 浏览器在实际请求之前发送 OPTIONS 请求以获取有关被调用端点的一些信息。响应标头 Access-Control-Allow-Origin 由 OPTIONS 请求返回,而不是由以下 GET 请求返回。浏览器预先发送的 OPTIONS 请求也可以用curl复制: curl --verbose --request OPTIONS "[endpoint being called]" --header "Origin: [host from which the endpoint is being called]" --header "Access-Control-Request-Method: [http method with which the endpoint is being called]" 因此,在您的情况下,命令行如下所示(我假设 Spring Boot 应用程序为前端和 API 提供服务): curl --verbose --request OPTIONS "http://localhost:8080/categories" --header "Origin: localhost:8080" --header "Access-Control-Request-Method: GET" 我已经根据您的示例设置了一个小型演示应用程序,curl 命令给出了以下输出: * Trying [::1]:8080... * Connected to localhost (::1) port 8080 > OPTIONS /categories HTTP/1.1 > Host: localhost:8080 > User-Agent: curl/8.4.0 > Accept: */* > Origin: localhost:8080 > Access-Control-Request-Method: GET > < HTTP/1.1 200 < Vary: Origin < Vary: Access-Control-Request-Method < Vary: Access-Control-Request-Headers < Access-Control-Allow-Origin: * < Access-Control-Allow-Methods: POST,GET,OPTIONS,DELETE,PUT < Access-Control-Max-Age: 4800 < Allow: GET, HEAD, POST, PUT, DELETE, OPTIONS, PATCH < Content-Length: 0 < Date: Thu, 25 Apr 2024 21:27:40 GMT < * Connection #0 to host localhost left intact 请记住,如果您为 API 添加安全性,即一旦您的 API 需要凭据进行身份验证,Access-Control-Allow-Origin 标头将不再允许使用通配符,并且您必须显式指定所有可能的引用主机名。

回答 1 投票 0

Spring Boot 消费者类也应该是生产者/rabbitmq

我正在使用rabbitmq和springBoot。我有一个消费者当前正在侦听一个队列,并且应该根据收到的消息向另一个队列发送一条新消息。这就是我的问题。我...

回答 1 投票 0

io.micrometer.core.instrument.config.validate.ValidationException:datadog.apiKey 为“null”,但它是必需的

我使用的是 Spring Boot 2.7.7,下面是我的 Maven 依赖项: 这是我在控制器中设置 DatadogConfig 的方法: DatadogConfig 配置 = new DatadogConfig() { @覆盖 ...

回答 2 投票 0

为什么 spring boot 3.2.4 在 jwt.io 成功验证的令牌上给出无效签名错误?

我像这样生成 rsa 密钥: # https://techdocs.akamai.com/iot-token-access-control/docs/generate-rsa-keys # 创建私钥 openssl genrsa -out jwtRSA256-private.pem 2048 # 提取一个pu...

回答 1 投票 0

注册后,将打开以下页面:https://shtura.by/assets/inputmask/jquery.inputmask.min.js

用户注册并登录后,打开以下页面: https://shtura.by/assets/inputmask/jquery.inputmask.min.js 在此输入图像描述 据我了解,此页面仅打开一次...

回答 1 投票 0

使用 CompletableFuture 时不会传播跟踪上下文

以下测试无法正常工作 @测试 void testContextPropagation() 抛出 ExecutionException、InterruptedException { // 使用来自...的测微计跟踪器创建新的跟踪...

回答 1 投票 0

“authorizeExchange()”自版本 6.1 起已弃用并标记为删除

我有以下 Spring Security 配置: @豆 公共SecurityWebFilterChain springSecurityFilterChain (ServerHttpSecurity http) { http.csrf().disable() .authorizeExchan...

回答 1 投票 0

我可以将 OAuth2 与 JWT 结合用于我的前端应用程序吗?

因此,我正在构建一个仅具有“使用 Google 登录”的应用程序,以便以经过身份验证的用户的名义将文件上传到他的谷歌驱动器。 现在我的问题是,因为这对我来说是最好的

回答 2 投票 0

spring boot服务调用另一个spring boot服务,如何使用spring-boot-docker-compose?

我浏览了 https://www.baeldung.com/docker-compose-support-spring-boot 并 教程 https://www.youtube.com/watch?v=lS1GwdIfk0c 这些解释了何时 Spring Boot 应用程序依赖于其他

回答 1 投票 0

Timefold:在学校时间表项目中使用 Spring JPA 的最佳实践

从 GitHub 上的项目(https://github.com/TimefoldAI/timefold-quickstarts/tree/stable/technology/java-spring-boot)开始,在项目中使用 Spring JPA 的最佳实践有哪些斯托...

回答 1 投票 0

为什么 http.server.requests 指标下的 uri 标记中有“/**”值?

有谁知道为什么 Spring Boot Actuator 指标中的 http.server.requests 指标下的 uri 标记中有“/**”值?我正在使用 spring boot 3、千分尺和 spring-boot-starter-actuator

回答 1 投票 0

如果我们在Spring Boot应用程序中使用eclipselink jpa如何进行静态编织

如果我们在Spring Boot应用程序中使用eclipselink jpa,如何进行静态编织。互联网上缺乏足够的文章。我看到的文章使用了de.empulse.eclipselink staticweave-maven-plu...

回答 1 投票 0

SpringBoot JPA 创建错误的 JPQL 并抛出 org.hibernate.exception.SQLGrammarException

我的实体具有 OneToMany 关系。下面是代码: 实体类: @数据 @实体 @Table(名称=“TEST_LADDER”,模式=“TEST_DBO”) 公共类 LadderEntityTemp 实现

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.