<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<!-- 👉 application.properties -->
<!-- 📌 DB 설정 -->
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/ssafy_board?serverTimezone=UTC"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
<!-- 👉 application.properties -->
<!-- 📌 Springboot를 적용하면 mapper, alias 관련 등록만 해주면 된다.
application.properties에서 dataSource는 등록되었음 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath*:mapper/**/*.xml"/>
<property name="typeAliasesPackage" value="com.ssafy.board.model.dto"/>
</bean>
<!-- 👉 DBConfig.java -->
<!-- 📌 자바 설정 클래스(DBConfig.java)를 따로 생성해서 설정
: dao interface들의 위치 지정 -->
<mybatis-spring:scan base-package="com.ssafy.board.model.dao"/>
<!-- 👉 @SpringBootApplication -->
<!-- 📌 @SpringBootApplication로 인해 com.ssafy.board 패키지 내의 클래스들은
모두 Bean 객체 등록되기 때문에 service를 별도로 지정해주지 않아도 된다.
(DB 관련 설정은 아님)-->
<context:component-scan base-package="com.ssafy.board.model.service"></context:component-scan>
</beans>
# JSP setting
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
#DB connection
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/ssafy_board?serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=ssafy
#mybatis > 이것에 의해서 sqlSessionFactory도 생성된다
mybatis.mapper-locations=classpath*:mapper/**/*.xml
mybatis.type-aliases-package=com.ssafy.board.model.dto
설정을 xml이 아닌 자바 config 파일로 하는 것
package com.ssafy.board.config;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@MapperScan(basePackages = "com.ssafy.board.model.dao")
public class DBConfig {
}