Spring -> Springboot

Welcome to Seoyun Dev Log·2022년 11월 22일
0

Springboot로 전환하기 전 꼭 알아야할 것들

pom.xml 설정

<dependencies>
		<!-- spring container(core) -->

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>${org.springframework-version}</version>
		</dependency>
		
		<!-- Spring Web -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>${org.springframework-version}</version>
		</dependency>
		
		<!-- Spring MVC -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>${org.springframework-version}</version>
		</dependency>
		
		<!-- jstl -->
		<dependency>
	        <groupId>javax.servlet</groupId>
	        <artifactId>jstl</artifactId>
	        <version>1.2</version>
		</dependency>
		
		<!-- Oracle JDBC -->
		<dependency>
			<groupId>com.oracle.database.jdbc</groupId>
			<artifactId>ojdbc6</artifactId>
			<version>11.2.0.4</version>
		</dependency>
		
		<!-- spring jdbc(DataSource) -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>${org.springframework-version}</version>
		</dependency>

		<!-- MyBatis -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>3.2.2</version>
		</dependency>
		
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>1.2.0</version>
		</dependency>
				
		<!-- jackson (json)-->
		<dependency>
			
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>2.8.7</version>
			
		</dependency>
		
		<!-- common fileupload -->
		<dependency>
			<groupId>commons-fileupload</groupId>
			<artifactId>commons-fileupload</artifactId>
			<version>1.3.3</version>
		</dependency>
		
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>2.4</version>
		</dependency>
		
		<!-- http components - http client & http core (rest template) -->
		 <dependency>
		    <groupId>org.apache.httpcomponents</groupId>
		    <artifactId>httpclient</artifactId>
		    <version>4.5.2</version>
		</dependency>
		
		<dependency>
		    <groupId>org.apache.httpcomponents</groupId>
		    <artifactId>httpcore</artifactId>
		    <version>4.4.15</version>
		</dependency>
		
		<!-- https://mvnrepository.com/artifact/org.json/json -->
		<dependency>
		    <groupId>org.json</groupId>
		    <artifactId>json</artifactId>
		    <version>20201115</version>
		</dependency>

		<!--mysql-->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>8.0.30</version>
		</dependency>

		<dependency>
			<groupId>commons-dbcp</groupId>
			<artifactId>commons-dbcp</artifactId>
			<version>1.4</version>
		</dependency>

		<!--springboot-->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
			<version>2.7.5</version>
		</dependency>

	</dependencies>  
/*
 * This file was generated by the Gradle 'init' task.
 */

plugins {
    id 'java'
    id 'maven-publish'
}

repositories {
    mavenLocal()
    maven {
        url = uri('https://repo.maven.apache.org/maven2/')
    }
    mavenCentral()
}

dependencies {
    implementation 'com.oracle.database.jdbc:ojdbc6:11.2.0.4'
    implementation 'org.springframework:spring-jdbc:5.3.23'
    implementation 'org.mybatis:mybatis:3.5.11'
    implementation 'org.mybatis:mybatis-spring:2.0.7'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.8.7'
    implementation 'commons-fileupload:commons-fileupload:1.4'
    implementation 'commons-io:commons-io:2.4'
    implementation 'org.apache.httpcomponents:httpclient:4.5.2'
    implementation 'org.apache.httpcomponents:httpcore:4.4.15'
    implementation 'org.json:json:20201115'
    implementation 'mysql:mysql-connector-java:8.0.30'
    implementation 'commons-dbcp:commons-dbcp:1.4'
    implementation 'org.springframework.boot:spring-boot-starter-web:2.7.5'
    compileOnly 'org.projectlombok:lombok:1.18.24'
    annotationProcessor 'org.projectlombok:lombok:1.18.24'

    testCompileOnly 'org.projectlombok:lombok:1.18.24'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.24'
}

group = 'boggle'
version = '0.0.1-SNAPSHOT'
description = 'boggle'
java.sourceCompatibility = JavaVersion.VERSION_11

publishing {
    publications {
        maven(MavenPublication) {
            from(components.java)
        }
    }
}
  • 기존 라이브러리

    • JDK 8
    • Maven
    • Apache Tomcat 8.5
    • Spring Framwork
    • log X
    • Junit, Mockito X
    • JSP, JSTL
  • 변경 라이브러리

    • JDK 11
    • Gradle
    • Embedded Tomcat
    • Spring Boot 2.7.5
    • spring-boot-starter-logging
    • spring-boot-starter-test
    • JSP, JSTL 제거

01. JDK 버전 변경

<plugin>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.8.1</version>
      <configuration>
        <release>11</release>
      </configuration>
</plugin>

02. gradle 변경

1) packaging 방식이 WAR인 경우, JSP 사용할 경우

: jar는 Java Archive의 약자로 자바 환경 위에서 바로 동작할 수 있는 애플리케이션이다
war는 Web Application Archive의 약자로 JSP 혹은 Servlet처럼 WAS 컨테이너 위에서 동작할 수 있는 패키징 방식이다

springboot가 패키징하는 JAR 내부에 Tomcat이 내장되어있기 때문에 JAR로 패키징 되어도 WAR 파일이 구동되는것이다.
이러한 환경 때문에 springboot의 디폴트는 jar 빌드(패키징)이다

  • 이런 환경에서 JSP를 띄우려면 내장 톰캣 모듈을 따로 설정해 줘야한다.
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper:10.1.2'

2) spring-framwork와 spring-jdbc 버전을 맞춰 줘야한다

  • [JAVA] java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration$EnableTransactionManagementConfiguration

3) spring-mybatis와 mybatis 버전이 맞지 않아서 생기는 오류

  • Field sqlSession in com.javaex.dao.BookdetailDao required a bean of type 'org.apache.ibatis.session.SqlSession' that could not be found.

4) Could not autowire. No beans of 'SqlSession' type found.

: intellij에서 component로 등록된 것을 @Autowired하여 사용하려면 해당 에러가 발생한다
컴파일 및 서버 실행에 문제는 없지만 해당 오류를 수정할 수 있다

컴포넌트를 사용하려는 클래스 위에 컴포넌트를 스캔할 패키지명을 적어준다

  • 의존성 주입이 잘 되지 않아서 발생하는 것
@Autowired(required = false)

5) Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

  • yml data 연동 설정이 되어있지 않거나 잘 못 작성한 것
    datasource 확인해보기


profile
하루 일지 보단 행동 고찰 과정에 대한 개발 블로그

0개의 댓글