[트러블슈팅] 6. 스프링부트 실습 중 발생한 문제

최재원's avatar
Mar 24, 2025
[트러블슈팅] 6. 스프링부트 실습 중 발생한 문제

1. 기존 게시판 데이터에서 nickname field 를 추가하다 발생한 문제

notion image
  • 해당 쿼리문 실행 중 에러 발생
  • Board 클래스에서 nickname field를 추가하고
  • db.sql 파일에서 insert쿼리를 실행 할 때 nickname 값을 추가하지 않아서 문제 발생 1
  • db.sql 파일에서 insert쿼리를 실행 할 때 nickname 컬럼을 추가하지 않아서 문제 발생 2
  • db.sql 파일에서 insert쿼리를 실행 할 때 nickname 값을 추가할 때 ‘’홑따옴표를 사용하지 않아서 문제 발생 3
  • 해결

2. application.properties 파일에 코드를 붙여넣기 한 뒤 에러 발생

# vscode console highlight spring.output.ansi.enabled=always # utf-8 server.servlet.encoding.charset=utf-8 server.servlet.encoding.force=true # DB spring.datasource.driver-class-name=org.h2.Driver spring.datasource.url=jdbc:h2:mem:test spring.datasource.username=sa spring.datasource.password= spring.h2.console.enabled=true # JPA table create spring.jpa.hibernate.ddl-auto=create # query log spring.jpa.show-sql=true # dummy data | classpath->templates 폴더 spring.sql.init.data-locations=classpath:db/data.sql # create dummy data after ddl-auto create spring.jpa.defer-datasource-initialization=true # mustache request expose spring.mustache.servlet.expose-request-attributes=true
notion image
notion image
  • db/data.sql 파일이 없기 때문에 실행이 불가하다는 에러다
  • 일단 주석 처리하고 진행하자

3. 주소 맵핑 중 발생한 문제

1. 테스트로 만들어둔 HelloController와 같은 맵핑을 사용해서 발생한 문제

  • 에러 코드를 끝까지 읽지 않고 앞 부분만 읽어봤다가 낭패를 봤다
notion image
notion image
notion image
  • HelloController에 @Controller를 주석처리하자
  • 해결

2. 상품 등록 버튼을 눌렀을 때 발생한 에러

notion image
notion image
  • post요청을 지원하지 않는다는 에러
notion image
  • 요청 방식은 post가 맞다
notion image
  • Controller에서 맵핑 방식을 잘못 작성했다
notion image
  • 해결

4. req객체에 담은 데이터 mustache에 사용 시 문제

notion image
10행에 '이름'이라는 이름의 메서드나 필드가 없고 근본 원인이 없습니다
notion image
notion image
req에 model 이름으로 키 값을 줬는데, 키 값으로 접근하지 않아서 생긴 문제
  • 해결

5. 맵핑 컨트롤러에 파라미터를 받을 때 어노테이션을 사용하지 않아 발생한 문제

notion image
notion image
리플렉션을 통해 파라미터 플래그를 사용 할 수 없다고 나왔다
notion image
notion image
formdata를 파라미터로 받으려면 @RequestParam()을 작성해줘야 받을 수 있다
해결

5. java코드 다 짜놓고 view파일 제대로 확인 안 해서 발생한 문제

notion image
notion image
name 이라는 매개변수가 없다고 나옴
notion image
name attribute를 작성하지 않아서 발생함
notion image
해결

6. h2 데이터 베이스는 문자열을 “?” 가 아닌 ‘?’를 사용한다

insert into store_tb (name, price, stock) values ("바나"', 3000, 40); insert into store_tb (name, price, stock) values ("딸기", 2000, 60); insert into log_tb (store_id, qty, total_price, buyer) values (1,5,15000,"ssar"); insert into log_tb (store_id, qty, total_price, buyer) values (1,5,15000,"ssar"); insert into log_tb (store_id, qty, total_price, buyer) values (2,5,10000,"cos");
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Failed to execute SQL script statement #1 of class path resource [db/data.sql]: insert into store_tb (name, price, stock) values ("바나나", 3000, 40)
Spring Boot 애플리케이션이 data.sql 파일을 실행하는 과정에서 SQL 문을 실행하지 못해 발생한 오류
insert into store_tb (name, price, stock) values ('바나나', 3000, 40); insert into store_tb (name, price, stock) values ('딸기', 2000, 60); insert into log_tb (store_id, qty, total_price, buyer) values (1,5,15000,'ssar'); insert into log_tb (store_id, qty, total_price, buyer) values (1,5,15000,'ssar'); insert into log_tb (store_id, qty, total_price, buyer) values (2,5,10000,'cos');
이렇게 바꾸고 동작함
해결
Share article

jjack1