inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링 MVC 2편 - 백엔드 웹 개발 활용 기술

스프링 메시지 소스 사용

not found 에러

해결된 질문

1337

정민교

작성한 질문수 50

0

@Controller
@RequestMapping("/message/items")
@RequiredArgsConstructor
public class MessageItemController {

    private final ItemRepository itemRepository;

    @GetMapping
    public String items(Model model) {
        System.out.println("MessageItemController.items");
        List<Item> items = itemRepository.findAll();
        model.addAttribute("items", items);
        return "message/items";
    }

    @GetMapping("/{itemId}")
    public String item(@PathVariable long itemId, Model model) {
        Item item = itemRepository.findById(itemId);
        model.addAttribute("item", item);
        return "message/item";
    }

...
}

http://localhost:8080/message/items get 요청을 보내면 not found에러가 발생하는데 이유를 찾을수가 없네요.

 

resources static 경로에 있는 index.html은 잘 찾아옵니다.

http://localhost:8080 을 입력하면 브라우저에 페이지가 잘 나와요.

templates 경로도 올바르게 되어있는 것 같은데 이유를 모르겠습니다

 

2024-06-07T00:51:34.677+09:00 DEBUG 20684 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : GET "/message/items", parameters={} 
2024-06-07T00:51:34.724+09:00 DEBUG 20684 --- [nio-8080-exec-1] o.s.w.s.r.ResourceHttpRequestHandler     : Resource not found 
2024-06-07T00:51:34.735+09:00 DEBUG 20684 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.servlet.resource.NoResourceFoundException: No static resource message/items.] 
2024-06-07T00:51:34.736+09:00 DEBUG 20684 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed 404 NOT_FOUND


debug 로그가 위와 같이 나옵니다.
thymeleaf 의존성을 추가는 했는데 templates 경로에서 찾지 않는 것 같아서요. 맞나요?
의존성 추가는 되어있습니다.

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

 

spring mvc

답변 1

0

OMG

안녕하세요. 정민교님, 공식 서포터즈 OMG입니다.

 

아래 로깅이 출력되는걸로 보아 application.properties 설정파일에 별도 설정을 추가하신 것 같습니다.

image

그리고 로깅 메시지에 items. 뒤에 html이 없는것도 설정파일에 별도 적용된 내용으로 인한 것이지 않나 예상합니다.

image

application.properties 전체 코드를 복사하여 올려주시겠어요?

그리고 타임리프 의존성 추가되어있는지도 확인해주세요^^image

감사합니다.

1

정민교

아 이 부분은 해결했습니다. 다 제대로 되어있었습니다.

프로젝트 메인 메소드를 다른 걸 실행해서 그런 것 같아요. 프로젝트를 spring initailizr로 새로 만들고 그냥 src랑 test 폴더를 복붙하다보니까 main 메소드가 있는 클래스가 두 개가 되었는데, 잘못된 걸 실행했습니다... 이런 멍청한 일로 2시간을 날렸읍니다....

이미지 업로드와 db 트랜잭션 묶는법

0

40

1

Could not resolve org.springframework.boot:spring-boot-starter-validation:2.4.4

0

45

2

MessageSourceTest 코드

0

46

1

인터셉터 에러 설정

0

47

1

resolveArgument()메서드 질문

0

54

1

43강 검증1 에서 실패 로직 관련 질문있습니다.

0

52

2

타임리프 3.X 버전 rendering, serializer 에러 해결 방법

2

130

3

스프링 빈에 등록이 안되는거 같은데 어떻게 하면 좋을까요?ㅠㅠ

0

86

3

pdf 오타 문의

0

54

1

ItemUpdateForm 검증 관련 질문입니다.

0

46

1

22page 링크 주소 변경

0

55

2

특정 데이터와 파일을 함께 저장 시, 테이블 구조 질문

0

52

1

섹션3번 수업에 대한 질문입니다.

0

78

2

@Autowired 보다 더 좋은 방법이 어떤 걸까요?

0

84

2

타입컨버터 가 람다랑 비슷해 보이는데 저의 생각이 맞는지?.

0

63

1

자바스크립트 인라인에서 객체 직렬화 시 오류가 납니다

0

140

3

스프링부트 - 오류페이지2 에서 500.html 에서 쓰인 객체 질문

0

62

1

톰캣 에러 페이지가 안보입니다.

0

98

2

apiEceptionController에서 센드 에러 호출하면 안되는지?

0

80

1

세션 타임아웃시 쿠키 삭제 방법이 없나요?

0

116

2

ApiExceptionController 질문드립니다.

0

62

1

셀렉박스 챕터에서 option value에 ==배송 방식 선택== 이것을 넣은 이유가 궁금함, 이렇게 구상해도 되는지?

0

64

1

MemberRepository 필드의 fianl 선언 유무

0

83

2

혹시 index.html 에서는 fragment 사용이 안되는건가요

0

57

1