MelRanG
719
2021-08-01 20:46:37 작성 2021-08-01 20:47:35 수정됨
11
284

스프링부트 첫 실행시 404에러가 발생합니다



스프링 부트와 AWS로 혼자 구현하는 웹 서비스

책으로 부트를 배우는 중입니다. 버전이 업그레이드 진행되서 작가님이 업데이트 내역을 블로그에 적어서 그 방식대로 진행중이었습니다.

https://jojoldu.tistory.com/539


발생하는 에러는

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Aug 01 20:44:47 KST 2021
There was an unexpected error (type=Not Found, status=404).

이고 구글링해보니 Application파일이 최상단에 위치해야한다해서 최상단에 위치시켰습니다.
그럼에도 불구하고 에러가 발생하는데 원인이 무엇인가요??




0
  • 답변 11

  • 하루히즘
    869
    2021-08-01 21:08:55
    코드를 봐야 알지 않을까요?
  • MelRanG
    719
    2021-08-01 21:13:26

    하루히즘 

    앗 죄송합니다

    Application.java

    package com.jojoldu.book.springboot;

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;

    @SpringBootApplication
    public class Application {
    public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
    }
    }


    HelloController.java

    package com.jojoldu.book.springboot.web;

    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;

    @RestController
    public class HelloController {

    @GetMapping("/hello")
    public String hello(){
    return "hello";
    }
    }
  • ㅉㅉㅉ
    2021-08-01 22:32:12

    hello.jsp 혹은 hello.html같은 View단에 파일이 존재하는 건가요?

    404에러가 발생한다는 건 파일을 찾을 수 없을 때 도출됩니다.

  • 하루히즘
    869
    2021-08-01 22:43:13

    어떤 상황에서 위의 에러가 발생했는지, IDE 콘솔에는 어떤 메시지가 출력됐는지 등등 더 많은 정보가 있으면 좋을 것 같습니다.

  • MelRanG
    719
    2021-08-01 22:52:14

    매너가 사람을 만든다  view단에 파일은 따로 존재하지 않고 혹시 그거때문인지 싶어 저자블로그와 다른분 글을 봤는데 안만들어도 잘 작동한다고 하더라구요 ㅠ

  • MelRanG
    719
    2021-08-01 22:56:32

    하루히즘 

    저 코드를 실행하면 에러가 발생합니다. 콘솔메시지에서 에러로그는 따로 뜨지않는거 같아서 안올렸는데 우선 첨부하겠습니다!


    2021-08-01 22:53:59.437  INFO 14332 --- [           main] com.jojoldu.book.springboot.Application  : Starting Application using Java 1.8.0_251 on DESKTOP-J6G8NQV with PID 14332 (C:\Users\se\IdeaProjects\freelec-springboot2-webservice\build\classes\java\main started by se in C:\Users\se\IdeaProjects\freelec-springboot2-webservice)

    2021-08-01 22:53:59.441  INFO 14332 --- [           main] com.jojoldu.book.springboot.Application  : No active profile set, falling back to default profiles: default

    2021-08-01 22:54:00.547  INFO 14332 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)

    2021-08-01 22:54:00.557  INFO 14332 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]

    2021-08-01 22:54:00.557  INFO 14332 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.41]

    2021-08-01 22:54:00.683  INFO 14332 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext

    2021-08-01 22:54:00.683  INFO 14332 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1189 ms

    2021-08-01 22:54:00.917  INFO 14332 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'

    2021-08-01 22:54:01.100  INFO 14332 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''

    2021-08-01 22:54:01.111  INFO 14332 --- [           main] com.jojoldu.book.springboot.Application  : Started Application in 2.101 seconds (JVM running for 4.364)



    추가로 JUnit으로 테스트했을 때 뜨는 메시지는



    java.lang.AssertionError: Status expected:<200> but was:<404>

    at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:59)

    at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:122)

    at org.springframework.test.web.servlet.result.StatusResultMatchers.lambda$matcher$9(StatusResultMatchers.java:627)

    at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:196)

    at com.jojoldu.book.springboot.HelloControllerTest.hello가_리턴된다(HelloControllerTest.java:26)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.lang.reflect.Method.invoke(Method.java:498)

    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:688)

    at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)

    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)

    at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)

    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)

    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)

    at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)

    at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)

    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)

    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)

    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)

    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)

    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)

    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)

    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:210)

    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:206)

    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:131)

    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:65)

    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)

    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)

    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)

    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)

    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)

    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)

    at java.util.ArrayList.forEach(ArrayList.java:1257)

    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)

    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)

    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)

    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)

    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)

    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)

    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)

    at java.util.ArrayList.forEach(ArrayList.java:1257)

    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)

    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)

    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)

    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)

    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)

    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)

    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)

    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)

    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)

    at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)

    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248)

    at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211)

    at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226)

    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199)

    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132)

    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)

    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)

    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)

    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.lang.reflect.Method.invoke(Method.java:498)

    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)

    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)

    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)

    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)

    at com.sun.proxy.$Proxy2.stop(Unknown Source)

    at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:133)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.lang.reflect.Method.invoke(Method.java:498)

    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)

    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)

    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)

    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)

    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)

    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)

    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)

    at java.lang.Thread.run(Thread.java:748)


    2021-08-01 22:55:25.040  INFO 23048 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'


    HelloControllerTest > hello가_리턴된다() FAILED

        java.lang.AssertionError at HelloControllerTest.java:26

    1 test completed, 1 failed

    > Task :test FAILED


    FAILURE: Build failed with an exception.


    * What went wrong:

    Execution failed for task ':test'.

    > There were failing tests. See the report at: file:///C:/Users/se/IdeaProjects/freelec-springboot2-webservice/build/reports/tests/test/index.html


    * Try:

    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.


    * Get more help at https://help.gradle.org

    BUILD FAILED in 6s

    3 actionable tasks: 1 executed, 2 up-to-date


  • Mambo
    6k
    2021-08-01 23:04:53

    hello에 대한 view 및 템플릿 엔진이 없으므로 404 오류가 발생하는게 정상입니다. 스프링 MVC에 대한 선행 학습이 필요해보입니다. 컨트롤러의 핸들러 함수가 String을 반환하는 경우 문자열을 출력하는게 아닌 해당 이름을 가진 view를 찾습니다.

  • 하루히즘
    869
    2021-08-02 12:23:50
    안 만들어도 작동한다는 건 컴파일은 된다는 얘기가 아닐까 싶네요 ㅋㅋㅋㅋ
  • MelRanG
    719
    2021-08-02 12:45:31

     


      view단 문제면 
     

    Whitelabel Error Page

    이렇게 뜨지 않고 404에러로 뜨지 않나요??

    일단 버전업 하는 과정에서 발생한 에러라 다시 버전 다운그레이드하니까 해결은 했습니다!

  • Mambo
    6k
    2021-08-02 13:06:28

    기본적으로 에러에 대하여 whitelabel 페이지로 응답하는 BasicErrorController가 있습니다.

    BasicErrorController에 의해 404 Not Found 응답 대신 에러 페이지로 응답한 거에요.

    whitelabel을 비활성화 하는 프로퍼티를 설정해보세요.

  • MelRanG
    719
    2021-08-02 13:16:28

    Mambo 

    네 감사합니다 알려주신 키워드로 검색해보겠습니다!

  • 로그인을 하시면 답변을 등록할 수 있습니다.