π μ€νλ§ νλ‘μ νΈ μ€μ νμΌ κ΄λ¦¬
μ€νλ§ νλ‘μ νΈλ₯Ό μμνκΈ°μ μμ μ€νλ§μ μ€μ νμΌμ μ€μ νλ λΆλΆμ΄ μ΄λ €μ΄ νΈμ΄λ€. Node.js λ‘λ§ νλ‘μ νΈλ₯Ό ν΄λ΄€λ λλ‘μ¨λ κ½€ νλ μμ λ€μ΄μλ€. XML νμΌλ€λ μ²μμ΄μκ³ JSP μ¬μ©λ μ²μμ΄μ΄μ κ½€λ λ§μ μκ°μ μλΉνμλ€.
μ§κΈκΉμ§ λ°°μ΄ μ€μ νμΌμ web.xml / servlet-context.xml / pom.xml / application-config.xml νμΌμ΄λ€. μ¬κΈ°μ λλ λ°λ‘ config νμΌμ λ§λ€μ΄ κ²½λ‘λ₯Ό λ³κ²½ν΄μ£ΌμκΈ° λλ¬Έμ application-config.xml μ root-context.xml κ³Ό κ°λ€κ³ 보면λλ€.
μ΄ λ΄μ©μ μλμμ μ€λͺ νλ€.
1. 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>classpath:application-config.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>
μμ xml νμΌμ μ€μ μ μ‘°κΈ λ°κΎΌ xmlμ΄λ€. context-param μ μ μΈνκ³ λ κΈ°λ³Έ μμ±μ΄ λλ€.
context-paramμ λ°κΎΌ μ΄μ κ° λ°λ‘ application-config.xml νμΌμ μλ‘ λ§λ€μκΈ° λλ¬Έμ΄λ€.
root-context.xml μ νλ‘μ νΈλ₯Ό μμ±νλ©΄ μλμΌλ‘ μμ±λλ€. μ¬κΈ°μ λΉ μ€μ μ ν΄μ£Όμ΄λ λμ§λ§ λλ λ°λ‘ λ§λ€κ³ κ΄λ¦¬λ₯Ό ν΄μ param-valueμ κ²½λ‘λ₯Ό classpath:application-config.xml λ‘ λ°κΎΈμ΄ μ£Όμλ€.
κ·Έλ¦¬κ³ Servletμ μ¬μ©νμκΈ° λλ¬Έμ servlet-context.xmlλ μ€μ ν΄μ€μΌ νλ€.
- classpath : eclipseμ src/main/resources
2. Servlet-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 https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://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 />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<resources location="/images/" mapping="/images/**"/>
<!-- 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.example.myapp.controller" />
</beans:beans>
- <annotation-driven/> : transactional μ΄λ Έν μ΄μ μ μ¬μ©νκΈ° μν νκ·Έ
- <resources> : JSPμμ Imgνκ·Έ, JS, CSS νμΌμ μ½μ΄ μ€κΈ° μν νκ·Έ
<beans: ~> : JSPλ₯Ό μ¬μ©νκΈ° μν νκ·Έ
<context-component-scan> : packageμμμ @Controller, @Service, @Repository λ± μ΄λ Έν μ΄μ μ μ¬μ©νκΈ° μν νκ·Έ
'π» BackEnd > π’ Spring | SpringBoot' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
π’ [Spring] μ€νλ§ μμ‘΄μ± μ£Όμ (DI) - [1] (0) | 2023.07.06 |
---|---|
π’ [Spring] μ€νλ§ νμΌ μ λ‘λ (0) | 2023.06.30 |
π’ [Spring] μ€νλ§ λΉ(Bean) μ΄λ? (0) | 2023.06.23 |
π’ Spring Boot μμνκΈ° (0) | 2023.03.09 |
μΈν 리μ μ΄(Intellij) νμ λΌμ΄μΌμ€ κ°±μ (0) | 2023.03.08 |