1. Spring Legacy Project 생성
2. 프로젝트 최초 생성 후 pome.xml 의 설정을 변경해줘야한다.
pom.xml 에 dependency 를 dependencies 의 자식요소로 추가해서 의존 라이브러리 추가
<!-- 추가 의존 라이브러리 -->
<!-- MyBatis 라이브러리 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.8</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.0</version>
</dependency>
<!-- Spring JDBC 라이브러리 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<!-- 파일업로드 처리를 위한 라이브러리 (SmartEditor 에서도 필요함)-->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!-- json, xml 응답을 편하게 할수 있도록 도와 주는 라이브러리 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.0</version>
</dependency>
<!-- Aop 용 라이브러리 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.0</version>
</dependency>
<!-- Spring Security 관련 라이브러리 -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<!-- 트렌젝션 처리를 위한 라이브러리 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
3. pome.xml 설정을 수정 후 Maven project 로 update 해주기
4. src -main - webapp - WEB-INF - web.xml 설정 수정
<!-- welcome 파일 추가 -->
<welcome-file-list>
<welcome-file>home.do</welcome-file>
</welcome-file-list>
<!-- url-pattern 을 /에서 *.do 로 수정 -->
<!-- 스프링 인코딩 필터(post 방식 전송했을 때 한글 깨지지 않도록) -->
<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<!-- Spring 인코딩 필터 맵핑하기 -->
<filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
5. webapp - spring - appServlet - servlet-context.xml 파일 수정
<!--
JNDI 데이터 소스 객체 얻어오는 설정
Servers/context.xml 에 설정된 oracle 접속정보 가 있어야 된다.
<Resource name="jdbc/myoracle" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@127.0.0.1:1521:xe"
username="scott" password="tiger" maxTotal="20" maxIdle="10"
maxWaitMillis="-1"/>
-->
<beans:bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<beans:property name="jndiName" value="java:comp/env/jdbc/myoracle"/>
</beans:bean>
<!--
위는 아래의 코드와 같다
dataSource = new JndiObjectFactoryBean();
dataSource.setJndiName("java:comp/env/jdbc/myoracle");
-->
<!-- SqlSessionFactory 객체 -->
<beans:bean id="sessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="configLocation"
<!-- 경로 동일하게 입력 -->
value="classpath:com/ / /mybatis/Configuration.xml"/>
<!-- 경로 동일하게 입력 -->
</beans:bean>
<!--
sessionFactory=new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
sessionFactory.setConfigLocation("classpath:com/gura/xxx");
-->
<!--
SqlSession 인터페이스를 구현한
SqlSessionTemplate(SqlSession) 객체
Dao 가 의존하는 객체
-->
<beans:bean class="org.mybatis.spring.SqlSessionTemplate">
<beans:constructor-arg name="sqlSessionFactory"
ref="sessionFactory"/>
</beans:bean>
<!--
new SqlSessionTemplate(sessionFactory);
-->
<!-- Multipart 폼 전송 처리를 위한 bean 설정 -->
<beans:bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<beans:property name="maxUploadSize" value="102400000"/>
</beans:bean>
6. Tomcat server 에 접속할 DB 연동
<!--기본 oracle local DB 연동 -->
<Resource name="jdbc/myoracle" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@127.0.0.1:1521:xe"
username="scott" password="tiger" maxTotal="20" maxIdle="10"
maxWaitMillis="-1"/>
7, HomeCotroller 수정
8. Mybatis pligin 설치 - 두가지 다 설치해준다
9. Mybatis 적용 / new package 생성 - Configuration.xml 파일 생성
10. 서버 실행
프로젝트 오른쪽 마우스 -> Run as -> Run on Server
'else Study' 카테고리의 다른 글
[git]Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch. 문구 해결 (0) | 2023.01.16 |
---|---|
WebRTC 넌 누구니 (0) | 2021.09.08 |