해당포스트를 읽기전에 반드시

http://dev-khm.tistory.com/21



데이터베이스를 만들기를 바란다.해당 챕터는 데이터 베이스와 연관되서 데이터를 가지고오는 챕터기때문에 선행학습이 필요하다.

우리는 알다시피 스프링컨텍스트 파일을 따로 관리 할 수 있게끔 분리시켰다.


이제 그 스프링컨텍스트에 mysql에 접속하기 위한 설정파일 두개를 만들것이다.

context-datasource.xml

context-mapper.xml를 만들것이다

먼저 데이터소스는 데이터베이스의 접근하기 위한 정보들을 설정한다고보면되며

mapper는 마이바티스란 오픈소스를 이용해. slq쿼리문과 연결시켜주는 역할을 한다고보면된다.


세세한 설명은 차분히 설명을하며 진행하도록하겠다.

먼저 지난번에 만들어주었던 spring 폴더에 context-datasource.xml 만들어주자.


 <?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:p="http://www.springframework.org/schema/p"

xsi:schemaLocation="http://www.springframework.org/schema/beans 

http://www.springframework.org/schema/beans/spring-beans.xsd">


<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

<property name="driverClassName" value="com.mysql.jdbc.Driver" />

<property name="url" value="jdbc:mysql://localhost:3306/app_data" />

<property name="username" value="root" />

<property name="password" value="1234" />

</bean>

</beans>


해당내용으로 작성을 해주자. 간단하게 설명하면 url은 로컬호스트로 돌리는 내 mysql에 로컬호스트로 돌리는 스프링 웹서버가 접근하겠다는 소리고 접근할때 3306으로 접근하고 app_data라는 스키마에 접근하겠다는소리다.


유저와 패스워드는 처음 mysql를 설치할때 설정한 값을 적용하면된다.

정상적으로 적었다면 아래와 같이 설정된다.



 

자이제 context-mapper.xml를 만들어주자.

 <?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:tx="http://www.springframework.org/schema/tx

xmlns:util="http://www.springframework.org/schema/util"

xmlns:aop="http://www.springframework.org/schema/aop"

xmlns:context="http://www.springframework.org/schema/context"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

<property name="dataSource" ref="dataSource" />

<property name="configLocation" value="classpath:/sqlmap/sql-mapper-config.xml" />

<property name="mapperLocations" value="classpath:/sqlmap/mappers/*.xml" />

</bean>

<bean id="mapper" class="org.mybatis.spring.mapper.MapperScannerConfigurer">

<property name="basePackage" value="

  com.pratice.project.dao

" />   

 <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />

</bean>


</beans>

 


설정이 조금많지만 복잡하지않다. 전부다 마이바티스 라이브러리를 사용하여 내부기능설정을 지정한다.

먼저 sqlSessionFacetory같은경우 데이터베이스에 접근하기위한 정보는 context-datasource.xml에 선언한 내용을 그대로 가지고 사용한다 실제로 보면 ref="dataSource"로 되어있는것을 알 수 있다. configLocation은 sql문을 쓸때 클래스path가 긴것을 개발자가 보기 쉽게하기 위해 사용된다. 이부분은 챕터를 보다보면 이해가될것이다. 그다음 mapperLocation은 우리가 만든 sql문의 접근위치를 이야기해준다


간단히 이야기하면 datasource정보를 접근해서 데이터베이스에 접근하고 mapperlocations에 위치한 쿼리문을 통해서 쿼리한다라는 의미다. 편의를위해서 쿼리문에서 configLocation에 위치한 설정파일로 쿼리를 실행할 때 도움을주고..


자 여기까지했으면 조금 의문이 들수 있다. 그럼 코드상에선 어떻게 접근을하는가?

그방법은 바로 아래에 있다.

mapper라는 bean을 하나 선언해준다. 이 mapper빈을 자바 코드내에서 autowired해서 가지고온다. 물론 autowired할때 mapper아래 설정한 property name="basePackage"에서 설정한 패키지에 존재하는 인터페이스만 접근하겠다는소리다.




인터페이스는 챕터를 진행하면서 만들것이다. 마지막에 정리가될것이다.

이제 다음으로 configLocation에 위치하는 /sqlmap/sql-mapper-config.xml를 만들어주자

sqlmap은 spring 폴더와 동일한위치에 만들어주면된다.

 <?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>

<typeAlias alias="name" type="com.pratice.project.model.Name"/>

</typeAliases>

</configuration>



내용은 정말간단하다. 우리가 만든Name 클래스를 간단하게 name이라는 명칭으로 접근하겠다는의미다. 이해가 안될수도있는데 만약 컨피그를 안사용하면 저 path.클래스 길게 일일히 쳐주어야한다.

다음으로 sqlmap안에 mappers라는 폴더를 만들어주고 그안에 query.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="com.pratice.project.dao.IGetDao">



<select id="selectName" parameterType="String" resultType="name">

 <![CDATA[

  SELECT UserName

         FROM usertbl

         WHERE UserName = #{name}

        ]]>

</select>

  </mapper>


이query.xml이 여러분들이 사용하게될 sql문을 적을장소이다.

mappernamespce는 내가만든 dao를 인터페이스를 의미한다.(곧만들것이다)

그리고 그 인터페이스의 정의된 메서드의 selectName의 쿼리는 아래에 나와있다.


이것을 보면 뭔가 보이지않는가? service인터페이스랑 형태만 다른뿐이지

쿼리자체가 실행부가된다고보면된다 즉 impl class implements service interface 가 그냥 query.xml implements dao interface가 된다고보면된다.


그리고 아래부분을 보시면 인터페이스에서 정의한 함수들을 구현하기위해 작성된 쿼리를 볼수 있다. 파라미터를 받겠다는 의미고 파라미터는 String으로 받겠다는 의미다. 그리고 resultType는 아까 config에서 설정한 Name class타입으로 객체를 리턴시키겠다는 것이다.


즉 쿼리를 실행하면 Name이란 객체로 데이터를 set시키고 리턴시키겠다는의미이다. 

정상적으로 세팅했다면 아래와같이 세팅이된다.




이제 dao를 만들어보자.. 그전에 한가지 바꿀부분이있다 모델클래스의 String name과 get,set 함수 이름을 좀 바꾸어야한다.

왜냐하면 DB컬럼과 이름을 똑같이해줘야 데이터를 받아올때 매핑될수 있다.

아래와 같이 바꿔주자.

 package com.pratice.project.model;


public class Name {

private String UserName;


public String getUserName() {

return UserName;

}


public void setUserName(String name) {

this.UserName = name;

}


}


이제 dao 패키지를 만들어주자. 그리고 패키지 안에 인터페이스를 만들어주자. 인터페이스명은 <mapper namespace="com.pratice.project.dao.IGetDao">선언한대로 IGetDao로 선언해주자.


그후..

<select id="selectName" parameterType="String" resultType="name">

 <![CDATA[

  SELECT UserName

         FROM usertbl

         WHERE UserName = #{name}

        ]]>

</select>

위에 선언한대로 selectName이란 함수를 만들어주고 name를 파라미터로 받아주는 메서드를 선언하자

 package com.pratice.project.dao;


public interface IGetDao {

public Name selectName(String name);

}


 


어떤가? 이제 이해가되지않는가? 구현부는 즉 implement영역은 쿼리, 인터페이스 영역은 IGetDao로 되어있다.

정상적으로 됬다면 위와같이 보일것이다.



이제 Service영역을 바꾸어보자.

 package com.pratice.project.service.impl;


import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;


import com.pratice.project.dao.IGetDao;

import com.pratice.project.model.Name;

import com.pratice.project.service.TestService;


@Service

public class TestServiceImpl implements TestService{


@Autowired

private IGetDao mapper;

@Override

public Name getName(String name) {

// TODO Auto-generated method stub

Name Testreturn = mapper.selectName(name);

return Testreturn;

}

}


어떤가? 아까  context-mapper.xml 설정했던 mapper를 기억하는가?

그 mapper를 bean 객체를 불어오는것이다. IGetDao란 형태의 인터페이스로 불러오라는것이다.

아까내용은 다음과같다

<bean id="mapper" class="org.mybatis.spring.mapper.MapperScannerConfigurer">

<property name="basePackage" value="

  com.pratice.project.dao

" />   

 <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />

</bean>


위의내용에서 선언된 mapper를 가지고오되 dao안에 있는 패키지안에 인터페이스를 사용해서 가지고온것이다.

그리고 이런부부은 우리가만든 sql문이랑 연결되는것이다.


이제 디비 컬럼값을 조회하기위해서 TestController를 바꾸어주자

 package com.pratice.project.controller;


import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.RestController;


import com.pratice.project.model.Name;

import com.pratice.project.service.TestService;


@RestController

public class TestController {


@Autowired

TestService testservice;

@RequestMapping(value = "/test/rest", method = RequestMethod.GET)

public Name getName(HttpServletRequest request, HttpServletResponse response) {

Name rt=testservice.getName("yoonjiwon");

return rt;

}

}



보면 바뀐부부은 이름을 조회하기 위해서 컬럼에 있는값들을 집어넣어주었다.

즉 로직을 설명하면

컨트롤러 url 매핑 -> 서비스 객체 오토와이어로 가지고오고 -> 서비스 impl 실행 -> mapper 객체 오토와이어로 가지고오고 mapper는 설정된 패키지 내에있는 인터페이스 형태로 가지고오게되고 -> mapper는 설정된 database로 연결되며 sqlmap에 선언된 쿼리문으로 연결된다. 


이런식이고 인터페이스와 sqlmap에 쿼리가 연결된다만 특별히 기억하면된다.

이제 이결과를 Rest client에서 실행하게되면.



위와같이 데이터베이스를 조회한 결과물이 나오게된다.


다음챕터는 json 포맷변화 컨트롤러의 파라미터를 받아서 조회하는 방법 까지 할예정이다. 조금더 여유가 있다면 트랜잭션처리까지 할예정이다.



'DEV > SPRING' 카테고리의 다른 글

Rest Service 구현[5]  (0) 2018.05.11
Rest Service 구현[4]  (0) 2018.05.11
Rest Service 구현[2]  (0) 2018.05.11
Rest Service 구현[1]  (0) 2018.05.11
Spring restful service 참고사이트  (0) 2018.05.11

mysql를 설치하고 간단하게 테이블을 만든후 tool로 컨트롤해보자.



http://withcoding.com/26

위의 방법으로 설치하면 된다.

툴은 mysql를 설치하면 자동으로 mysql workbench가 설치되니 따로 볼필요는 없다.

 

여기서 테스트를하기전에 간단한 단축키를알려드리면

컨트롤+엔터는 쿼리실행 컨트롤 + B는 쿼리 정리이다.


또한 설치과정중에 자동실행을 켜놓지않았다면(필자가 그렇다)

재시작후에 mysql이 가동이 안될텐데 윈도우 하단창에서 mysql notifiler 선택해서 서버를 스타트 시키면된다.






만약 정상적으로 실행이 안된다면..

http://ddochea.tistory.com/9

위블로그를 참조하기 바란다.
필자의 경우 C:\Users\(유저이름)\AppData\Roaming\Oracle\MySQL Notifier
settings.config가 위치해있었고..
Service네임이 MySQL57 이었다.

특히 ServiceName의 대소문자를 유심히봐야한다.(대소문자가 틀리면 작동이 안된다!)

여하튼 정상적으로 실행했다면 이제 스키마를 만들어주자
스키마는 여러분의 데이터베이스라고 생각하면된다.

Mysql workbench를 실행시켜주자




Root를 클릭해서 Mysql에 접속해주자. 좌측에  스키마 영역에서 우측을 클릭후에 create schema 를 클릭해주자.



스키마이름을 app_data 라고 짓고 Apply를 눌러주자



정상적으로 만들어졌다면 아래와 같이뜨게된다.


여기서 app_data를 클릭해주어야 해당 스키마를 선택하기때문에 클릭해주자



이제 쿼리탭에서 테이블을 만들어보자.



쿼리문은 다음과같다.

  create table userTbl (

UserID varchar(50) primary key,

UserName varchar(50) null,

UserAge int null,

Phone varchar(50) null,

Comment varchar(600) null);

 


데이터를 인서트해보자.

 insert into userTbl(UserID,UserName,UserAge,Phone,Comment) values 

('jiwon92','yoonjiwon','24','010-2009-0000','hello my name is jiwon yoon');

 


이제 정상적으로 인서트가 되었는지 select문을 통해 확인해보자.

 select * from usertbl;

 


정상적으로 보인다면 아래와 같이 보인다.


 


1과정을 다맞추었다면


좀더 Rest Service를  멋지게 꾸며보자


많은 분들도 아시겠지만 

Controller단에서 곧바로 로직을 처리하는것보단

인터페이스로 서비스로직을 정리하고 impl패키를 만들어 거기서 서비스 로직을 실행하는것이

좀더 효율적이라고 할 수 있다.


또한 JSON을 처리할때 애노테이션을 붙여서 json의 프로퍼티도 조절 할 수도 있다 .

이번 2과정은 그런과정을 좀더 진행해보자


일단 service 패키지를 하나 만들어주자.



이제 인터페이스를 만들어주자 해당 service에 TestService란 인터페이스를 만들어주자.

인터페이스가 만들어졌다면 아래와 같이 작성해보자.

package com.pratice.project.service;


import com.pratice.project.model.Name;


public interface TestService {

public Name getName(String name);

}


 

정상적으로 만들어졌다면 이제 로직을 실행하는 impl 를 만들어보자

먼저 service패키지안에 impl 패키지 폴더를 하나 만들어주자


패키지 안에 인터페이스를 implements 할 클래스를 만들어주자 이름은 TestServiceImpl로 지정해주자

그리고 해당과 같이 인터페이스 구현부를 작성해주자.

 package com.pratice.project.service.impl;


import com.pratice.project.model.Name;

import com.pratice.project.service.TestService;


@Service

public class TestServiceImpl implements TestService{


@Override

public Name getName(String name) {

// TODO Auto-generated method stub

Name Testreturn = new Name();

Testreturn.setName(name);

return Testreturn;

}


}


 


위의 결과는 1과정에서 실행한 컨트롤러단에 있는 로직을 전부 인터페이스로 옮겨준내용이다.

해당부분으로 로직을 분리해줌으로써 컨트롤러는 로직외적인 부분만 신경쓰고 서비스로직은 인터페이스에서 실행되게 구조를 변경해준것이다. 조금 바뀐 부분이라면 인자값으로 이제 객체를 만들어준다는것이다.


한가지 더 중요한 사실이 있다 서비스 클래스 위를 보면 @Service란 애노테이션이 붙은것을 확인 할 수 있다. 이부분은 bean 객체를 스프링 컨텍스트가 객체로 인식하게끔 만들어준다. 이부분은 컨트롤러 딴에서 객체를 autowired할때 필요하게된다.

이해가 안된다면 스프링에 대해서 조금 공부해보는 시간을 갖는걸 추천한다.



이제 컨트롤러를 바꾸어줘보자.

 package com.pratice.project.controller;


import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.RestController;


import com.pratice.project.model.Name;

import com.pratice.project.service.TestService;


@RestController

public class TestController {


@Autowired

TestService testservice;

@RequestMapping(value = "/test/rest", method = RequestMethod.GET)

public Name getName(HttpServletRequest request, HttpServletResponse response) {

Name rt=testservice.getName("jiwon");

return rt;

}

}



어떤가? 전과 비교해서 훨씬 간편해지지않았나? testservice란 객체는 @Service 애노테이션으로 가지고온 서비스 클래스 그자체이다.

이 서비스 객체 변수를 이용해 간편하게 객체를 리턴시킬수 있다.

이런 나누는결과는 여러가지 개발적으로 로직과 전처리 또는 에러처리등 코드적으로 나누어서 관리를 할 수 있고 디펜던시를 낮출 수 있다.


아여기서 스프링을 공부해 본사람은 알겠지만 설정파일이 가면갈수록 많아질텐데 이런것을 관리하기 위해서

몇가지 수정할 사항이 있다.


기본적으로 /src/webapp/WEB-INF 밑에 스프링에 관련된 설정파일들이 모여있는데 그냥 디폴트로 만들어지는 설정파일은 단일 한개로

지정되어있고 web 설정파일이 있어야할 자리에 Root context와 servlet context가 모여져있어 별로 보기가 좋지않다. 또한 추가적으로 설정파일을 작성한다고 했을시에도 현재는 Root context와 servlet context에만 추가 할수 있기때문에 보기 좋은 구조가아니다.


이런 설정을 바꾸기위해 아래와같이 변경해보자.[/src/webapp/WEB-INF/web.xml]

 <?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">


<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->

<!-- 

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/spring/root-context.xml</param-value>

</context-param>

  -->

<context-param>

<param-name>contextConfigLocation</param-name>

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

</context-param>

<!-- Creates the Spring Container shared by all Servlets and Filters -->

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>


<!-- Processes application requests -->

<servlet>

<servlet-name>appServlet</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>appServlet</servlet-name>

<url-pattern>/</url-pattern>

</servlet-mapping>


</web-app>



보시다시피 root-context.xml를 주석처리하였고 나머지 설정파일들은 spring 폴더에 전부 설정을 할수 있도록 변경하였다.


위와같은설정을하면 resources에 context로 시작하는는 설정파일들을 한곳에서 관리하면서 쉽게 수정할 수 있다.


그럼 실제로 spring폴더를 만들고 common한 설정파일 한개를 만들어줘보자.



spring이 정상적으로 만들어졌다면 이제 이안에 common한 xml를 하나 만들어보자.

파일명은 context-common.xml이다.



 <?xml version="1.0" encoding="UTF-8"?>


<beans

xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.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.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"

xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans">


<context:component-scan use-default-filters="false"

base-package="com.pratice.project">


<context:include-filter expression="org.springframework.stereotype.Component"

type="annotation" />


<context:include-filter expression="org.springframework.stereotype.Service"

type="annotation" />


<context:include-filter expression="org.springframework.stereotype.Repository"

type="annotation" />


</context:component-scan>


</beans>

 


많이 복잡해보이지만 전혀그렇지않다 상단 내용은 spring기능을 사용하기 위한 선언문이고

아래 내용은 전체 패키지내에서  Componet,Service,Repository로 들어오는 애노테이션은 빈처리로 스캔하겠다는 의미다 

빈처리는 객체로 인식하겠다는소리다.


또한 추가적으로 src/webpp/WEB_INF/spring/appServlet/serlet-context.xml를 아래와 같이 바꾸어준다.

 <?xml version="1.0" encoding="UTF-8"?>

<beans:beans xmlns="http://www.springframework.org/schema/mvc"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:beans="http://www.springframework.org/schema/beans"

xmlns:context="http://www.springframework.org/schema/context"

xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.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.xsd">


<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->

<annotation-driven />


<context:component-scan base-package="com.pratice.project" use-default-filters="false">

<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />

</context:component-scan>

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->

<resources mapping="/resources/**" location="/resources/" />


<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->

<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<beans:property name="prefix" value="/WEB-INF/views/" />

<beans:property name="suffix" value=".jsp" />

</beans:bean>

<!-- 

<context:component-scan 

base-package="com.pratice.project">


</context:component-scan>

 -->

</beans:beans>


 

여러 내용이 많지만 간단하게 말해 컨트롤러 애노테이션을 스캔해서 객체화 시키겠다는것이다.


이렇게 나누어 두는 내용은 view단에 서블릿에서만 컨트롤러 단에 해당되거나 뷰단에 해당되는 내용들을 처리하고

나머지 설정이나 서비스단이나 다른 애노테이션처리는 전부 다른 설정파일에서 처리하겠다는 의미다.


이렇게 나누는 이유는 크게 2가지로 압축된다


첫째. 스프링에서 뷰단,컨트롤러 설정은 서블릿 컨텍스트가 담당하고 나머지 설정파일들은 전부 다른 컨텍스트가 담당하게 만드는게 관리하기 편한다.

두번째. web.xml 에서 보면 context-*.xml로 선언되있는것을 볼수가있다. 즉  context 이름으로 다양한 설정파일을 쉽게 관리 할수 있다.


이런점때문에 나누었고 결론적으로 서비스 bean[@Service]을 관리하는건 common context가 관리하고 나머지 @Controller 나 jsp 매핑은 서블릿 context가 관리 하는것이다.


다음 3장에서는 DAO를 통한 데이터베이스에 해당정보를 가지고와서 뿌려주는 것을 배워보도록하겠다.



'DEV > SPRING' 카테고리의 다른 글

Rest Service 구현[5]  (0) 2018.05.11
Rest Service 구현[4]  (0) 2018.05.11
Rest Service 구현[3]  (0) 2018.05.11
Rest Service 구현[1]  (0) 2018.05.11
Spring restful service 참고사이트  (0) 2018.05.11

+ Recent posts