JHipster从8.1.0升级至8.2.1/8.3.0失败,存在语法错误
JHipster升级至8.2.1/8.3.0时的Java语法解析错误问题
问题概况
- 项目基于JHipster 8.0.0搭建,已顺利升级至8.1.0版本
- 尝试升级到8.2.1或8.3.0版本时触发错误,升级流程中断
- 错误核心提示:解析
src\main\java\com\pccw\hktms\mp\config\SecurityConfiguration.java文件时,第42行第9列存在语法错误——期望分号;,但实际遇到return关键字 - 手动核查代码发现,该行
.requestMatchers(mvc.pattern("/management/**")).hasAuthority(AuthoritiesConstants.ADMIN))末尾确实遗漏了分号 - 已将npm(v10.5.2)和Node.js(v20.12.2)更新至最新稳定版,问题依旧存在
错误详情
create src\test\java\com\pccw\hktms\mp\config\RedisTestContainersSpringContextCustomizerFactory.java ERROR! ERROR! Error parsing file src\main\java\com\pccw\hktms\mp\config\SecurityConfiguration.java: Error: Sad sad panda, parsing errors detected in line: 42, column: 9! Expecting --> ';' <-- but found --> 'return' <--! ->compilationUnit ->ordinaryCompilationUnit ->typeDeclaration ->classDeclaration ->normalClassDeclaration ->classBody ->classBodyDeclaration ->classMemberDeclaration ->methodDeclaration ->methodBody ->block ->blockStatements ->blockStatement ->statement ->statementWithoutTrailingSubstatement ->expressionStatement at package com.pccw.hktms.mp.config; import com.pccw.hktms.mp.security.*; import tech.jhipster.config.JHipsterProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher; import org.springframework.web.servlet.handler.HandlerMappingIntrospector; @Configuration @EnableMethodSecurity(securedEnabled = true) public class SecurityConfiguration { private final JHipsterProperties jHipsterProperties; public SecurityConfiguration( JHipsterProperties jHipsterProperties) { this.jHipsterProperties = jHipsterProperties; } @Bean public SecurityFilterChain filterChain(HttpSecurity http, MvcRequestMatcher.Builder mvc) throws Exception { http .csrf(csrf -> csrf .disable()) .authorizeHttpRequests(authz -> // prettier-ignore authz .requestMatchers(mvc.pattern("/api/authenticate")).permitAll() .requestMatchers(mvc.pattern("/api/admin/**")).hasAuthority(AuthoritiesConstants.ADMIN) .requestMatchers(mvc.pattern("/api/**")).authenticated() .requestMatchers(mvc.pattern("/v3/api-docs/**")).hasAuthority(AuthoritiesConstants.ADMIN) .requestMatchers(mvc.pattern("/management/health")).permitAll() .requestMatchers(mvc.pattern("/management/health/**")).permitAll() .requestMatchers(mvc.pattern("/management/info")).permitAll() .requestMatchers(mvc.pattern("/management/prometheus")).permitAll() .requestMatchers(mvc.pattern("/management/**")).hasAuthority(AuthoritiesConstants.ADMIN)) return http.build(); } @Bean MvcRequestMatcher.Builder mvc(HandlerMappingIntrospector introspector) { return new MvcRequestMatcher.Builder(introspector); } } at file:///C:/Users/02007425/IdeaProjects/mp-api/node_modules/generator-jhipster/dist/generators/bootstrap/support/java-unused-imports-transform.mjs:20:27 at Transform.<anonymous> (file:///C:/Users/02007425/IdeaProjects/mp-api/node_modules/@yeoman/transform/dist/transform.js:42:19) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Transform.transform [as _transform] (file:///C:/Users/02007425/IdeaProjects/mp-api/node_modules/@yeoman/transform/dist/transform.js:16:37) ERROR! An error occured while running jhipster:upgrade#prepareUpgradeBranch ERROR! ERROR! Command failed with exit code 1: npx --no jhipster --force --skip-install --skip-git --ignore-errors --no-insight --skip-checks Error: Command failed with exit code 1: npx --no jhipster --force --skip-install --skip-git --ignore-errors --no-insight --skip-checks at makeError (file:///C:/Program%20Files/nodejs/node_modules/generator-jhipster/node_modules/execa/lib/error.js:60:11) at handlePromise (file:///C:/Program%20Files/nodejs/node_modules/generator-jhipster/node_modules/execa/index.js:124:26) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async UpgradeGenerator.prepareUpgradeBranch (file:///C:/Program%20Files/nodejs/node_modules/generator-jhipster/dist/generators/upgrade/generator.js:168:21) at async UpgradeGenerator.executeTask (file:///C:/Program%20Files/nodejs/node_modules/generator-jhipster/node_modules/yeoman-generator/dist/actions/lifecycle.js:244:13) at async runLoop.add.once (file:///C:/Program%20Files/nodejs/node_modules/generator-jhipster/node_modules/yeoman-environment/dist/environment-base.js:395:17) { shortMessage: 'Command failed with exit code 1: npx --no jhipster --force --skip-install --skip-git --ignore-errors --no-insight --skip-checks',
npm doctor检查结果
>npm doctor Check Value Recommendation/Notes npm ping ok npm -v ok current: v10.5.2, latest: v10.5.2 node -v ok current: v20.12.2, recommended: v20.12.2 npm config get registry ok using default registry (https://registry.npmjs.org/) git executable in PATH ok C:\Program Files\Git\cmd\git.EXE global bin folder in PATH ok C:\Program Files\nodejs
内容的提问来源于stack exchange,提问作者Raymond Choi
相关产品推荐
相关产品推荐

