๋กœ์ผ“๐Ÿพ
article thumbnail

 

์ด ๊ธ€์€ ์ œ๊ฐ€ ์ดํ•ดํ•œ ๊ฐœ๋…์„ ๋ฐ”ํƒ•์œผ๋กœ ์ž‘์„ฑํ•˜์˜€๊ธฐ์— ํ‹€๋ฆฐ ๋ถ€๋ถ„์ด ์žˆ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ‹€๋ฆฐ ๋ถ€๋ถ„ ์žˆ๋‹ค๋ฉด ์ง€์ ํ•ด์ฃผ์„ธ์š” :)

 

์Šคํ”„๋ง์—์„œ ๋งํ•˜๋Š” ์ปจํ…์ŠคํŠธ(context)๋Š” ์Šคํ”„๋ง์ด ๊ด€๋ฆฌํ•˜๋Š” ๋นˆ๋“ค์ด ๋‹ด๊ฒจ ์žˆ๋Š” ์ปจํ…Œ์ด๋„ˆ ๋ผ๊ณ  ์ƒ๊ฐํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 

์Šคํ”„๋ง์„ ๊ณ„์† ๊ณต๋ถ€์ค‘์ด์ง€๋งŒ ์—„์ฒญ ํ—ท๊ฐˆ๋ ธ๋˜ ๋ถ€๋ถ„์ด WebApplicationContext์™€ ApplicationContext์˜ ๊ด€๊ณ„, web.xml์—์„œ์˜ servlet-context์™€ root-context์˜ ๊ด€๊ณ„ ๊ทธ๋ฆฌ๊ณ  ContextLoaderListenter์™€ dispatcher-servlet์˜ ๊ด€๊ณ„ ์ด ์ด 3๊ฐœ์˜ ๊ด€๊ณ„๊ฐ€ ๋ณผ๋•Œ๋งˆ๋‹ค ํ—ท๊ฐˆ๋ ธ์Šต๋‹ˆ๋‹ค. 

 

์Šคํ”„๋ง ๋‚ด์—์„œ์˜ context ๊ตฌ์กฐ

 


# root-context ์™€ sevlet-context ํ๋ฆ„

 

์ด ๊ธ€์€ WAC์™€ AC ๊ด€๋ จ ๊ธ€์ด ์•„๋‹ˆ๋ฏ€๋กœ root-context์™€ servlet-context์— ๋Œ€ํ•ด์„œ๋งŒ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

STS์„ ํ™œ์šฉํ•˜์—ฌ ์Šคํ”„๋ง ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋ฉด 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 https://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/config/action-mybatis.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>

 

<context-param> ํƒœ๊ทธ ์•ˆ์— ์žˆ๋Š” ์„ค์ •์ด root-context ๊ด€๋ จํ•œ ๊ฒƒ๋“ค์ด๊ณ  <servelet> ํƒœ๊ทธ ์•ˆ์— ์žˆ๋Š” ์„ค์ •์ด servlet-context ๊ด€๋ จ ์„ค์ •์ž…๋‹ˆ๋‹ค.

 

ํ๋ฆ„์„ ์ •๋ฆฌํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

  1. <context-param>์„ ์ด์šฉํ•˜์—ฌ root-context ์„ค์ •์„ ํ•ด์ค๋‹ˆ๋‹ค.(action-mybatis๊ฐ€ root-context)
  2. <listener>ํƒœ๊ทธ์˜ ContextLoaderListener ํด๋ž˜์Šค๋ฅผ ์ด์šฉํ•˜์—ฌ contextConfigLocation์— ์žˆ๋Š” root-context๋“ค์„ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค.
  3. ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ๋ฐ›์œผ๋ฉด <servlet> ํƒœ๊ทธ ์•ˆ์— ์žˆ๋Š” ์„ค์ •๋“ค์ด ์ž‘๋™ํ•˜๋ฉด์„œ servlet-context(sertvlet-context.xml)์„ ๋ถˆ๋Ÿฌ์˜ด๊ณผ ๋™์‹œ์— root-context์™€ ๊ฐ™์ด ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค. ์ด๋•Œ DispatcherServlet ํด๋ž˜์Šค๋ฅผ ์‹คํ–‰์‹œํ‚ต๋‹ˆ๋‹ค.

 


# root-context์™€ servlet-context ๋น„๊ต

 

์œ„์— ํ๋ฆ„๋„๋ฅผ ๊ฐ„๋‹จํ•˜๊ฒŒ ์„ค๋ช…ํ•˜์ž๋ฉด web.xml์—์„œ ContextLoaderListener๋ฅผ ์ด์šฉํ•˜์—ฌ root-context๋ฅผ, DispatcherServlet๋ฅผ ์ด์šฉํ•˜์—ฌ servlet-context๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

ใ…ฃ root-context 

  • root-context์— ๋“ฑ๋ก๋˜๋Š” ๋นˆ๋“ค์€ ๋ชจ๋“  ์ปจํ…์ŠคํŠธ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. (๊ณต์œ  ๊ฐ€๋Šฅ)
  • service๋‚˜ dao๋ฅผ ํฌํ•จํ•œ, ์›น ํ™˜๊ฒฝ์— ๋…๋ฆฝ์ ์ธ ๋นˆ๋“ค์„ ๋‹ด์•„๋‘ก๋‹ˆ๋‹ค.
  • ์„œ๋กœ ๋‹ค๋ฅธ servlet-context์—์„œ ๊ณต์œ ํ•ด์•ผ ํ•˜๋Š” ๋นˆ๋“ค์„ ๋“ฑ๋กํ•ด๋†“๊ณ  ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • servlet-context ๋‚ด ๋นˆ๋“ค์€ ์ด์šฉ์ด ๋ถˆ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

 

ใ…ฃ servlet-context

  • servlet-context์— ๋“ฑ๋ก๋˜๋Š” ๋นˆ๋“ค์€ ํ•ด๋‹น ์ปจํ…Œ์ŠคํŠธ์—์„œ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • DispatcherServlet์ด ์ง์ ‘ ์‚ฌ์šฉํ•˜๋Š” ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ํฌํ•จํ•œ ์›น ๊ด€๋ จ ๋นˆ์„ ๋“ฑ๋กํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
  • ๋…์ž์ ์ธ ์ปจํ…์ŠคํŠธ๋“ค์„ ๊ฐ€์ง€๋ฉฐ, root-context ๋‚ด ๋นˆ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

 

root-context๋Š” ๊ณต์œ ๊ฐ€ ๊ฐ€๋Šฅํ•œ ๋ฐ˜๋ฉด servlet-context๋Š” ํ•ด๋‹น ์ปจํ…์ŠคํŠธ ๋‚ด์— ์žˆ๋Š” ๋นˆ๋งŒ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋ฏ€๋กœ 

root-context ๊ฐ™์€ ๊ฒฝ์šฐ Service์™€ Repository(Dao) servlet-context ๊ฐ™์€ ๊ฒฝ์šฐ Controller๋ฅผ ๋‹ด๋‹นํ•ฉ๋‹ˆ๋‹ค.

 

๋งŒ์•ฝ ๊ฒน์น˜๋Š” ๋นˆ์ด ์ƒ๊ธธ ๊ฒฝ์šฐ servlet-context์˜ ๋นˆ์„ ์šฐ์„ ์‹œ ํ•ฉ๋‹ˆ๋‹ค.

 

์ด์ƒ root-context์™€ servlet-context์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์•˜์Šต๋‹ˆ๋‹ค.

 

์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

์งˆ๋ฌธ์€ ์–ธ์ œ๋‚˜ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค.

 

"๋‚œ ๋ฐ˜๋“œ์‹œ ๋ฐฑ์—”๋“œ ์™•์ด ๋ ๊ฑฐ์•ผ"

 

profile on loading

Loading...