spring-mvc 相关问题

基于模型 - 视图 - 控制器(MVC)模式构建Java Web应用程序的框架。它从底层视图技术中提升灵活和分离的代码。

为什么我在运行简单的 Spring Boot 应用程序时总是收到状态为“404”的 Whitelabel 错误页面

我的控制器 @控制器 //@RequestMapping("/") //@ComponentScan("com.spring") //@EnableAutoConfiguration 公共类 HomeController { @Value("${framework.welcomeMessage}") 私有字符串

回答 7 投票 0

从 HandlerInterceptor 抛出 HTTP 状态代码异常

我正在尝试创建一个HandlerIntecerptor,其预处理的代码结构如下 public boolean preHandle(HttpServletRequest req,HttpServletResponse res,对象处理程序)抛出

回答 2 投票 0

SpringMVC 中没有 GET / 的映射

我正在尝试构建 Spring MVC Web 应用程序。 问题出在我的欢迎页面(localhost:8080 /)。在我的输出日志中我看到: 没有 GET / 的映射 我将欢迎页面设置为 URL:“/spring-mvc-login...

回答 7 投票 0

如何在 Spring 应用程序中记录 JSON 请求?

经过多次尝试,我在这里询问是否有一种方法可以在将输入的 JSON 请求反序列化为 Java 对象之前记录它。 我的尝试: 1:我能够在

回答 1 投票 0

Angular + Spring Boot:将所有 Angular 路由转发到 Angular,并将所有 API 转发到 Spring 控制器

我有一个 Spring Boot 应用程序和一个 Angular 应用程序。我想从 Spring Boot 应用程序提供 Angular 应用程序。我构建了 Angular 应用程序并将所有文件(包括 index.html 文件)移动到 /resources/st...

回答 3 投票 0

我们如何以及应该在 Spring REST 控制器中验证可选查询参数

我有一个 Spring REST API 端点定义如下: @GetMapping(“/书籍”) 公共列表 getBooks( @RequestParam @NotNull 长id, @RequestParam(必需= false)

回答 1 投票 0

为什么@HeadMapping在Spring MVC中不可用?

Spring框架中包含以下注解: @GetMapping、@PostMapping、@PutMapping、@DeleteMapping 和 @PatchMapping 用于标准 Spring MVC 控制器方法。然而@HeadMap...

回答 2 投票 0

Minecraft Forge NoClassDefFoundError:org/apache/commons/logging/LogFactory

我正在尝试在与 Minecraft Forge Mod 相同的代码库中运行 SpringBoot 应用程序。我使用的是版本 1.12.2,ForgeGradle“2.3”。使用 Intellij 运行时一切运行良好。但是

回答 1 投票 0

使用 Spring RestClient 调用 AWS S3 预先设计的链接时出现错误请求错误

我正在尝试使用(新的)Spring RestClient 对 AWS S3 预先设计的链接进行 GET 调用。 AWS 文档中的此类链接示例: https://examplebucket.s3.us-east-1.amazonaws.com/test.txt...

回答 1 投票 0

Spring Security 6 - 如何处理 InvalidBearerTokenException

春季启动3 春季安全6 我做错了什么? 定义异常处理程序 @ExceptionHandler({AuthenticationException.class }) 公共 ResponseEntityhandleInvalidBearerTo... 春季启动3 Spring 安全 6 我做错了什么? 定义异常处理程序 @ExceptionHandler({AuthenticationException.class }) public ResponseEntity<Object> handleInvalidBearerToken(AuthenticationException exception) { Error error = new Error().errorCode(Error.ErrorCodeEnum.INVALID_DATE_RANGE) .errorDescription(exception.getMessage()); return new ResponseEntity<Object>(error, new HttpHeaders(), HttpStatus.UNAUTHORIZED); } @ExceptionHandler({InvalidBearerTokenException.class }) public ResponseEntity<Object> handleInvalidBearerToken(InvalidBearerTokenException exception) { Error error = new Error().errorCode(Error.ErrorCodeEnum.INVALID_DATE_RANGE) .errorDescription(exception.getMessage()); return new ResponseEntity<Object>(error, new HttpHeaders(), HttpStatus.UNAUTHORIZED); } 安全链* @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.csrf(AbstractHttpConfigurer::disable) .authorizeHttpRequests(authorize -> authorize.requestMatchers("/v1/**")) .authorizeHttpRequests(authorize -> authorize.anyRequest().authenticated()) .oauth2ResourceServer((oauth2) -> oauth2.jwt(Customizer.withDefaults())) .exceptionHandling(ex-> ex.accessDeniedPage("/localhost")); // Some random url return http.build(); } @ExceptionHandler({AuthenticationException.class }) public ResponseEntity<Object> handleInvalidBearerToken(AuthenticationException exception) { Error error = new Error().errorCode(Error.ErrorCodeEnum.INVALID_DATE_RANGE) .errorDescription(exception.getMessage()); return new ResponseEntity<Object>(error, new HttpHeaders(), HttpStatus.UNAUTHORIZED); } 2024-07-04T16:58:27.093+05:30 TRACE 953112 --- [Alpha-Project] [nio-8081-exec-1] .s.r.w.a.BearerTokenAuthenticationFilter : Failed to process authentication request org.springframework.security.oauth2.server.resource.InvalidBearerTokenException: An error occurred while attempting to decode the Jwt: Jwt expired at 2024-07-02T17:36:11Z at org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationProvider.getJwt(JwtAuthenticationProvider.java:103) at org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationProvider.authenticate(JwtAuthenticationProvider.java:88) at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:182) at org.springframework.security.authentication.ObservationAuthenticationManager.lambda$authenticate$1(ObservationAuthenticationManager.java:54) at io.micrometer.observation.Observation.observe(Observation.java:565) at org.springframework.security.authentication.ObservationAuthenticationManager.authenticate(ObservationAuthenticationManager.java:53) at org.springframework.security.oauth2.server.resource.web.authentication.BearerTokenAuthenticationFilter.doFilterInternal(BearerTokenAuthenticationFilter.java:137) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.springframework.security.web.ObservationFilterChainDecorator$ObservationFilter.wrapFilter(ObservationFilterChainDecorator.java:240) at org.springframework.security.web.ObservationFilterChainDecorator$ObservationFilter.doFilter(ObservationFilterChainDecorator.java:227) at org.springframework.security.web.ObservationFilterChainDecorator$VirtualFilterChain.doFilter(ObservationFilterChainDecorator.java:137) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:107) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:93) at org.springframework.security.web.ObservationFilterChainDecorator$ObservationFilter.wrapFilter(ObservationFilterChainDecorator.java:240) at org.springframework.security.web.ObservationFilterChainDecorator$ObservationFilter.doFilter(ObservationFilterChainDecorator.java:227) at org.springframework.security.web.ObservationFilterChainDecorator$VirtualFilterChain.doFilter(ObservationFilterChainDecorator.java:137) at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:91) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.springframework.security.web.ObservationFilterChainDecorator$ObservationFilter.wrapFilter(ObservationFilterChainDecorator.java:240) at org.springframework.security.web.ObservationFilterChainDecorator$ObservationFilter.doFilter(ObservationFilterChainDecorator.java:227) at org.springframework.security.web.ObservationFilterChainDecorator$VirtualFilterChain.doFilter(ObservationFilterChainDecorator.java:137) at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:90) at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:75) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.springframework.security.web.ObservationFilterChainDecorator$ObservationFilter.wrapFilter(ObservationFilterChainDecorator.java:240) at org.springframework.security.web.ObservationFilterChainDecorator$ObservationFilter.doFilter(ObservationFilterChainDecorator.java:227) at org.springframework.security.web.ObservationFilterChainDecorator$VirtualFilterChain.doFilter(ObservationFilterChainDecorator.java:137) at org.springframework.security.web.context.SecurityContextHolderFilter.doFilter(SecurityContextHolderFilter.java:82) at org.springframework.security.web.context.SecurityContextHolderFilter.doFilter(SecurityContextHolderFilter.java:69) at org.springframework.security.web.ObservationFilterChainDecorator$ObservationFilter.wrapFilter(ObservationFilterChainDecorator.java:240) at org.springframework.security.web.ObservationFilterChainDecorator$ObservationFilter.doFilter(ObservationFilterChainDecorator.java:227) at org.springframework.security.web.ObservationFilterChainDecorator$VirtualFilterChain.doFilter(ObservationFilterChainDecorator.java:137) at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:62) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.springframework.security.web.ObservationFilterChainDecorator$ObservationFilter.wrapFilter(ObservationFilterChainDecorator.java:240) at org.springframework.security.web.ObservationFilterChainDecorator$ObservationFilter.doFilter(ObservationFilterChainDecorator.java:227) at org.springframework.security.web.ObservationFilterChainDecorator$VirtualFilterChain.doFilter(ObservationFilterChainDecorator.java:137) at org.springframework.security.web.session.DisableEncodeUrlFilter.doFilterInternal(DisableEncodeUrlFilter.java:42) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.springframework.security.web.ObservationFilterChainDecorator$ObservationFilter.wrapFilter(ObservationFilterChainDecorator.java:240) at org.springframework.security.web.ObservationFilterChainDecorator$AroundFilterObservation$SimpleAroundFilterObservation.lambda$wrap$0(ObservationFilterChainDecorator.java:323) at org.springframework.security.web.ObservationFilterChainDecorator$ObservationFilter.doFilter(ObservationFilterChainDecorator.java:224) at org.springframework.security.web.ObservationFilterChainDecorator$VirtualFilterChain.doFilter(ObservationFilterChainDecorator.java:137) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:233) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:191) at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:113) at org.springframework.web.servlet.handler.HandlerMappingIntrospector.lambda$createCacheFilter$3(HandlerMappingIntrospector.java:195) at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:113) at org.springframework.web.filter.CompositeFilter.doFilter(CompositeFilter.java:74) at org.springframework.security.config.annotation.web.configuration.WebMvcSecurityConfiguration$CompositeFilterChainProxy.doFilter(WebMvcSecurityConfiguration.java:230) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:352) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:268) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140) at org.springframework.web.filter.ServerHttpObservationFilter.doFilterInternal(ServerHttpObservationFilter.java:107) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:389) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:904) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190) at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63) at java.base/java.lang.Thread.run(Thread.java:1583) Caused by: org.springframework.security.oauth2.jwt.JwtValidationException: An error occurred while attempting to decode the Jwt: Jwt expired at 2024-07-02T17:36:11Z at org.springframework.security.oauth2.jwt.NimbusJwtDecoder.validateJwt(NimbusJwtDecoder.java:193) at org.springframework.security.oauth2.jwt.NimbusJwtDecoder.decode(NimbusJwtDecoder.java:139) at org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationProvider.getJwt(JwtAuthenticationProvider.java:99) ... 85 common frames omitted 向调用者返回自定义错误消息 Spring Security异常处理指南 您可以添加如下authenticationEntryPoint @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.csrf(AbstractHttpConfigurer::disable) .authorizeHttpRequests(authorize -> authorize.requestMatchers("/v1/**")) .authorizeHttpRequests(authorize -> authorize.anyRequest().authenticated()) .oauth2ResourceServer((oauth2) -> oauth2.jwt(Customizer.withDefaults()).authenticationEntryPoint(((request, response, authException) -> { if (authException instanceof InvalidBearerTokenException){ //do something } }))) .exceptionHandling(ex-> ex.accessDeniedPage("/localhost")); // Some random url return http.build(); }

回答 1 投票 0

Springboot mySQL 无法确定合适的驱动类

这是我的属性文件: 服务器端口=8081 spring.datasource.url=jdbc:mysql://lin-836046-17428-mysql-primary.servers.linodedb.net:3306/mailing_db spring.datasource.username=mailing_usr spring.data...

回答 1 投票 0

通过 Header.jsp 重定向到页面

我正在尝试弄清楚如何从 JavaScript 函数重定向回我的搜索结果:在给定搜索结果显示的 JSP 标题上,有一个“返回结果列表”l...

回答 1 投票 0

设置 bean 属性“mongoOperations”时无法解析对 bean“mongoTemplate”的引用

这个问题的答案已经很少了。但它们都不适合我。 我一生都无法弄清楚为什么会出现错误。 以下是我尝试过的方法: 使用

回答 2 投票 0

org.springframework.validation.BeanPropertyBindingResult:0 个错误

有人可以帮忙解决这个问题吗? 我无法在 spring 项目中配置验证。 实体类 公共类员工{ @Size(min = 2,message = "名称必须至少包含 2 个符号")

回答 1 投票 0

无法弄清楚为什么我的loginController无法验证用户身份。 Spring Security 让我抓狂

这是我收到的错误: 2024-07-03T00:19:09.320-04:00 TRACE 10178 --- [fitBuddyApp] [nio-8080-exec-7] o.s.s.w.a.ExceptionTranslationFilter:发送 AnonymousAuthenticationToken [Principal=

回答 1 投票 0

响应后删除tmp文件?

我的用例: 根据用户请求创建 tmp 文件(我实际上不需要创建真实文件,但我需要有 java.io.File 实例) 处理这个文件 以 json 形式返回文件和其他元数据 删除...

回答 1 投票 0

警告:上下文初始化期间遇到异常 - 取消刷新尝试

错误如下图所示。问题是,如下所示,这个 XmlWebApplicationContext 不需要出现,因为它再次注入 bean。如何避免呢? org.springframework.web.context.sup...

回答 6 投票 0

登录页面未使用 oath2/oidc 进行重定向

我尝试在我的 spring mvc 非启动应用程序中使用 oauth2 和 oidc 提供程序来实现 spring security。 预期行为: 当用户访问安全端点时,他将被重定向到...

回答 1 投票 0

WebApplicationContext 中的@Autowired Spring MVC 测试不起作用

我正在尝试在我的 spring mvc 控制器中进行测试,但我的 applicationContext 始终为 null。 导入 org.springframework.beans.factory.annotation.Autowired 导入org.springframework.test.context....

回答 3 投票 0

如何在 Spring MVC 中调用 API 并从更新方法中选择正确的选项

我一直在关注 MVC 的在线教程,但在更新时遇到了障碍。 在控制器中使用了 updateStudent() 方法并传入了 id,但是在 updateStudent() 内部我有一个...

回答 1 投票 0

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