[SpringBoot] SpringBoot 설정모음

🐷Jinie (juniorDeveloper)·2021년 1월 6일
1

SpringBoot

목록 보기
7/11

1. pom.xml

 <!-- JSTL 의존성 추가  -->
<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>jstl</artifactId>
</dependency>
	    
<!-- JSP 컴파일을 위한 라이브러리 추가  -->
<dependency>
	<groupId>org.apache.tomcat.embed</groupId>
	<artifactId>tomcat-embed-jasper</artifactId>
</dependency>

2. application.properties

##  웹서버 실행 
spring.main.web-application-type=SERVLET  
server.port=8888          

## 데이터베이스 연동 (오라클드라이버)
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:xe
spring.datasource.username=system
spring.datasource.password=1234

## JSP 경로설정 
spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp

3. DatabaseConfig.java

package com.ruby;

import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@MapperScan(basePackages="com.ruby")	
@EnableTransactionManagement
public class DatabaseConfig {
	@Bean
    public  SqlSessionFactory  sqlSessionFactory(DataSource dataSource )  throws Exception {
			 
		SqlSessionFactoryBean sqlSessionFactory = new  SqlSessionFactoryBean();
		sqlSessionFactory.setDataSource(dataSource);
		PathMatchingResourcePatternResolver resolver = new  PathMatchingResourcePatternResolver();
		sqlSessionFactory.setMapperLocations(resolver.getResource("classpath:mapper/sample-Mapper.xml")); 
		return sqlSessionFactory.getObject();  
		  
	}
	 
	@Bean
	public  SqlSessionTemplate  sqlSessionTemplate(SqlSessionFactory  sqlSessionFactory) throws Exception{  
		final  SqlSessionTemplate  sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
		return sqlSessionTemplate;  
	}
}
profile
ᴘᴇᴛɪᴛs ᴅᴇ́ᴠᴇʟᴏᴘᴘᴇᴜʀ. ᴘʀᴏɢʀᴀᴍᴍᴀᴛɪᴏɴ = ᴘʟᴀɪsɪʀ 💕

0개의 댓글