요즘 현업을 시작하면서
환경변수 세팅 , 세팅 , 세팅 .. 하느냐고
너무 바쁜것 같다. 세팅이 진짜 절반인것같다.
그리고 스프링 부트와 스프링은 확실하게 다르다.
(나는 이 둘이 비슷하다라고 생각되지 않는다.)
결과값
시작
기본적으로 프로젝트를 생성하면,
여기까지는 기본적으로 만들어져있을 것이다.
이제 웹 페이지를 띄우기 위한 방법이 필요한데
⭐⭐⭐⭐⭐
Spring Boot는 Spring과 다르게 Server가 자체적으로
내장 되어있기 때문에 Server을 껐다 켰다 할 필요가 없다.
application.properties
server.address=0.0.0.0
server.servlet.context-path=/
server.port=8080
spring.mvc.view.prefix= /WEB-INF/views/
spring.mvc.view.suffix= .jsp
#Datasource Configuration
spring.datasource.hikari.maximum-pool-size=4
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=[본인해당아이디]
spring.datasource.password=[본인비밀번호]
#그리고 여긴 샵이 주석임
신기한건 Spring의 root-context / Servlet 에서 DB사용과
서버에대한 주소 Path, 이런것을 다
⭐⭐⭐⭐⭐
Application.properties 여기다가 선언해주는것이다.
정말 당황 스러웠다. 스프링 레거시는 알아서 다 적어주는데..
+ 디비연결 안되면 웹 또는 콘솔에 DB연결하라는 Error 계속 뜰것이다.
TestController.java
package com.example.test;
import javax.sql.DataSource;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class TestController {
@RequestMapping(value = "/index")
public String test() throws Exception {
return "index";
}
}
이건 그나마 Spring이랑 비슷한 부분인것 같다.
Controller를 통해서 Mapping 해주는 역할 (RequestMapping 오랜만에 봐서 반갑다.)
pom.xml
<!-- jsp를 연결시켜주는 tag s -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!-- jsp를 연결시켜주는 tag e -->
pom.xml 에 이것까지 선언해주면 아마 Error = 404 는 일어날일 없을 것이다.
index.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>오픈레이어스 예제</title>
<style>
.map {
height: 960px;
width: 100%;
}
</style>
</head>
<body>
<h1>헬로월드!!!!</h1>
<h1>헬로월드!!!!</h1>
</body>
</html>
이제 마지막이다 jsp파일만 생성해주면 된다
난 간단하게 index.jsp 로 지었다.
폴더 잘 만들어 주도록 하자 아니면 index.jsp 파일을 못찾는다.
자 그럼 여기까지 jsp 페이지 띄우는것까지는
끝
Github 잔디가 안심어진다면 아래 참조
https://chocoboy.tistory.com/165
To be continue..
'Career > Spring Boot' 카테고리의 다른 글
[Spring Boot] 스프링부트 Alias 사용방법 (0) | 2022.07.20 |
---|---|
[Spring Boot] 사용하는 방법 (0) | 2022.07.19 |
[Spring Boot] lombok 설치 후 Getter Setter 사용 (0) | 2022.07.19 |
[Spring Boot] Path with "WEB-INF" or "META-INF" 에러 해결방법 (0) | 2022.07.16 |
[Spring Boot] 스프링 부트 프로젝트 생성 및 깃허브 연결 (0) | 2022.07.15 |