본문 바로가기
Spring/Spring 실습

스프링 기본 환경설정

by java나유 2022. 8. 29.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>그룹아이디 입력</groupId>
  <artifactId>프로젝트 이름</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <properties>
  <maven.compiler.target>1.8</maven.compiler.target>
  <maven.compiler.source>1.8</maven.compiler.source>
  </properties>
  <dependencies>
  <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.2.19.RELEASE</version>
</dependency>

  </dependencies>

</project>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  version="3.1"
  metadata-complete="true">

  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>
  <servlet>
  <servlet-name>webtest</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  </servlet>
  
  <servlet-mapping>
  <servlet-name>webtest</servlet-name>
  <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

<url-pattern>/<url-pattern>으로해주기

 

 

webtest-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/mvc
        https://www.springframework.org/schema/mvc/spring-mvc.xsd
        ">

	<!-- 
	beans : mvc를 사용하도록 적용(mvc태그를 사용하기 위해)
	정적파일 서비스를 하기 위해 사용(기본 정적파일 서비스를 사용하지 못함) 
	
	 -->
	<!-- /admin/ : 가상의 디렉토리명(Controller은 가상 디렉토리로 움직이게 됨) -->
	<bean id="/index" class="test1.index"></bean>
	<bean id="/main" class="test1.main"></bean>
<bean id="/postok.do" class="test1.postok"></bean>
	<!-- Controller와 jsp이름을 동일화 시키는 작업 -->
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/view/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>


	<!-- HTML 출력파트 정적파일 서비스 (HTML, JS, JQuery, CSS, IMAGE)-->
	<!-- WEB-INF 빼고 출력할 수 있음  -->
	 <mvc:resources location="/" mapping="/**"></mvc:resources> 
	<!--  <mvc:resources location="/html" mapping="/**"></mvc:resources> -->


</beans>
728x90

댓글