运行Okta Spring Security托管登录示例时遇异常及POM问题
解决Okta Spring示例项目的POM路径错误与运行时异常
1. 处理POM parent路径错误
这个错误是因为单独拉取了okta-hosted-login子模块,而该模块的pom.xml依赖仓库根目录的聚合POM文件,导致IDEA无法找到正确的父POM。解决方法二选一:
- 克隆完整仓库:
再执行启动命令即可。git clone https://github.com/okta/samples-java-spring.git cd samples-java-spring/okta-hosted-login - 修改子模块POM配置:
编辑okta-hosted-login/pom.xml中的parent节点,移除错误的relativePath,让Maven自动从远程仓库拉取Spring Boot父POM:<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.8</version> <!-- 保持和原项目一致的版本 --> <relativePath/> <!-- 替换原来的../pom.xml --> </parent>
2. 解决java.lang.NoSuchMethodError异常
这个异常是thymeleaf-extras-springsecurity5与Thymeleaf核心版本不兼容导致的:IWebContext.getExchange()是Thymeleaf 3.1.x新增的方法,项目中存在版本不匹配的依赖。
解决步骤:
- 在
pom.xml中添加版本统一配置,确保Thymeleaf核心与security扩展版本一致:<properties> <thymeleaf.version>3.1.2.RELEASE</thymeleaf.version> <thymeleaf-extras-springsecurity5.version>3.1.2.RELEASE</thymeleaf-extras-springsecurity5.version> </properties> - 清理Maven缓存并重新构建启动:
mvn clean install -U -Dokta.oauth2.issuer=https://{yourOktaDomain}/oauth2/default -Dokta.oauth2.clientId={clientId} -Dokta.oauth2.clientSecret={clientSecret}
完成以上两步后,项目应该可以正常启动并访问。
内容的提问来源于stack exchange,提问作者Fernando
相关产品推荐
相关产品推荐

