Notice
Recent Posts
Recent Comments
Link
«   2025/10   »
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
Archives
Today
Total
관리 메뉴

스포츠마케터의 초보 개발자 도전기

Spring 파일 세팅 방법 1. 본문

develop/Spring

Spring 파일 세팅 방법 1.

teammate brothers 2024. 6. 5. 16:06

Spring 초기 세팅이 끝난 후 아래와 같이 역할에 맞게 파일 세팅을 해주는 것이 코드작성에 용이하다

 

1. 아래쪽 폴더트리를 참고하여 src/main/webapp/WEB-INF에 web.xml파일을

아래파일(한글이 안깨지게 처리한 파일)로 바꾼다.

web.xml
0.00MB

 

2. 1) src/main/resource 폴더에서 config.spring.context 패키지를 만든다. 이때 패키지명은 꼭 config.spring.context가 아니어도 된다.

2. 2) 만든 패키지에 src/main/WEB-INF/spring 폴더의 root-context를 잘라내어 삽입한다.

 

2. 3) 가져온 root-context 파일을 복사하여 기능에 맞게 아래 이름으로 변경한다. (수정되는 순서도 중요해서 넘버링을 함)

① context-1-datasource

② context-2-mybatis

③ context-3-dao

④ context-4-service

 

3. web.xml을 열어서 원래 root-context로 지정된 내용을 새로만든 context의 내용을 참고하도록 아래코드로 수정한다.

 

원래파일 web.xml파일>

 

수정코드>

<param-value>classpath*:config/spring/context/context-*.xml</param-value>

 

수정완료 된 web.xml파일 코드 >

 

4. 1) src/main/resources에 config.spring.mvc 패키지를 만든다.

 

4. 2) src-main-WEB-INF-spring-appServlet에 있는 servlet-context를 방금만든 패키지로 이동시킨다.

4. 3) web.xml 파일에서 servlet-context를 실행하는 경로를 수정한다.

원래파일 web.xml파일 코드>

 

수정 코드>

<param-value>classpath*:config/spring/mvc/servlet-context.xml</param-value>

 

수정완료 된 web.xml파일 코드>

 

-- 여기까지 완료 후 서버를 실행해서 초기값(Hello world!) 이 나와야 한다.

 

5. 1) src/main/resources에 config.mybatis 패키지를 만든다.

5. 2) 해당 패키지에 db.properties 파일을 만든다. properties는 정해진 확장자이기 때문에 꼭 쓰고, db는 파일 이름이라 다른것으로 바꿀 수 있다.

 

5.3) db.properties에 아래 코드를 삽입한다.

driver=oracle.jdbc.OracleDriver
url=jdbc:oracle:thin:@localhost:1521:xe
user=test
password=1111

여기서 user는 oracle 계정명, password는 계정의 비밀번호

 

5. 4) config.mybatis 패키지에 아래 파일을 삽입한다.

mybatis-config.xml
0.00MB

 

 

 

 

5. 5) mybatis-config.xml 파일을 열어 참고할 mapper를 수정한다.

 

6. 1) src/main/resources에 config.mybatis.mapper 패키지를 만든다.

 

6. 2) 파일명.xml을 만들어 아래코드를 넣는다.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="d">

</mapper>

 

6. 3) namespace에 적당한코드를 넣는다. (위 코드는 d가 이미 입력되어있다)

 

 

'develop > Spring' 카테고리의 다른 글

Spring 파일 세팅 방법 3.  (0) 2024.06.05
Spring 파일 세팅 방법 2.  (0) 2024.06.05
Spring 초기 세팅  (0) 2024.06.05