반응형
반응형

*루트




현재 생성한 파일들이다 Test 붙은 부분은 매핑 테스트 한다고 생성 한것이고

나중엔 지울거 같으니 무시하면 된다

Board* 로시작하는 파일들을 생성해서 사용할 예정이다


*VO 생성


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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.common.domain;
 
import java.util.Date;
 
public class BoardVO {
 
    private Integer bno;
    private String title;
    private String content;
    private String writer;
    private Date regdate;
    private int viewcnt;
    public Integer getBno() {
        return bno;
    }
    public void setBno(Integer bno) {
        this.bno = bno;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public String getWriter() {
        return writer;
    }
    public void setWriter(String writer) {
        this.writer = writer;
    }
    public Date getRegdate() {
        return regdate;
    }
    public void setRegdate(Date regdate) {
        this.regdate = regdate;
    }
    public int getViewcnt() {
        return viewcnt;
    }
    public void setViewcnt(int viewcnt) {
        this.viewcnt = viewcnt;
    }
    
    
}
 
cs



게시판의 데이터 전송을 위한 계층간 컬럼들을 설정한다 디비의 테이블명과 일치시키는게 개발시에 편하다


*root-context.xml 빈 추가



root-context.xml 의 체크된 빈을 추가한다


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
32
33
34
35
36
37
38
39
40
<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd
        http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
        http://www.springframework.org/schema/beans http://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/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
    <!-- Root Context: defines shared resources visible to all other web components -->
    
    <bean id="dataSource" name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"></property>
        <property name="url" value="jdbc:log4jdbc:mysql://127.0.0.1:3306/book_ex?
useSSL=false&amp;characterEncoding=UTF-8&amp;serverTimezone=UTC"></property>
        <property name="username" value="root"></property>
        <property name="password" value="1234"></property>                  
    </bean>
    
    <!-- 
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" lazy-init="false">
        <property name="dataSource" ref="dataSource"></property>
        <property name="configLocation" value="classpath:/mybatis-config.xml"></property>
    </bean> 
    -->
    
 
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" lazy-init="false">
        <property name="dataSource" ref="dataSource"></property>
        <property name="configLocation" value="classpath:/mybatis-config.xml"></property>
        <property name="mapperLocations" value="classpath:mappers/**/*Mapper.xml"></property>
    </bean>
    
    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="clearCache">
        <constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"></constructor-arg>    
    </bean>
    
</beans>
cs


해당 소스를 참고한다


*BoardDAO 생성


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package com.common.persistance;
 
import java.util.List;
 
import com.common.domain.BoardVO;
 
public interface BoardDAO {
    
    public void create(BoardVO vo) throws Exception;
    
    public BoardVO read(Integer bno) throws Exception;
    
    public void update(BoardVO vo) throws Exception;
    
    public void delete(Integer bno) throws Exception;
    
    public List<BoardVO> listAll() throws Exception;
}
cs



*BoardMapper.xml 생성


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
32
33
34
35
36
37
38
39
40
41
<?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="com.common.mapper.BoardMapper">
    
    <insert id="create">
        insert into tbl_board(title, content, writer)
        values(#{title}, #{content}, #{writer})
    </insert>
    
    <select id="read" resultType="com.common.domain.BoardVO">
        select
            bno, title, content, writer, regdate, viewcnt
        from
            tbl_board
        where bno = #{bno}
    </select>
    
    <update id="update">
        update tbl_board set title = #{title}, content = #{content}
        where bno = #{bno}
    </update>
    
    <delete id="delete">
        delete from tbl_board where bno = #{bno}
    </delete>
    
    <select id="listAll" resultType="com.common.domain.BoardVO">
        <![CDATA[
            select
                bno, title, content, writer, regdate, viewcnt
            from
                tbl_board
            where bno > 0
            order by bno desc, regdate desc
        ]]>
    </select>
    
</mapper>
cs


boardMapper.xml 의 각 SQL 문의 id 속성값은 BordDAO 인터페이스와 동일하게 설정해 줘야한다



*BoardDAO의 구현 클래스 BoardDAOImpl



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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.common.persistance;
 
import java.util.HashMap;
import java.util.Map;
 
import javax.inject.Inject;
 
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;
 
import com.common.domain.MemberVO;
 
@Repository
public class MemberDAOImpl implements MemberDAO {
    
    @Inject
    private SqlSession sqlSession;
    
    private static final String namespace="com.common.mapper.MemberMapper";
 
    @Override
    public String getTime() {
        // TODO Auto-generated method stub
        return sqlSession.selectOne(namespace+".getTime");
    }
 
    @Override
    public void insertMember(MemberVO vo) {
        // TODO Auto-generated method stub
        sqlSession.insert(namespace+".insertMember", vo);
    }
 
    @Override
    public MemberVO readMember(String userid) throws Exception {
        // TODO Auto-generated method stub
        return (MemberVO) sqlSession.selectOne(namespace + ".selectMember", userid);
    }
 
    @Override
    public MemberVO readWithPW(String userid, String userpw) throws Exception {
        // TODO Auto-generated method stub
        Map<String, Object> paramMap = new HashMap<String, Object>();
        
        paramMap.put("userid", userid);
        paramMap.put("userpw", userpw);
        
        return (MemberVO) sqlSession.selectOne(namespace + ".readWithPW", paramMap);
    }
 
    
}
 
cs




*BoardDAO 의 테스트 작성



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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package org.common.web;
 
import java.util.Random;
 
import javax.inject.Inject;
 
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
import com.common.domain.BoardVO;
import com.common.persistance.BoardDAO;
 
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/spring/**/root-context.xml"})
public class BoardDAOTest {
    
    @Inject
    private BoardDAO dao;
    
    private static Logger logger = LoggerFactory.getLogger(BoardDAOTest.class);
    
    @Test
    public void testCreate() throws Exception{
        BoardVO board = new BoardVO();
        board.setTitle("새로운 글 입니다");
        board.setContent("새로은 내용 입니다");
        board.setWriter("user00");
        dao.create(board);
    }
    
    @Test
    public void testRead() throws Exception{
        logger.info("============Start testRead()================");
        logger.info(dao.read(1).toString());
        logger.info("============End testRead()================");
    }
    
    @Test
    //@Transactional
    public void testUpdate() throws Exception{
        Random r = new Random();
        BoardVO board = new BoardVO();
        board.setBno(1);
        board.setTitle("새로운 글 입니다 -- Update Test "+r.nextInt(1000000000));
        board.setContent("새로은 내용 입니다-- Update Test "+r.nextInt(1000000000));
        board.setWriter("user00-- Update Test "+r.nextInt(1000000000));
        dao.create(board);
    }
    
    @Test
    //@Transactional
    public void testDelete() throws Exception{
        dao.delete(1);
    }
}
 
 
cs


테스트를 작성했으면 JUNIT 을 실행해보고 제대로 빌드가 되는지 테스트 해보면 된다

나의 경우엔 BoardDAOImpl 의 @Repository 가 빠진것때문에 에러가 나서 좀 살펴봐야했다



마지막으로


1
2
3
4
5
6
7
8
9
10
11
<?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>
    
    <typeAliases>
        <package name="com.common.domain"/>
    </typeAliases>
    
</configuration>
cs



해당 부분을 추가하고 이번 포스팅은 마치겠다

반응형
반응형

*개발 준비 진행


초반부터 책을 보고 잘 따라했다면 문제 없는 과정이다


-환경 설정


1
2
3
4
5
6
7
<bean id="dataSource" name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"></property>
        <property name="url" value="jdbc:log4jdbc:mysql://127.0.0.1:3306/book_ex?
         useSSL=false&amp;characterEncoding=UTF-8&amp;serverTimezone=UTC"></property>
        <property name="username" value="root"></property>
        <property name="password" value="1234"></property>                  
</bean>
cs



디비 주소 뒤에 useSSL 여부에 따라 에러가 나는 경우가 있으니 주의하도록 하자



-테스트 작성


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
32
33
package org.common.web;
 
import java.sql.Connection;
 
import javax.inject.Inject;
import javax.sql.DataSource;
 
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/spring/**/root-context.xml"})
public class DataSourceTest {
    
    @Inject
    private DataSource ds;
    
    @Test
    public void testConnection() throws Exception{
        
        try(Connection con = ds.getConnection()){
            
            System.out.println(con +"git bash commit용 테스트 메세지 ");
            
        }catch(Exception e){
            e.printStackTrace();
        }
        
    }
 
}
cs


중간에 git 테스트 때문에 수정내역을 보기위해 했던 수정이다 넘어가자



- 빌드 테스트












로그와 Junit 도 Success


-테이블 생성



1
2
3
4
5
6
7
8
9
10
create table tbl_board(
    bno INT NOT NULL AUTO_INCREMENT,
    title VARCHAR(200NOT NULL,
    content TEXT NULL,
    writer VARCHAR(50NOT NULL,
    regdate TIMESTAMP NOT NULL DEFAULT now(),
    viewcnt INT DEFAULT 0,
    PRIMARY KEY (bno)
    
);
cs




-용도별 쿼리 분류


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
게시물 등록
 
INSERT INTO `book_ex`.`tbl_board`
(
`title`,
`content`,
`writer`)
VALUES
(
'제목입니다',
'내용입니다',
'user00');
 
조회
 
select * from tbl_board where bno = 1;
 
전체 목록
 
select * from tbl_board where bno > 0 order by bno desc;
 
수정
 
update tbl_board set title = '수정된 제목' where bno = 1;
 
삭제
 
delete from tbl_board where bno = 1;
cs





-web.xml 에 필터 추가



1
2
3
4
5
6
7
8
9
10
11
12
13
    <filter>        
        <filter-name>enconding</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>
    <filter-mapping>
        <filter-name>encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
 
cs


애플리케이션을 제작하다보면 한글 처리가 문제 될때가 많기때문에 미리 등록한다

톰캣에 설정하는 부분도있고 디비주소에 설정하는 부분도 있고 한글 처리는 항상 문제가 되는듯하다



-bootstrap, html 


해당 저서에는 bootstrap과 관련 템플릿을 통해서 웹페이지를 구성하기때문에

해당 자료를 다운받아 프로젝트에 넣어야한다


https://cafe.naver.com/gugucoding/798


여기서 받을수있다


static.zip 파일과 include.zip 파일을 압축 풀어서


bootstrap,dist,plugin 파일은 webapp/resource 아래에 두고

include 파일은 webapp/WEB-INF/views 아래에 두면된다




-html 파일 수정


home.jsp 파일을 수정해야한다


그전 장에서 톰캣의 설정이 되어있어야 테스트가 가능하다


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="include/header.jsp" %>
 
<!-- Main content -->
<section class="content">
    <div class="row">
        <!-- left colum -->
        <div class="col-md-12">
            <!-- genaral from element -->
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title"> HOME PAGE</h3>
                </div>
            </div>
        </div><!-- /.col (left) -->
    </div><!-- /.row -->
</section><!-- /.content -->
 
<%@ include file="include/footer.jsp" %>
cs




전부 적용되었는지 확인하고 서버를 실행해보면 디자인이 적용된걸 확인할수있다


반응형
반응형
*개발 준비표


 영역

 준비

 설명

 데이터베이스 관련

 관련 스키마,계정의 생성

개발에 사용할 스키마를 정의하고, 개발에 필요한 사용자 계정등을 생성합니다.

 테이블 설계와 생성

실제 작업할 테이블을 설계하고 각 테이블의 관계를 ERD 등을 사용해서 그려둡니다.

 더미 데이터 생성

테스트를 위한 가상의 의미없는 데이터를 추가해서 개발 시 결과를 확인할 때 사용합니다.

 스프링 MVC 관련

 패키지 구조 결정 

개발에 사용할 패키지 이름이나 코드 규칙 등을 미리 지정합니다

 개발 역할 분담

팀원들 간의 개발 역할을 어떨게 할 것인지를 결정합니다 수평적 혹은 수직적인 분할을 하게됩니다

 테스트 방법의 수립

개발의 중간에 팀원들의 현재 상황을 올바르게 인식할수있는 테스트 방법을 공유하고 지킵니다

 화면 관련

 화면 방식의 결정

JSP 위주의 개발인지,HTML 위주와 Javascript를 주로 사용하는 개발인지를 명확이 정확히 정합니다.

 절대경로, 상대경로의 결정

페이지에서 사용하는 링크의 처리를 하나로 통일해서 진행합니다 



*프로젝트의 필요한 라이브러리


MySQL 드라이버


Spring-test 모듈


MyBatis 모듈


MyBatis-Spring 모듈




*소스 구조





해당 형태로 준비되었고 진행할 예정이다


반응형
반응형

이전에 말했듯이 선행으로 하고있던 프로젝트 부터 시작하기때문에


기본적인 부분들은 전부 건너뛰고 


130페이지의 6.5 스프링에 빈으로 등록하기 부분을 학습할 예정이다


지난번의 내용은 Mysql 에서 테이블을 등록하고


Mybatis 테스트 코드 작성을 통해 디비 연동 부분을 테스트 해봤다



그부분에서 @Inject 를 사용한 부분이 계속 에러가 나서 골치가 아팠는데


그부분은 


root-context.xml 의


1
2
3
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="clearCache">
        <constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"></constructor-arg>    
 </bean>
cs



이부분을 작성하지 않아서 생긴 오류 였다 참고 바란다


그렇게 해서 작성된 root-context.xml 부분은 


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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema
          /jdbc/spring-jdbc-4.3.xsd     
        http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
        http://www.springframework.org/schema/beans http://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/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
    <!-- Root Context: defines shared resources visible to all other web components -->
    
    <bean id="dataSource" name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"></property>
        <property name="url" value="jdbc:log4jdbc:mysql://127.0.0.1:3306/book_ex?useSSL=false&amp;
        characterEncoding=UTF-8&amp;serverTimezone=UTC"    ></property>
        <property name="username" value="root"></property>
        <property name="password" value="1234"></property>                  
    </bean>
    
    <!-- 
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" lazy-init="false">
        <property name="dataSource" ref="dataSource"></property>
        <property name="configLocation" value="classpath:/mybatis-config.xml"></property>
    </bean> 
    -->
    
 
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" lazy-init="false">
        <property name="dataSource" ref="dataSource"></property>
        <property name="configLocation" value="classpath:/mybatis-config.xml"></property>
        <property name="mapperLocations" value="classpath:mappers/**/*Mapper.xml"></property>
    </bean>
    
    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="clearCache">
        <constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"></constructor-arg>    
    </bean>
    
    
    <context:component-scan base-package="com.common.persistance"></context:component-scan>
    
</beans>
 
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="clearCache">
        <constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"></constructor-arg>    
 </bean>
cs



이렇게 변경이 되었다


MemberDAOTest 를 작성했다 junit으로 테스트 하기위함으로 src/test/java 하위 경로에 작성해야한다



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
32
33
34
35
36
37
38
package org.common.web;
 
import javax.inject.Inject;
 
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
import com.common.domain.MemberVO;
import com.common.persistance.MemberDAO;
 
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/spring/**/root-context.xml"})
public class MemberDAOTest {
    
    @Inject
    private MemberDAO dao;
    
    @Test
    public void testTime() throws Exception{
        System.out.println(dao.getTime());
    }
    
    @Test
    public void testInsertMember() throws Exception{
        
        MemberVO vo = new MemberVO();
        vo.setUserid("user00");
        vo.setUserpw("user00");
        vo.setUsername("USER00");
        vo.setEmail("user00@aaa.com");
        
        dao.insertMember(vo);
    }
    
}
 
cs


그다음은 디비 로그 출력을 위해 로그 파일을 추가하는 부분이다


pom.xml 에 해당 내용을 추가해야 한다


1
2
3
4
5
6
        <!-- log4j -->
        <dependency>
            <groupId>org.bgee.log4jdbc-log4j2</groupId>
            <artifactId>log4jdbc-log4j2-jdbc4</artifactId>
            <version>1.16</version>
        </dependency>
cs



root-context.xml 부분도 바꿔준다


1
2
3
4
5
6
7
    <bean id="dataSource" name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"></property>
        <property name="url" value="jdbc:log4jdbc:mysql://127.0.0.1:3306/book_ex?useSSL=false&amp;
        characterEncoding=UTF-8&amp;serverTimezone=UTC"    ></property>
        <property name="username" value="root"></property>
        <property name="password" value="1234"></property>                  
    </bean>
cs



이후에 

/src/main/resources

폴더에 파일 두개를 추가해서 설정을 추가해 주면된다


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
log4jdbc.log4j2.properties
    log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
 
 
logback.xml
    
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <include resource="org/springframework/boot/logging/logback/base.xml"/>
        <logger name="jdbc.sqlonly" level="DEBUG">
            <logger name="jdbc.sqltiming" level="INFO"/>
            <logger name="jdbc.audit" level="WARN"/>
            <logger name="jdbc.resultset" level="ERROR"/>
            <logger name="jdbc.resultsettable" level="ERROR"/>
            <logger name="jdbc.connection" level="INFO"/>
        </logger>
    </configuration>
cs




이렇게 해서 2부를 마친다

반응형
반응형


최근에 공부가 부족하다고 생각하여 개인 프로젝트를 책과 함께 진행하려고 한다


책제목은 '코드로 배우는 스프링 웹 프로젝트' 이고 개발자들 사이에선 실무배우기 좋은 책으로 정평이 나있다


최근에 나오는 신기술들 에 비해선 약간 배우는 범위가 떨어질수는있다


하지만 이직이나 기업 환경을 경험해 보았다면 알수있듯이 기업에서 사용하는 스프링이나 JDK 버전은 현저히 낮기때문에


스프링을 배우지 않고 바로 스프링 부트를 배운다거나 해서 스프링을 쓰는 곳으로 이직했을때의 


환경설정 쪽의 불편함같은건 없어야 하기때문에


배워둘 필요가 있는 기술이라고 생각한다




일단 기본적으로 프로젝트를 어느정도 진행 해놓은 상태기때문에


기본설정은 자세히 다루지는 않을 예정이다 버전 스펙을 나열하자면


스프링 버전 : 4.3.8

JDK 버전 : 1.8

톰캣 버전 : 8.5

Mybatis

JUnit 4

maven


책의 내용에 따라 pom.xml에 필요한 라이브러리를 받아놓으면 된다


책의 좋은점을 보자면 테스트와 디버깅을 어느정도 잘 알려주고 있다고 생각한다

JUNIT 테스트코드 작성법

이클립스 디버깅등 알아두면 실무에 유용한 내용들이다


 초반 책의 내용을 따라하다가 주의할점이 있는데

DataSource 테스트 코드를 작성하고 테스트하면서 계속 에러를 내뿜는 부분이 있었다



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
import java.sql.Connection;
 
import javax.inject.Inject;
import javax.sql.DataSource;
 
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:/src/main/webapp/WEB-INF/spring/**/root-context.xml"})
public class DataSourceTest {
    
    @Inject
    private DataSource ds;
    
    @Test
    public void testConnection() throws Exception{
        
        try(Connection con = ds.getConnection()){
            
            System.out.println(con);
            
        }catch(Exception e){
            e.printStackTrace();
        }
        
    }
 
}
cs



해당내용에서

1
2
3
4
5
6
org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'org.common.web.DataSourceTest'
Unsatisfied dependency expressed through field 'ds'
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 
'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: 
{@javax.inject.Inject()}
cs






이런 에러가 발생했고 어떤문제인지 몰라서 이것저것 해보다가



1
2
3
4
5
@ContextConfiguration(locations={"file:/src/main/webapp/WEB-INF/spring/**/root-context.xml"})
 
변경
 
@ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/spring/**/root-context.xml"})
cs



경로의 문제였다는걸 알고 변경했다 이부분을 주의하자


이후엔 마이바티스 연동까지 한 상태로 쿼리를 날리는 부분까지 선행이 완료된 상태이기 때문에 해당부분 부터 진행할것이다


반응형
반응형
1

+ Recent posts