개발 환경 설정 및 툴 사용법

스프링 이니셜라이저 사용해서 스프링 부트 첫 실행 돌려보기 (이클립스, 메이븐)

letsDoDev 2023. 9. 29. 01:53

https://start.spring.io/

위 주소로 링크를 타면 스프링 이니셜라이저 사이트에 접속 가능하다.

1.

개인 프로젝트를 위해 설정은 다음과 같이 지정하였다.

주 언어 : JAVA ( 11 )

DB : Oracle

2.

새로운 워크스페이스(프로젝트를 위한)를 생성하고

아래와 같이 file>import>기존 메이븐 프로젝트 선택

다운로드 받은 zip 파일의 압축을 푼 후 pom.xml 이 존재하는 경로를 복사한 후

import Maven Projects의 Root Directory에 붙여넣기 하고 Browse를 클릭하면

다음과 같이 적용할 수 있다 이후 Finish를 클릭

==>

다음과 같이 이클립스에 프로젝트가 import 된 것을 확인 할 수 있다.

 

+ 수정 사항

pom.xml에서 스프링부트이니셜라이저 설정과 다르기 <java.version>17</java.version> 설정이 잡혀있어

11(내가 설치한 jdk 버전)으로 변경하였다.


▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼개인설정 ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼

여기서부터는 개인마다 많이 상이할 설정이다.

- pom.xml  :

(수정 | 버전호환, 에러 이슈로 약간의 수정을 진행)

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		 <version>2.0.0.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.springboot.myplanner</groupId>
	<artifactId>first-springboot-project</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>first-springboot-project</name>
	<description>myplanner project for Spring Boot</description>
	<properties>
		<java.version>11</java.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-validation</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<scope>runtime</scope>
			<optional>true</optional>
		</dependency>
		<!-- 오라클 연동을 위한 추가 부분 javax.xml.bind  -->
		<dependency>
		    <groupId>javax.xml.bind</groupId>
		    <artifactId>jaxb-api</artifactId>
		    <!-- <version>2.3.1</version> --> <!-- JAXB API 버전에 따라 변경 가능 -->
		</dependency>
		
		<dependency>
            <groupId>oracle.jdbc</groupId>
            <artifactId>OracleDriver</artifactId>
		    <version>19.8.0.0</version>
	        <scope>system</scope>
            <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/ojdbc8.jar</systemPath>
		</dependency>
		
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.security</groupId>
			<artifactId>spring-security-test</artifactId>
			<scope>test</scope>
		</dependency>
		<!-- lombok  -->
		<dependency>
		    <groupId>org.projectlombok</groupId>
		    <artifactId>lombok</artifactId>
		    <optional>true</optional>
		</dependency>
		<!-- ibatis  -->
		<dependency>
        	<groupId>org.mybatis.spring.boot</groupId>
        	<artifactId>mybatis-spring-boot-starter</artifactId>
        	<version>2.1.4</version>
		</dependency>
		
		<!-- Thymeleaf  -->
	   <dependency>
       		 <groupId>org.springframework.boot</groupId>
     	  	 <artifactId>spring-boot-starter-thymeleaf</artifactId>
   		 </dependency>
   		 
		<!-- jsp  -->		
		<dependency>
		       <groupId>javax.servlet</groupId>
		       <artifactId>jstl</artifactId>
		</dependency>
       <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>

 		<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat -->
		<dependency>
		    <groupId>org.springframework.boot</groupId>
		    <artifactId>spring-boot-starter-tomcat</artifactId>
		    <scope>provided</scope>
		</dependency>
		
		<!-- etc  -->
	    <dependency>
        	<groupId>commons-logging</groupId>
       		<artifactId>commons-logging</artifactId>
      		<version>1.1.1</version>
    	</dependency>
		
		</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

- application.properties 파일 : 

DB로 오라클을 사용하였기 때문에 properties에서 OracleDriver를 사용하였다.

MySQL 또는 MariaDB 유저는 다른 package를 사용하여야 할 것이다, --> 구글링 추천 

# server
server.port=8090

# view
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html

# encoding
spring.http.encoding.charset=UTF-8
spring.servlet.filter.character.encoding.enabled=true
spring.servlet.filter.character.encoding.force-request=true
spring.servlet.filter.character.encoding.force-response=true
spring.servlet.filter.character.encoding.encoding=UTF-8
spring.servlet.filter.character.encoding.force=true

# resources 
spring.mvc.static-path-pattern=/resources/**

# database
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:xe
spring.datasource.username=사용자명
spring.datasource.password=사용자 비밀번호

# mybatis
mybatis.mapper-locations=classpath:/mapper/*.xml

# url
server.servlet.context-path=/

 

※ ※ ※ ojdbc 라이브러리는 springboot에서 찾지를 못해 직접 물리적 파일도 해당 경로에 집어넣었다.

그래서 <scope></scope> 가 system으로 된 것.

<dependency>
            <groupId>oracle.jdbc</groupId>
            <artifactId>OracleDriver</artifactId>
    <version>19.8.0.0</version>
        <scope>system</scope>
            <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/ojdbc8.jar</systemPath>
</dependency>

 

- 실행 결과

 

스프링 부트가 정상적으로 실행되었고,
에러 없이 Oracle 과 연동되었음을 알 수 있다.