SpringBoard 생성
pom.xml
java-version : 1.11
org.springframework-version: 4.3.8
version: 4.12
source : 1.11
target : 1.11
외부 라이브러리 추가
<!-- 외부 라이브러리 추가 -->
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.0.32</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>5.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.bgee.log4jdbc-log4j2/log4jdbc-log4j2-jdbc4.1 -->
<dependency>
<groupId>org.bgee.log4jdbc-log4j2</groupId>
<artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>
<version>1.16</version>
</dependency>
<!-- 외부 라이브러리 추가 -->
artifactId : javax.servlet-api
version : 3.1.0
src/main/resource에 설정 파일 복붙
root-context.xml
<!-- hikariCP : 연결정보 저장객체 -->
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<!-- <property name="driverClassName" value="com.mysql.cj.jdbc.Driver" /> -->
<!-- <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/springdb" /> -->
<property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy" />
<property name="jdbcUrl" value="jdbc:log4jdbc:mysql://localhost:3306/springdb" />
<property name="username" value="root" />
<property name="password" value="1234" />
</bean>
<!-- hikariCP : 연결정보 저장객체 -->
<!-- dataSource(CP) : 디비연결 -->
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<constructor-arg ref="hikariConfig" />
</bean>
<!-- dataSource(CP) : 디비연결 -->
<!-- dataSource : 디비연결 -->
<!-- <bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/springdb"/>
<property name="username" value="root"/>
<property name="password" value="1234"/>
</bean> -->
<!-- dataSource : 디비연결 -->
<!-- sqlSessionFactory : 디비연결, 데이터처리(SQL실행, Mybatis 설정) -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:/mybatis-config.xml" />
<property name="mapperLocations" value="classpath:/mappers/**/*Mapper.xml"/>
</bean>
<!-- sqlSessionFactory : 디비연결, 데이터처리(SQL실행, Mybatis 설정) -->
<!-- sqlSession : 디비연결, 데이터처리(SQL실행, Mybatis 설정), 자동 자원해체처리 -->
<!-- 기본적인 트랜잭션관리, 쓰레드 처리 안정성 높임 -->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="close">
<constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>
<!-- sqlSession : 디비연결, 데이터처리(SQL실행, Mybatis 설정), 자동 자원해체처리 -->
<!-- com.itwillbs.persistence 패키지 등록 -->
<context:component-scan base-package="com.itwillbs.persistence" />
<!-- com.itwillbs.service 패키지 등록 -->
<context:component-scan base-package="com.itwillbs.service" />
패키지 생성 후
context에 체크해주면 오류 없어짐
web.xml
<!-- 한글처리 필터 -->
<filter>
<filter-name>setUTF8</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>setUTF8</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
위 코드 추가
'spring · spring boot' 카테고리의 다른 글
[Spring] 게시판 만들기 - 글쓰기(1) (0) | 2023.12.14 |
---|---|
[Spring] 프로젝트 DB연결 세팅 - test (0) | 2023.12.14 |
[Spring] mybatis 개발 사용 순서 따라 적용해보기 (0) | 2023.12.12 |
[spring] HikariCP 커넥션 풀 연동하기 (0) | 2023.12.05 |
[spring] 의존 객체 자동 주입 (0) | 2023.12.04 |