250x250
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- JDBC
- 설정
- oracle
- Exception
- JavaScript
- Docker
- PostgreSQL
- STS
- SpringBoot
- Thymeleaf
- Spring Boot
- maven
- IntelliJ
- MSSQL
- 오픈소스
- Source
- Open Source
- 문서
- Eclipse
- jpa
- Tomcat
- git
- Python
- Core Java
- AJAX
- MySQL
- error
- ubuntu
- myBatis
- spring
Archives
- Today
- Total
헤르메스 LIFE
[개발환경] Spring + Maven + MyBatis + PostgreSQL 본문
728x90
개발환경
Eclipse Java EE IDE for Web Developers ( Eclipse IDE Neon 3 Packages x64 )
Spring 3.2.14
Maven 3.8.6
MyBastis 3.1.1
PostgreSQL 14.1
Tomcat 8.5.81
JDK 1.8.0_202
DBCP + MyBatis 를 이용한 PostgreSQL 접속 방법
context-common.xml
<?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:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<!-- annotation enabled -->
<context:annotation-config />
<context:component-scan base-package="spring.simple.test">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
</beans>
context-datasource.xml
<?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:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/springboot" />
<property name="username" value="hermeswing" />
<property name="password" value="pass" />
</bean>
</beans>
context-mapper.xml
<?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:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:config/mapper/mybatis-config-base.xml" />
<property name="mapperLocations">
<list>
<value>classpath*:spring/simple/test/sample/**/dao/*Mapper.xml</value>
</list>
</property>
</bean>
<!-- MyBatis SqlSessionTemplate -->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="spring.simple.test.sample" />
</bean>
</beans>
context-transaction.xml
<?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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
<tx:annotation-driven proxy-target-class="true" />
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource" />
</beans>
mybatis-config-base.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="cacheEnabled" value="true" />
<setting name="lazyLoadingEnabled" value="false" />
<setting name="multipleResultSetsEnabled" value="true" />
<setting name="useColumnLabel" value="true" />
<setting name="useGeneratedKeys" value="false" />
<setting name="defaultExecutorType" value="SIMPLE" />
<setting name="defaultStatementTimeout" value="25000" />
</settings>
<typeHandlers>
<!-- java.sql.Timestamp 를 java.util.Date 형으로 반환 -->
<typeHandler javaType="java.sql.Timestamp" handler="org.apache.ibatis.type.DateTypeHandler" />
<typeHandler javaType="java.sql.Time" handler="org.apache.ibatis.type.DateTypeHandler" />
<typeHandler javaType="java.sql.Date" handler="org.apache.ibatis.type.DateTypeHandler" />
</typeHandlers>
</configuration>
http://localhost:9090/sample-spring-webapp/sample/list
아래의 환경을 참조해서 셋팅만 변경해서 테스트한 내용입니다.
소스는 아래 개발환경을 기초로 Import 해서 테스트해 보시면 실행되실 거라 생각됩니다.
https://hermeslog.tistory.com/629
https://hermeslog.tistory.com/541
개발환경 다운로드
https://mega.nz/file/MakC0CDK#tCCYVOg13Cq4xccC2SlNviCuAcxJVF--oQGFaS0Q3RA
728x90
'Spring Framework' 카테고리의 다른 글
[Redis] SpringBoot + Redis (0) | 2022.11.23 |
---|---|
[JNDI] 간단한 Tomcat + JSP + JNDI 테스트 (0) | 2022.11.21 |
[Maven] Dynamic Web Project를 Maven Project 로 Convert 하기 (0) | 2022.11.18 |
[개발환경] Spring + Maven + MyBatis + HSQL Simple Web Sample (0) | 2022.08.17 |
Spring Boot 설정파일 암호화 (0) | 2022.05.29 |