Notice
Recent Posts
Recent Comments
Link
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Archives
Today
Total
관리 메뉴

한바다

스프링부트 에러 Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 본문

React

스프링부트 에러 Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.

한바다진화 2024. 8. 8. 19:58

✅ 게시판 제목 클릭 상세페이지이동 에러

게시판에서 제목을 클릭 했을때 상세페이지로 이동하기 위해 스프링 부트에서 아래와 같이 코드를 추가 하였다

[Post-mapper.xml]

<!--특정 게시글 보기 -->
<select id="findPostId" parameterType="int" resultType="com.six.dto.Post">
  SELECT * FROM Post WHERE post_no = #{postNo}
 </select>

 

[PostMapper.java]

@Mapper
public interface PostMapper {
  Post findPostById(@Param("postNo") int postNo);
 }

[PostService.java]

public interface PostService {
  Post findPostById(int postNo);
}

[PostServiceImpl.java]

@Override
public Post findPostById(int postNo) {
    return postMapper.findPostById(postNo);

}

[PostController.java]

@GetMapping("/board/{postNo}")
public Post findById(@PathVariable("postNo") int postNo) {
     return postService.findPostId(postNo)l
}

 위에는 에러를 수정한 화면이다. 해당 로직을 실행 시 아래와 같은 오류 가 발생 하였다.

위 코드는 게시판 제목을 클릭하였을때 상세페이지를 이동하도록 스프링부트 코드를 구현 하였으며

리액트에서 axios api주소 "api/board/${postNo}러 연결해준다.

[오류화면1]

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in 
class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invalid mapping on handler class [com.six.controller.PostController]: public com.six.dto.Post com.six.controller.PostController.findPostById(int)

▶ 위 오류코드는 controller 어노테이션 매핑 주소에서 잘못되었음을 확인 할 수 있었다.

controller 페이지 상단에 @RequestMapping("/api")가 있는데

@GetMapping("/api/board/${postNo}") 로 api가 중복되어 있었다.

또한 매퍼쪽에 postNo를 postNO로 오타가 있었다!!

 

[오류화면2]

Caused by: java.lang.IllegalStateException: Invalid mapping on handler class 
[com.six.controller.PostController]: public com.six.dto.Post com.six.controller.PostController.findPostById(int)
	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lambda$detectHandlerMethods$1(AbstractHandlerMethodMapping.java:287) ~[spring-webmvc-6.1.11.jar:6.1.11]

▶ 위 오류 코드 확인 시 어노테이션에 붙어 있는 문법이 잘못되었다!

(수정 전) @GetMapping("/board/${postNo}")

(수정 후)@GetMapping("/board/{postNo}")  즉  $를 없애줘야 한다!

 

위와 비슷했던 구문이 수업시간에 있었던 것 같다~!!!!

//await axios.delete(`user?id=${id}`) //Mysql-Gradle UserController에서...
@DeleteMapping("/{id}")
public void deleteUser(@PathVariable("id") indt id {
    userService.deleteUser(id);

}

 

⬛ Profile Controller에서 발생한 에러

[수정 전 코드]

@RestController
@RequestMapping("/profile")
public class ProfileController {
 @Autowired
  private ProfileService profileservice; //'ProfileService'임포트 해준 후 ctrl +엔터시 소문자로 시작하는 변수가 아래 뜬다!! ctrl+enter는 요술 같은 것
  
  @GetMapping("/watching")
  public ResponseEntity<List<UserProfile>> getProfile() {
     return ResponseEntity.ok(service.getProfile());
  
  }
  @PostMapping("/upload")
  public ResponseEntity<String> insertProfile(@RequestParam("file") MultipartFile[] file,
                                              @RequestParam("username") String username,
                                              @RequestParam("profileImageUrl") String profileImageUrl){
                                              
                  service.uploadProfile(files,username,profileImageUrl);
                  return ResponseEntity.ok("이미지업로드성공");
}

->발생한 에러 두가지
1. 하단 service에 계속 빨간줄이 생겼다.. 하단에 작성한 service는 어디선가 불러와야 하는데
상단에 해당단어가 없었던 것이다!! 결국 내가 구문을 잘 못 작성한 걸 알았다. 
@Autowired
  private ProfileService profileservice
 => 요쪽 영역에서 profileservice 가 아닌 service 이다!!!
 그곳에서 service를 기재해줘야 하단에서 service로 구문들을 불러올 수 있는 것이다. 코드는 연결되어 있는 것,연결연결 잊지말자!!
 2. 두번째는 (@RequestParam("file") 요곳에서 file라고 작성을 하니
   service.uploadProfile(files,username,profileImageUrl);이곳에서 files이 빨간줄이 생겼다.
   이곳도 마찬가지로 위에서 연결이 되어 있는 것이니 상단에 files라고 변경해줬다. 왜냐면 앞단 service
   에서 files였었다!! 코드는 연결연결 유기적으로 연결되어 있는 것을 잊지 말자!!!

 

⬛ 리액트 App.js import에서 에러

import에서는 파일 경로에 따라 가는길을 잘 지정해줘야 한다!!

- 첫번째 잘못 경로 지정 파일

import Main from './component/Main'; 

▶위에는 component파일 아래에 Main이 있다고 설정 해줬는데 정작 Main.js는 conponent폴더 경로를 벗어 나 있었다.

그래서 Main.js를 conponent폴더로 쏙 넣어 주었다

 

- 두번째 잘못 경로 지정 파일

import Header from "./component/layout/Header";
import Footer from "./component/layout/Footer";
import Banner from "./component/layout/Banner";

▶ 위에는 component폴더 아래 layout폴더 아래 파일들이 있는 것인데 폴더 경로를 무시하고 바로 파일을 지정해줘서

오류가 발생 하였다!!

 

- 세번째 js파일 하단에 export default 파일이름; 을 해줘야 파일을 내보내 주고 import를 할수 가 있다.

- 또한 파일위에 파일이 있을 시 import Header from "./component/layout/Header"; 가 아닌

import Header from "../../component/layout/Header";  => 요련 형식을 ../를 두번 해줘야 한다!!!

 

⬛ Entity 정리

ResponseEntity : 사용자가 요청한 응답을 개발자가 다시 사용자한테 전달할 때 사용

HttpEntity : Http 요청 또는 응답의 본문(body)과 헤더(headers)를 포함한 객체

Http 요청을 보낼 때 본문과 헤더를 설정하고자 할 때 사용

본문(body) : 실제 전송될 데이터 ex) 아이디 비밀번호 작성한 글 등

헤더(headers) : HTTP 헤더 정보를 포함 ex) 글자인지 이미지인지 동영상인지

 

ResponseEntity (Response = 응답 / Http를 상속받아서 Http 기능에 응답에 대한 기능을 추가로 설정한 Entity)

ResponseEntity<String이면 String, Integer면 Integer