# [spring-servlet.xml] : controller 설정 등 각종 설정
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.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">
<context:annotation-config />
<context:component-scan base-package="com.bitacademy.emaillist.controller" />
<!-- validator, conversionService, messageConverter를 자동으로 등록 -->
<mvc:annotation-driven />
<!-- 서블릿 컨테이너의 디폴트 서블릿 위임 핸들러 -->
<!-- 정적파일 에러 세팅 -->
<mvc:default-servlet-handler />
<!-- ViewResolver 설정 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
<property name="order" value="1" />
</bean>
</beans>
[applicationContext.xml] : repository 설정
<?xml version="1.0" encoding="UTF-8"?>
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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.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/task http://www.springframework.org/schema/task/spring-task.xsd">
<context:annotation-config />
<context:component-scan base-package="com.bitacademy.emaillist.repository">
<!-- @Repository, @Service, @Component 만 스캔하겠다는 설정 -->
<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository" />
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service" />
<context:include-filter type="annotation" expression="org.springframework.stereotype.Component" />
</context:component-scan>
</beans>
spring-servlet.xml 에서 com.bitacademy.emaillist.controller 의 스캔하게 설정했고
applicationContext.xml 에서는 com.bitacademy.emaillist.repository 의 스캔을 설정했는데
굳이 두개의 xml파일로 나누어서 스캔 설정을 한 이유가 있을까요?
spring-servlet.xml 에 controller, repository 스캔을 한번에 하면 안되나요?
=> controller 스캔과 repository 스캔 설정을 따로 두는 것을 spring에서 권고하고 있다.
spring-servlet.xml 파일에 비지니스 객체를 먼저 로딩시키고,
DB요청이 들어왔을때 repository.xml 파일의 객첼르 로딩시키는게 효율적이다.
# [web.xml] 설정
<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>mysite03</display-name>
<!-- ContextLoadListener -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Dispatcher Servlet: Frontend Controller -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- 한글인코딩 설정 -->
<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>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
# Spring 내부 프로세스
============= 과제 Guestbook03 프로세스 설명 =============
'비트교육센터[전문가반]' 카테고리의 다른 글
Spring MVC [비트교육센터] _ 복습04 _ API 전용 컨트롤러 (0) | 2021.04.24 |
---|---|
Spring MVC [비트교육센터] _ 복습03 (0) | 2021.04.22 |
Spring MVC [비트교육센터] _ 복습01 (0) | 2021.04.21 |
JavaScript 복습02 (0) | 2021.03.23 |
JavaScript 복습01 (0) | 2021.03.22 |