본문 바로가기
Back-end/Spring

[Spring] Controller Biz 사용하기

by JiGyeong 2016. 4. 18.

Biz를 사용하고 싶으면 Interface로 만든다.



Biz 패키지 안에 impl 패키지를 만들어준다.




관리하기 편하도록 impl 패키지를 따로 만든다.




applicationContext.xml

1
2
3
4
5
6
7
    <bean id="articleController"
            class="com.ktds.jgbaek.web.ArticleController">
        <property name="articleBiz" ref="articleBiz"/>
    </bean>
            
    <bean id="articleBiz"
            class="com.ktds.jgbaek.biz.impl.ArticleBizImpl"/>
cs


이렇게 쓰면 Controller가 필요한 객체 Biz를 사용할 수 있게 된다.

Service Controller Biz를 만든다고 생각한다.

여기서 id는 변수명이고 class는 객체이다.

articleController는 객체가 필요하다.-> aritcleBiz가 필요하다

그러므로 articleBiz는 객체이다.




url과 관련있다싶으면 applicationContext에 넣어주고
나머지것들은 분리시킨다.
applicationContext가 비대해 지는것을 막기 위해서


Spring Bean Definition File을 spring 폴더안에 만들어준다.






web.xml에 ContextLoaderListener를 추가해준다.

모든 Context를 추가해 줄수있게

url을  /WEB-INF/spring/*Context.xml 로 써준다.

1
2
3
4
5
6
7
8
9
10
11
12
<!-- needed for ContextLoaderListener -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/spring/*Context.xml
        </param-value>
    </context-param>
 
    <!-- Bootstraps the root web application context before servlet initialization -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
cs



'Back-end > Spring' 카테고리의 다른 글

[Spring] ORM : MyBatis 연동 2  (0) 2016.04.19
[Spring] ORM : MyBatis 연동  (0) 2016.04.19
[Spring] Controller 리턴타입  (0) 2016.04.15
[Spring] 인터셉터 ( Inerceptor )  (0) 2016.04.15
[Spring] ExceptionHandler  (0) 2016.04.14