spring 相关问题

Spring Framework是Java平台上应用程序开发的开源框架。其核心是对基于组件的体系结构的丰富支持,目前它拥有20多个高度集成的模块。

@GetMapping 和 @GetExchange 有什么区别?

从Spring 6开始,引入了@GetExchange、@PostExchange、@PutExchange、@DeleteExchange、@PatchExchange。 据我所知,我们已经有了相同的注释,可以做同样的事情@GetMa...

回答 1 投票 0

如何在 MockWebServer 中使用 @BeforeEach 和 @AfterEach 注解?

在进行集成测试时,我试图用一个或多个 MockWebServer 来模拟控制器的行为,但没有找到解决方案。 我看到这里的帖子说 MockWebServer 应该......

回答 1 投票 0

Spring Cloud Gateway + Spring Cloud Security + Keycloak 如何连接

他这几天一直在尝试用 Keycloak 连接 s-c-gateway 和 s-c-security。我希望位于网关后面的模块没有 keycloak 配置。 春天来了吗...

回答 4 投票 0

Spring boot:无法打破bean之间的依赖循环

我正在使用 Spring Boot 创建一个航空公司网站。我有一个 Seat 类和一个 Flight 类,它们代表数据库中的表。这个想法是,每当添加航班时,座位......

回答 1 投票 0

Spring参数验证注解不验证

我有一个像这样的控制器方法: 导入 javax.validation.Valid; 导入 javax.validation.constraints.Min; 导入 javax.validation.constraints.NotNull; @控制器 @RequestMapping(值 = "/fo...

回答 3 投票 0

spring 4 计算注释的占位符

我有一个注释,带有一个 String 属性,我希望它在运行时计算。 在我所说的具体情况下 @Scheduled(initialDelayString = "10000" ) 根据o...

回答 1 投票 0

原因:org.messaging.handler.annotation.support.MethodArgumentNotValidException:无法解析 public void 中索引 1 处的方法参数

我正在开发 Kafka Consumer App,在手动尝试确认和确认时出现以下错误。可能是什么原因导致了这个问题? 错误详情: org.springframework.kafka.listener.

回答 1 投票 0

如何访问springs中的另一个字段@Value

就像标题所示,我想使用 springs @Value 注释访问另一个字段值。 我想这样做是为了通过另一个字段 id 解析字段值。例如:我有一个字段 id 和一个字段

回答 1 投票 0

Spring Boot 提供被安全阻止的静态内容

我启动了 Spring Boot + Angular 应用程序,现在我想将整个应用程序部署为 jar。所以我创建了 Maven 配置,其中构建了 Angular 应用程序,然后将其复制到 /target/classes/resource...

回答 7 投票 0

百里香叶+春天。提交响应后无法创建会话

我有一个网络应用程序使用带有 thymeleaf 的引导程序形式: 我有一个网络应用程序使用带有百里香的引导程序形式: <form th:method="POST" th:action="@{/main}" th:object="${order}"> <div class="mb-3"> <label for="companyNameInput" class="form-label">Company Name</label> <input type="text" th:field="*{companyName}" class="form-control" id="companyNameInput" aria-describedby="companyHelp"> <div id="companyHelp" class="form-text">What is the name of your company?</div> <div style="color:red" th:if="${#fields.hasErrors('companyName')}" th:errors="*{companyName}">IF::ERROR</div> </div> <div class="mb-3"> <label for="contactPersonInput" class="form-label">Contact Person</label> <input type="text" th:field="*{contactName}" class="form-control" id="contactPersonInput" aria-describedby="nameHelp"> <div id="nameHelp" class="form-text">What is the name of the person we are going to talk to?</div> <div style="color:red" th:if="${#fields.hasErrors('contactName')}" th:errors="*{contactName}">IF::ERROR</div> </div> <div class="mb-3"> <label for="contactNumberInput" class="form-label">Number</label> <input type="text" th:field="*{number}" class="form-control" id="contactnumberInput" aria-describedby="numberHelp"> <div id="numberHelp" class="form-text">Leave us your number so we can contact with you to negotiate next steps!</div> <div style="color:red" th:if="${#fields.hasErrors('number')}" th:errors="*{number}">IF::ERROR</div> </div> <div class="mb-3"> <label for="contactEmailInput" class="form-label">Email</label> <input type="email" th:field="*{email}" class="form-control" id="contactEmailInput" aria-describedby="emailHelp"> <div id="emailHelp" class="form-text">We'll sent you an email to recall about your order when it's ready to go. We'll never share your email with anyone else.</div> <div style="color:red" th:if="${#fields.hasErrors('email')}" th:errors="*{email}">IF::ERROR</div> </div> <div class="mb-3"> <label for="contactAdressInput" class="form-label">Address</label> <input type="text" th:field="*{address}" class="form-control" id="contactAdressInput" aria-describedby="addressHelp"> <div id="addressHelp" class="form-text">Where would you like to get your order?</div> <div style="color:red" th:if="${#fields.hasErrors('address')}" th:errors="*{address}">IF::ERROR</div> </div> <div class="mb-3"> <label for="categorySelect" class="form-label">Product Category</label> <select class="form-select" th:field="*{category}" aria-label="categorySelect" id="categorySelect" aria-describedby="categoryHelp"> <option th:value="Cigarettes" selected>Cigarettes</option> <option th:value="Vapes">Vapes</option> <option th:value="Devices">Smoking Devices</option> <option th:value="Drinks">Drinks</option> <option th:value="Food">Food</option> </select> <div id="categoryHelp" class="form-text">Where would you like to get your order?</div> <div style="color:red" th:if="${#fields.hasErrors('category')}" th:errors="*{category}">IF::ERROR</div> </div> <div class="mb-3"> <label for="additionalInformationTextarea" class="form-label">Additional Information</label> <textarea class="form-control" th:field="*{additionalInformation}" id="additionalInformationTextarea" rows="5"></textarea> <div style="color:red" th:if="${#fields.hasErrors('additionalInformation')}" th:errors="*{additionalInformation}">IF::ERROR</div> </div> <div class="mb-3 form-check"> <input type="checkbox" class="form-check-input js-checkbox" id="privacyCheck"> <label class="form-check-label" for="privacyCheck">I agree to all the company's terms and conditions and the data processing rule.</label> </div> <button type="submit" class="btn btn-primary js-button" disabled>Place an order</button> </form> 这个控制器可以处理这个: @GetMapping("/main") public String mainPage(@ModelAttribute("order") Order order) { return "main"; } @PostMapping("/main") public String createOrder(@ModelAttribute("order") @Valid Order order, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return "main"; } order.setStatus(String.valueOf(OrderStatus.Pending)); orderDetailsService.saveOrder(order); return "redirect:/main"; } 但是当我进入我的网站时,我遇到了这个异常,看起来我的网站有点冻结(就像手风琴或轮播不起作用)。但如果我从 html 代码中删除“表单”,网站将再次运行。如果我多次重新加载页面,则可能会显示表单并且网站会停止冻结。 2024-05-13T19:34:49.173+03:00 INFO 13472 --- [retailShop] [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2024-05-13T19:34:49.173+03:00 INFO 13472 --- [retailShop] [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2024-05-13T19:34:49.175+03:00 INFO 13472 --- [retailShop] [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms 2024-05-13T19:34:49.432+03:00 ERROR 13472 --- [retailShop] [nio-8080-exec-2] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-2] Exception processing template "main": Error during execution of processor 'org.thymeleaf.spring6.processor.SpringActionTagProcessor' (template: "main" - line 383, col 44) org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring6.processor.SpringActionTagProcessor' (template: "main" - line 383, col 44) at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:117) ~[thymeleaf-3.1.2.RELEASE.jar:3.1.2.RELEASE] 2024-05-13T19:34:49.438+03:00 ERROR 13472 --- [retailShop] [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring6.processor.SpringActionTagProcessor' (template: "main" - line 383, col 44)] with root cause java.lang.IllegalStateException: Cannot create a session after the response has been committed 2024-05-13T19:34:49.453+03:00 ERROR 13472 --- [retailShop] [nio-8080-exec-2] s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request [/main] as the response has already been committed. As a result, the response may have the wrong status code. 如何解决这个问题? 看来我已经解决了! https://github.com/thymeleaf/thymeleaf-spring/issues/222 我将此代码添加到我的 SecurityConfig.class 方法中: public SecurityFilterChain filterChain(HttpSecurity http) { http.sessionManagement(httpSecuritySessionManagementConfigurer -> httpSecuritySessionManagementConfigurer.sessionCreationPolicy(SessionCreationPolicy.ALWAYS)); }

回答 1 投票 0

如何使用Spring data JPA保存双向关联而不进行级联?

假设我在父子之间有双向一对多关联,映射如下: 父级.java: @实体 公开课家长{ @ID 私有整数 ID; @OneToMany(mappedBy...

回答 2 投票 0

在 Spring Kafka 中为批量监听器实现自定义错误处理程序

我将向我的容器工厂添加自定义错误处理程序 这是我的要求: 我有一个批处理侦听器,即使某个特定记录由于

回答 1 投票 0

是否可以在thyemleaf中选择性地使用片段?

在SpringBoot3中,我用这样的片段制作了一段代码。 我想选择性地使用它。例如,...

回答 1 投票 0

转储Spring启动配置

我们的运维人员希望在应用程序启动时将 Spring boot 配置(即所有属性)转储到日志文件中。我认为这可以通过使用注释 @

回答 4 投票 0

JPA Criteria Api 未生成正确的 sql

我的条件查询中有一段,我希望生成一个sql段作为子字符串(manifest_url, instr(manifest_url, '?') - 14, 10) 最终路径manifestUrlPath = JpaUtils.ge...

回答 1 投票 0

运行Spring Boot应用程序后不启动tomcat服务器

我的 spring boot 应用程序在运行后没有启动 tomcat 服务器。 localhost:8080 输出“无法访问此站点”。 intellJIDEA社区版需要安装才能...

回答 1 投票 0

如何防止Spring Boot中的@Async方法参数中的数组被清除?

我遇到了 @Async 方法注释的某种线程问题。正在处理从 csv 到 DB 的数据,对于每 10000 条记录,将这些记录传递给另一个用 @Async 注释的方法。 ...

回答 1 投票 0

如何在应用程序启动后在运行时加载Spring Boot中的属性而不需要重新启动

应用程序属性 春天.年龄=10 启动 Spring Boot 应用程序后,我想更改属性。 应用程序属性 春天.年龄=20 年龄 = 20 应该加载,无需

回答 2 投票 0

如何在java spring boot应用程序中存储json响应直到特定日期/时间戳

我有 25 个项目的 json 响应,其中每个项目都包含一个时间戳。但是我只想存储过去 7 天的数据项。我怎样才能在java spring boot应用程序中做到这一点? 我尝试使用...

回答 0 投票 0

Spring Data:使用@CreatedBy为ManyToMany关系添加额外的审核属性到JoinTable

在 Spring Data 中为多对多关系向连接表添加附加属性的最佳实践是什么? 更准确地说,我想添加一些用于使用 @Created 进行日志记录的信息...

回答 1 投票 0

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