Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Java
- eGovFramework
- eGov
- jsp
- sql
- html
- 오류
- spring
- select
- Ajax
- json
- 암호화
- jQuery
- POI
- 과정평가형
- input
- CSS
- 개념
- 태그
- javascript
- TO_DATE
- mybatis
- 정의
- 함수
- Oracle
- controller
- web.xml
- JVM
- array
- was
Archives
- Today
- Total
web developer
[spring] root-context.xml 본문
728x90
728x90
root-context.xml
mvc설정과 관련된 여러 처리를 담당하는 설정 파일로 DAO, VO 그리고 service 등과 같은 파일을 어떻게 사용할 것인가 빈(객체)들을 관리하는 문서이다. 다운 받은 라이브러리를 사용하는 곳이고, 필요할 때 객체를 사용하기 위해 이 문서에 bean태그를 이용해 빈을 등록하고 주입하는 방식으로 사용한다.
<?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:mvc="http://www.springframework.org/schema/mvc"
xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
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
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
<!--
root-context.xml : mvc 설정과 관련된 여러 처리를 담당하는 설정 파일 (ex: DAO, VO, service...)
xml의 형태를 어떻게 사용할 것인가 빈(객체)들을 관리하는 문서(xml)이다.
필요할 때마다 주입해서 사용하기 위해 이곳에 빈을 등록해둔다.
(bean태그를 사용해서 등록한다. id="빈의 이름" class="클래스의 위치")
다운받은 라이브러리들을 사용하는 곳
-->
<!-- properties 파일 로딩하기 -->
<context:property-placeholder location="classpath:/database/jdbc.properties"/>
<!-- [DB 관련 설정 : DB 관련 정보를 커넥션 풀 객체에 담는 설정] -->
<!-- 1. HikariConfig 빈 등록 -->
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<!-- 변수 설정 : property 태그 사용, name="변수 이름" value="저장 값" -->
<!-- 보안을 위해 직접 작성하지 않고 properties를 el태그로 불러오는 방식을 사용했다. -->
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<!-- 추가 속성 -->
<property name="maximumPoolSize" value="30"/>
</bean>
<!-- 2. DataSource 등록 : 데이터베이스의 정보들을 포장하고있는 애들 -->
<bean id="ds" class="com.zaxxer.hikari.HikariDataSource">
<!-- 생성자를 통한 의존성 주입 -->
<constructor-arg ref="hikariConfig"/>
</bean>
<!-- [마이바티스 주요 객체 sessionFactory클래스 빈등록] -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- setter를 통한 의존성 주입 -->
<property name="dataSource" ref="ds"/>
<!-- 마이바티스 설정 파일을 변수 configLocation에 저장 -->
<property name="configLocation" value="classpath:/spring/mybatis-config.xml"/>
<!-- sql문이 작성될 xml파일이 들어간 경로 저장 -->
<property name="mapperLocations" value="classpath:/mappers/**/*Mapper.xml"></property>
</bean>
<!-- [마이바티스를 쉽게 사용할 템플릿 클래스 빈 등록] -->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="clearCache">
<constructor-arg ref="sqlSessionFactory"/>
</bean>
<!-- [Mapper.xml 파일을 빈객체로 등록하는 설정] -->
<mybatis-spring:scan base-package="com.spring.myapp.board.repository"/>
<!-- [컴포넌트 자동 스캔 명령] -->
<!-- 자동주입 명령을 사용하기 위해 위치를 알려줘야한다. -->
<context:component-scan base-package="com.spring.myapp"/>
</beans>
출처 : https://yeahajeong.tistory.com/49?category=957804
[SpringMVC] 초기 설정 - servlet-context.xml
servlservlet-context.xml 앞에서 servlet-context.xml 파일의 이름을 servlet-config.xml로 변경하였다. 이 파일은 DispacherServlet의 기반 설정을 기록하는 파일이다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16..
yeahajeong.tistory.com
728x90
728x90
'Framework > Spring [java]' 카테고리의 다른 글
[spring] 파일 관련 기능: 업로드, 다운로드, 게시글 등록 및 수정, 삭제 (0) | 2022.01.05 |
---|---|
[spring] Spring IOC, IOC Container ,DI 의미 (0) | 2021.12.23 |
[spring] web.xml (0) | 2021.12.23 |
[spring] servlet-context.xml (0) | 2021.12.23 |
[Spring] lombok 설정 (onMethod_ 에러발생) (0) | 2021.11.24 |