背景
参考文档 开发者指南->开发环境运行halo,在 windows 上以开发环境运行 halo。
现象
运行成功无报错,且能成功进入站点初始化。但是在填写初始化信息提交保存的时候页面提示 500 服务器错误
。查看日志后发现有以下堆栈错误:
24-12-12T09:39:39.430+08:00 DEBUG 20168 --- [ parallel-3] r.h.a.e.ReactiveExtensionClientImpl : Successfully retrieved by names from db for v1alpha1/User in 1ms :application:bootRun
2024-12-12T09:39:39.431+08:00 DEBUG 20168 --- [ parallel-3] r.h.app.theme.HaloViewResolver$HaloView : [7941b0ce-16] View name 'setup', model {form=SetupRequest[formData={}], org.springframework.validation.BindingResult.form=org.springframework.validation.BeanPropertyBindingResult: 0 errors, usingH2database=true, thymeleafWebSession=MonoCacheTime, thymeleafWebExchangePrincipal=MonoMapFuseable, _csrf=MonoPeekTerminal, thymeleafSpringSecurityContext=MonoDefaultIfEmpty}
2024-12-12T09:39:42.243+08:00 DEBUG 20168 --- [ parallel-4] r.h.a.e.ReactiveExtensionClientImpl : Successfully retrieved by names from db for v1alpha1/User in 1ms :application:bootRun
2024-12-12T09:39:42.244+08:00 DEBUG 20168 --- [ parallel-4] r.h.app.theme.HaloViewResolver$HaloView : [5596f742-22] View name 'setup', model {form=SetupRequest[formData={}], org.springframework.validation.BindingResult.form=org.springframework.validation.BeanPropertyBindingResult: 0 errors, usingH2database=true, thymeleafWebSession=MonoCacheTime, thymeleafWebExchangePrincipal=MonoMapFuseable, _csrf=MonoPeekTerminal, thymeleafSpringSecurityContext=MonoDefaultIfEmpty}
2024-12-12T09:40:16.969+08:00 DEBUG 20168 --- [ctor-http-nio-4] r.h.a.e.ReactiveExtensionClientImpl : Successfully retrieved by names from db for v1alpha1/User in 1ms :application:bootRun
2024-12-12T09:40:16.977+08:00 DEBUG 20168 --- [oundedElastic-7] r.h.a.i.utils.YamlUnstructuredLoader : Loading from YAML: null
2024-12-12T09:40:16.987+08:00 DEBUG 20168 --- [oundedElastic-7] a.w.r.e.AbstractErrorWebExceptionHandler : [ba0a1eda-28] Resolved [YAMLException: java.nio.charset.MalformedInputException: Input length = 1] for HTTP POST /system/setup
2024-12-12T09:40:16.987+08:00 ERROR 20168 --- [oundedElastic-7] a.w.r.e.AbstractErrorWebExceptionHandler : [ba0a1eda-28] 500 Server Error for HTTP POST "/system/setup"
org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1
at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:213) ~[snakeyaml-2.3.jar:na]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
*__checkpoint ? run.halo.app.infra.console.ProxyFilter [DefaultWebFilterChain]
*__checkpoint ? run.halo.app.infra.console.ProxyFilter [DefaultWebFilterChain]
*__checkpoint ? run.halo.app.security.InitializeRedirectionWebFilter [DefaultWebFilterChain]
*__checkpoint ? run.halo.app.infra.webfilter.LocaleChangeWebFilter [DefaultWebFilterChain]
*__checkpoint ? run.halo.app.security.device.DeviceSessionFilter [DefaultWebFilterChain]
*__checkpoint ? SecurityWebFilterChainProxy [DefaultWebFilterChain]
*__checkpoint ? AuthorizationWebFilter [DefaultWebFilterChain]
*__checkpoint ? ExceptionTranslationWebFilter [DefaultWebFilterChain]
*__checkpoint ? LogoutWebFilter [DefaultWebFilterChain]
*__checkpoint ? ServerRequestCacheWebFilter [DefaultWebFilterChain]
*__checkpoint ? SecurityContextServerWebExchangeWebFilter [DefaultWebFilterChain]
*__checkpoint ? SecurityWebFilterChainProxy [DefaultWebFilterChain]
*__checkpoint ? AnonymousAuthenticationWebFilter [DefaultWebFilterChain]
*__checkpoint ? SecurityWebFilterChainProxy [DefaultWebFilterChain]
*__checkpoint ? SecurityWebFilterChainProxy [DefaultWebFilterChain]
*__checkpoint ? AuthenticationWebFilter [DefaultWebFilterChain]
*__checkpoint ? AuthenticationWebFilter [DefaultWebFilterChain]
*__checkpoint ? AuthenticationWebFilter [DefaultWebFilterChain]
*__checkpoint ? MapOAuth2AuthenticationFilter [DefaultWebFilterChain]
*__checkpoint ? SecurityWebFilterChainProxy [DefaultWebFilterChain]
*__checkpoint ? [DefaultWebFilterChain]
*__checkpoint ? AuthenticationWebFilter [DefaultWebFilterChain]
*__checkpoint ? SecurityWebFilterChainProxy [DefaultWebFilterChain]
*__checkpoint ? ReactorContextWebFilter [DefaultWebFilterChain]
*__checkpoint ? CsrfWebFilter [DefaultWebFilterChain]
*__checkpoint ? CorsWebFilter [DefaultWebFilterChain]
*__checkpoint ? HttpHeaderWriterWebFilter [DefaultWebFilterChain]
*__checkpoint ? SecurityWebFilterChainProxy [DefaultWebFilterChain]
*__checkpoint ? ServerWebExchangeReactorContextWebFilter [DefaultWebFilterChain]
*__checkpoint ? org.springframework.security.web.server.WebFilterChainProxy [DefaultWebFilterChain]
*__checkpoint ? run.halo.app.infra.webfilter.AdditionalWebFilterChainProxy [DefaultWebFilterChain]
*__checkpoint ? org.springframework.web.filter.reactive.ServerWebExchangeContextFilter [DefaultWebFilterChain]
*__checkpoint ? HTTP POST "/system/setup" [ExceptionHandlingWebHandler]
通过搜索引擎搜索可知,报错原因是因为操作系统的编码是GBK, 而文件采用UTF-8编码,两者编码不一致导致。(该问题一般window系统才会出现)
查看当前 windows 系统编码可用命令:
chcp
若输出为: 936
,表示编码格式为 GBK
若输出为: 65001
,表示编码格式为 UTF8
解决方案
我这里采用的是直接修改操作系统默认编码,若有其他更好的方案可在评论区补充。
修改Windows操作系统默认编码可参考文章:win10 配置系统默认utf-8编码
修改编码到 UTF-8 后,删除 ${user.home}/halo2-dev
文件,并且 ui 也重新 build
一下(因为我具体不知道是哪一部分编码不一致了,是h2数据库?ui?亦或是 jar 包? 为了简单所以便全部清除重新build,也请了解这方面的大佬能够解解惑),然后再运行,初始化页面就正常了。