레벨업 일지

[에러] cannot resolve symbol 'validation' 본문

JAVA/spring

[에러] cannot resolve symbol 'validation'

24시간이모자란 2023. 2. 7. 15:34

문제

너 왜 빨간색이니

@NotBlank 어노테이션을 사용하기 위해 jakarta 라이브러리를 import 했는데, validation 부분이 빨간색이 뜨면서 인식을 못한다. jakarta 대신 javax.validation 을 사용해도 마찬가지였다.

공식문서를 다시 봐도 패키지 네임 문제는 아닌듯 하다.

원인

스프링부트 2.3 부터 Validation Starter 가 Spring Boot Web과 분리가 되면서 동작을 하지 않는다.
그래서 dependencies 를 추가로 작성해야 한다.

해결

https://docs.gradle.org/current/userguide/war_plugin.html

The War Plugin

The default behavior of the War task is to copy the content of src/main/webapp to the root of the archive. Your webapp directory may of course contain a WEB-INF sub-directory, which may contain a web.xml file. Your compiled classes are compiled to WEB-INF/

docs.gradle.org

  1. gradle 설정에 war 플러그인 추가해주었다.
  2. dependencies 에 다음 코드 추가
	//jakarta
	providedCompile 'jakarta.platform:jakarta.jakartaee-web-api:8.0.0'

spring 3.x.x 버전부터 javax 말고 jakarta 를 사용하는것이 권장된다.

'JAVA > spring' 카테고리의 다른 글

[에러] 스프링 java 버전 에러  (0) 2023.02.23
[Annotation] @란?  (0) 2023.02.08
[에러] error: variable name not initialized in the default constructor  (0) 2023.02.07
[에러] failed :compileJava  (0) 2023.02.07
[에러] Compile() 문제  (0) 2023.02.07
Comments