Spring Maven 설정
1. pom.xml 수정
pom.xml |
<!-- Generic properties --> <!-- Web -->
<!-- Hibernate / JPA --> |
2. pom.xml 에 dependency 추가
- 필요한 것들을 http://mvnrepository.org 에서 검색을 통해 찾아서 추가하면 된다.
2.1 mybatis (DB 접근을 위한)
pom.xml |
<dependency> <groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.3.0</version>
</dependency> |
2.2 mybatis spring
pom.xml |
<dependency> <groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.3</version>
</dependency> |
2.3 Spring jdbc
pom.xml |
<dependency> <groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.1.RELEASE</version>
</dependency> |
2.4 connection pool ("dbcp")
pom.xml <dependency>
2.5 Oracle ("ojdbc6")
pom.xml <dependency>
3. pom.xml 에 저장소 지정
pom.xml <repositories>
4. web.xml 설정
4.1 dispatcher-config.xml (웹과 관련 있는 것; Spring bean configuration file) 설정
web.xml |
<servlet> |
4.2 web.xml UTF-8 필터 추가
web.xml |
<!-- 스프링에 파라메터로 한글을 넘길 때 --> |
5. Root Application Context 설정 (웹과 관련 없는 것; application-config.xml)
Root Application Context란 전체 계층구조에서 최상단에 위치한 컨텍스트 (웹환경과 독립적인 빈 등록)
- 서로 다른 서블릿 컨텍스트에서 공유해야하는 Bean들을 등록해놓고 사용할 수 있다.
- 웹 어플리케이션 전체에 적용가능한 DB 연결, 로깅기능등에 이용
- Servlet Context에 등록된 Bean 이용 불가능!
- Servlet Context와 동일한 Bean이 있을 경우 Servlet Context Bean이 우선된다.
- 하나의 컨텍스트에 정의된 AOP 설정은 다른 컨텍스트의 빈에는 영향을 미치지 않는다
- 디폴트 설정 파일 /WEB-INF/applicationContext.xml 으로 설정된다
- 서비스계층과 데이터 액세스 계층을 포함해서 웹환경과 직접 관련이 없는 모든 빈들을 여기에 등록한다
- 만약에 사용할 이름이 다르거나 설정파일이 여러개인 경우 contextConfigLocation 파라미터를
추가해서 설정해주면 된다
web.xml |
<!-- <context-param> <listener> |
Root Application Context는 STS에서 Spring Project를 생성하면 기본적으로
spring/application-config.xml 로 생성됩니다.
5.1 application-config.xml Namespaces 추가
5.2 connection pool & datasource
application-config.xml |
<!-- Connection Pool & DataSource -->
|
5.3 SqlSessionFactory & transaction
application-config.xml |
<!-- SqlSessionFactory -->
|
application-config.xml |
<!-- Transaction -->
|
6. /spring/mybatis-config.xml 설정파일 만들기
mybatis-config.xml |
<?xml version="1.0" encoding="UTF-8"?> "-//mybatis.org//DTD Config 3.0//EN"
|