반응형


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


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


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


하지만 이직이나 기업 환경을 경험해 보았다면 알수있듯이 기업에서 사용하는 스프링이나 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



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


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


반응형

+ Recent posts