localhost 오류 질문드립니다.

24.05.02 20:38 작성 조회수 41

0

package controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@Slf4j
public class HomeController {
    @RequestMapping("/")
    public String home() {
        log.info("home controller");
        return "home";
    }
}

 

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="fragments/header :: header">
    <title>Hello</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div class="container">
    <div th:replace="fragments/bodyHeader :: bodyHeader" />
    <div class="jumbotron">
        <h1>HELLO SHOP</h1>
        <p class="lead">회원 기능</p>
        <p>
            <a class="btn btn-lg btn-secondary" href="/members/new">회원 가입</a>
            <a class="btn btn-lg btn-secondary" href="/members">회원 목록</a>
        </p>
        <p class="lead">상품 기능</p>
        <p>
            <a class="btn btn-lg btn-dark" href="/items/new">상품 등록</a>
            <a class="btn btn-lg btn-dark" href="/items">상품 목록</a>
        </p>
        <p class="lead">주문 기능</p> <p>
        <a class="btn btn-lg btn-info" href="/order">상품 주문</a>
        <a class="btn btn-lg btn-info" href="/orders">주문 내역</a>
    </p>
    </div>
    <div th:replace="fragments/footer :: footer" />
</div> <!-- /container -->
</body>
</html>

 

 

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<div class="header" th:fragment="bodyHeader">
    <ul class="nav nav-pills pull-right">
        <li><a href="/">Home</a></li>
    </ul>
    <a href="/"><h3 class="text-muted">HELLO SHOP</h3></a>
</div>

 

 

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<div class="footer" th:fragment="footer">
    <p>&copy; Hello Shop V2</p>
</div>

 

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:fragment="header">
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrinkto-fit=no">
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="/css/bootstrap.min.css" integrity="sha384-
ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
          crossorigin="anonymous">
    <!-- Custom styles for this template -->
    <link href="/css/jumbotron-narrow.css" rel="stylesheet">
    <title>Hello, world!</title>
</head>

 

 

이렇게 다 했는데 localhost:8080 누르면 아무 화면도 나오지않습니다. 어떤 오류때문에 그런 것인지 알 수가 없습니다.

감사합니다.

답변 1

답변을 작성해보세요.

0

인프런 AI 인턴님의 프로필

인프런 AI 인턴

2024.05.03

안녕하세요, 인프런 AI 인턴입니다.

whdk333님의 코드를 살펴보았을 때, 문제의 원인이 될 수 있는 몇 가지 포인트를 짚어 보겠습니다.

  1. 컨트롤러 설정 확인: HomeController에서 @RequestMapping("/")을 통해 매핑된 URL이 올바르게 작동하는지 확인하셔야 합니다. / 경로로 요청이 올바르게 도달하는지 로그를 통해 확인해 보세요.

  2. Thymeleaf 설정 확인: 반환된 문자열 “home”이 Thymeleaf를 통해 올바른 뷰로 매핑되고 있는지 확인하세요. resources/templates 디렉토리 내에 home.html 파일이 존재하는지 확인해 보세요. Spring Boot는 Thymeleaf 설정이 올바르게 되어 있다면, 이 경로에 있는 home.html을 찾아 렌더링을 시도합니다.

  3. 정적 자원 경로 확인: CSS, JS와 같은 정적 자원의 경로가 올바른지 확인하세요. Spring Boot에서는 정적 자원을 resources/static 디렉토리 아래에 두면 자동으로 제공됩니다. 만약 정적 자원의 경로가 잘못되어 있거나 파일이 누락되었다면, 페이지가 제대로 렌더링되지 않을 수 있습니다.

  4. 스프링 부트 로그 확인: 애플리케이션 실행 시 콘솔 로그에 오류 메시지가 없는지 확인해 보세요. 스프링 부트는 애플리케이션이 시작할 때 중요한 정보를 로그를 통해 출력하기 때문에, 여기서 문제의 원인을 찾을 단서를 얻을 수 있습니다.

이 평가를 토대로 애플리케이션이 올바르게 작동하지 않는 구체적인 이유를 찾기 위해 하나씩 확인해 보시기 바랍니다. 문제가 해결되지 않을 경우, 보다 상세한 오류 메시지나 로그 내용을 함께 제공해 주시면, 좀 더 구체적인 해결 방안을 모색할 수 있을 것입니다.

감사합니다.

whdk333님의 프로필

whdk333

질문자

2024.05.03

댓글 감사드립니다.

위의 방법들로 다 해봤습니다. 컨트롤러 설정도 확인했고, 타임리프도 잘 설정됐고, css외 js도 올바르게 들어갔습니다. 스프링부트 로그 오류메시지도 딱히 없습니다. 어떤 것이 문제일까요??

2024-05-03T23:45:52.447+09:00 INFO 26192 --- [ restartedMain] jpabook.jpashop.JpashopApplication : Starting JpashopApplication using Java 17.0.10 with PID 26192 (C:\study\jpashop\out\production\classes started by User in C:\study\jpashop)

2024-05-03T23:45:52.450+09:00 INFO 26192 --- [ restartedMain] jpabook.jpashop.JpashopApplication : No active profile set, falling back to 1 default profile: "default"

2024-05-03T23:45:52.524+09:00 INFO 26192 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable

2024-05-03T23:45:52.524+09:00 INFO 26192 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'

2024-05-03T23:45:53.685+09:00 INFO 26192 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.

2024-05-03T23:45:53.742+09:00 INFO 26192 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 29 ms. Found 0 JPA repository interfaces.

2024-05-03T23:45:54.535+09:00 INFO 26192 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)

2024-05-03T23:45:54.549+09:00 INFO 26192 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]

2024-05-03T23:45:54.550+09:00 INFO 26192 --- [ restartedMain] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.19]

2024-05-03T23:45:54.628+09:00 INFO 26192 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext

2024-05-03T23:45:54.629+09:00 INFO 26192 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2103 ms

2024-05-03T23:45:54.785+09:00 INFO 26192 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...

2024-05-03T23:45:54.979+09:00 INFO 26192 --- [ restartedMain] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection conn0: url=jdbc:h2:tcp://localhost/~/jpashop user=SA

2024-05-03T23:45:54.980+09:00 INFO 26192 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.

2024-05-03T23:45:54.993+09:00 INFO 26192 --- [ restartedMain] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:tcp://localhost/~/jpashop'

2024-05-03T23:45:55.162+09:00 INFO 26192 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]

2024-05-03T23:45:55.274+09:00 INFO 26192 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.4.4.Final

2024-05-03T23:45:55.331+09:00 INFO 26192 --- [ restartedMain] o.h.c.internal.RegionFactoryInitiator : HHH000026: Second-level cache disabled

2024-05-03T23:45:55.674+09:00 INFO 26192 --- [ restartedMain] o.s.o.j.p.SpringPersistenceUnitInfo : No LoadTimeWeaver setup: ignoring JPA class transformer

2024-05-03T23:45:56.144+09:00 INFO 26192 --- [ restartedMain] p6spy : #1714747556144 | took 12ms | statement | connection 2| url jdbc:h2:tcp://localhost/~/jpashop

select * from INFORMATION_SCHEMA.SEQUENCES

select * from INFORMATION_SCHEMA.SEQUENCES;

2024-05-03T23:45:57.213+09:00 INFO 26192 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)

2024-05-03T23:45:57.227+09:00 DEBUG 26192 --- [ restartedMain] org.hibernate.SQL :

drop table if exists category cascade

2024-05-03T23:45:57.246+09:00 INFO 26192 --- [ restartedMain] p6spy : #1714747557246 | took 17ms | statement | connection 3| url jdbc:h2:tcp://localhost/~/jpashop

 

2024-05-03T23:45:57.315+09:00 INFO 26192 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'

2024-05-03T23:45:57.549+09:00 WARN 26192 --- [ restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning

2024-05-03T23:45:57.579+09:00 INFO 26192 --- [ restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]

2024-05-03T23:45:58.015+09:00 INFO 26192 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729

2024-05-03T23:45:58.056+09:00 INFO 26192 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path ''

2024-05-03T23:45:58.067+09:00 INFO 26192 --- [ restartedMain] jpabook.jpashop.JpashopApplication : Started JpashopApplication in 6.319 seconds (process running for 7.109)

2024-05-03T23:46:30.947+09:00 INFO 26192 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'

2024-05-03T23:46:30.948+09:00 INFO 26192 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'

2024-05-03T23:46:30.949+09:00 INFO 26192 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms