1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Spring boot で java.lang.NoSuchMethodError: 'org.thymeleaf.web.IWebExchange org.thymeleaf.context.IWebContext.getExchange()' のエラー

1
Posted at

環境

spring boot 2.7.2
gradleプロジェクト

エラーログ

SpringSecurityとThymeleafを連携させ、認証情報をViewで表示させようとしたところエラー。

There was an unexpected error (type=Internal Server Error, status=500).
'org.thymeleaf.web.IWebExchange org.thymeleaf.context.IWebContext.getExchange()'
java.lang.NoSuchMethodError: 'org.thymeleaf.web.IWebExchange org.thymeleaf.context.IWebContext.getExchange()'
	at org.thymeleaf.extras.springsecurity5.util.Spring5VersionSpecificUtility.isWebMvcContext(Spring5VersionSpecificUtility.java:80)
	at org.thymeleaf.extras.springsecurity5.util.SpringVersionSpecificUtils.isWebMvcContext(SpringVersionSpecificUtils.java:118)
	at org.thymeleaf.extras.springsecurity5.util.SpringSecurityContextUtils.getAuthenticationObject(SpringSecurityContextUtils.java:127)
	at org.thymeleaf.extras.springsecurity5.auth.AuthUtils.getAuthenticationObject(AuthUtils.java:102)
	at org.thymeleaf.extras.springsecurity5.dialect.processor.AuthenticationAttrProcessor.doProcess(AuthenticationAttrProcessor.java:66)
	at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74)
	at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95)
	at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633)
	at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1314)
	at org.thymeleaf.engine.OpenElementTag.beHandled(OpenElementTag.java:205)
...

解決

原因 : 依存関係でバージョンを指定しているため。

Spring Securityのバージョンのそれぞれに対応した、thymeleaf-extras-springsecurityのライブラリを使用しなくてはならないです。
そのバージョンの整合性の関係で発生したエラーだと考えました。


以下のように記述するとエラーが解消できました。

build.gradle
dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.springframework.boot:spring-boot-starter-security'

    //バージョンを指定せずに記述
	implementation group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity5'

	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation 'org.springframework.security:spring-security-test'
}

以下のようにthymeleaf-extras-springsecurityのバージョンを指定するとエラーが起こりました。

build.gradle
//バージョンを指定している
implementation group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity5', version: '3.1.0.M1'

バージョンの指定をなくせばエラーは解消できました。

build.gradle
implementation group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity5'
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?