[Personal Coding Learning Project] Travel Info Sharing Website - Error Code Analaysis & Difficulties

코딩기록·2024년 12월 28일

[ Giving Access to DB to Others]

- Issue

  • I developed the to-do list page using MariaDB on my computer. However, when trying to share the application with a friend, they were unable to access the MariaDB database.

- Solution

1) Using ngrok:

Utilized ngrok to expose the local backend server via a public URL, making it accessible externally.

2) Configuring CORS:

Added CORS settings on the backend server to allow requests from different domains.

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("http://localhost:3000") // 프론트엔드 주소
                .allowedMethods("GET", "POST", "PUT", "DELETE")
                .allowedHeaders("*")
                .allowCredentials(true);
    }
}

[ Real-Time Sharing with Friends]

- Issue

  • I wanted to make that updates made by one user are reflected in real-time for other users in todo list.

- Solution

  • Used setInterval function
        // =============== 초기 실행 함수 ================== //
       // # 전체 ToDo 목록 렌더링
       fetchAndRenderAllTodos();
       // # 상대방과 공유 할 수 있도록, 2초마다 viewingsession 확인 후 렌더링
       setInterval((e) => {
           renderViewingSession()
       }, 2000);

[ sqlSessionTemplate ]

  1. Error Code

    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'todoRepository' defined in file [todoRepository 저장 경로]: Cannot resolve reference to bean 'sqlSessionTemplate' while setting bean property 'sqlSessionTemplate'

  2. Cause

  • Wrong type-aliases-package setting

  • MyBatis을 이용한 JDBC 구현 중, @Mapper 클래스인 TodoRepository와 매핑되는 매퍼 파일(xml)에 resultTyle을 아래와 같이 입력하였는데,

     -- resultType에 클래스 이름만 적으려면,
     -- application.yml 파일의 mybatis:type-aliases-package에 파일 경로를 적어줘야 함
    <select id="findTodos" resultType="Todo">
  • 그런데 application.xml 파일에 type-aliases-package 경로를 잘못 지정해 두었음


[ AddEventListnet for Label ]

  • I wanted to trigger event lisnter when check status of the input[type='checkbox'] is changed, but wasn't sure what type of event it should be.

  <li class="task">
                <label for="\${todo.id}">
                    <input type="checkbox" id="\${todo.id}" \${todo.completed ? 'checked' : ''}>
                    <p class="\${todo.isCompleted ? 'completed' : 'pending'}">\${todo.task}</p>
                </label>
                <div class="settings">
                    <i class="uil uil-ellipsis-h"></i>
                    <ul class="task-menu">
                        <li>
                            <i class="uil uil-pen"></i>Edit
                        </li>
                    </ul>
                </div>
            </li>
            
  • Resolution : The check status of the Checkbox is changed basically when the label tag(both p tag and input tag), so I can simply add 'click' event listener to p tag and input tag.
  • Side Note) The check status of a checkbox could be checked on 'check' proprerty. ($Checkbox.check)

0개의 댓글