본문 바로가기

Spring

이클립스 Spring mvc 패턴 실습

 

 

 

 

 

 

mvc 메이븐 프로젝트 생성 기본 단계

 

 

프로젝트 설정(Properties)

 

 

 

 

1.5는 자바 버전을 의미한다.

 

 

자신에게 맞는 자바 버전으로 맞춰준다.

 

 

 

설정 변경 후 프로젝트 리프레쉬 해준다.

 

다이나믹 웹 모듈이 3.0으로 변경 되어 있으면 올바르게 변경된 것이다.

 

2.step 프로젝트 생성을 위한 파일 설정 

 

alt + f5번을 이용한다.

 

<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 http://maven.apache.org/maven-v4_0_0.xsd">


	<modelVersion>4.0.0</modelVersion>
	<groupId>Spring999</groupId>
	<artifactId>Spring999</artifactId>
	<packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>Spring02 Maven Webapp</name>
	
	<url>http://maven.apache.org</url>


	<properties>
		<spring.version>4.0.1.RELEASE</spring.version>
	</properties>
	<repositories>
		<repository>
			<id>Spring Plugins</id>
			<url>https://repo.spring.io/plugins-release/</url>
		</repository>
	</repositories>
	<dependencies>		
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.7</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet.jsp</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.2</version>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.0.1</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>4.1.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.0</version>
				<configuration>
					<source>16</source>
					<target>16</target>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>3.3.2</version>
			</plugin>
		</plugins>
	</build>
</project>

POM.XML

 

 

 

내가 다운 받은 라이브러리의 내역

 

src-main-webapp-web-inf 안에 xml 파일 생성

 

 

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

	xmlns:context="http://www.springframework.org/schema/context"

	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

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc.xsd">

	<!-- 컨트롤러 위치 설정 -->

	<context:component-scan base-package="Pack01" />

	<mvc:annotation-driven />

	<mvc:default-servlet-handler />


	<!-- 뷰 위치 설정 -->

	<mvc:view-resolvers>

		<mvc:jsp prefix="/WEB-INF/Views/" />

	</mvc:view-resolvers>

</beans>

dispatcher-servlet.xml 안에 넣어준다

 

 

 

 

 

index.jsp

 

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:context="http://www.springframework.org/schema/context"

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

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<!-- 컨트롤러 위치 설정 -->

<context:component-scan base-package="Pack01" />

<mvc:annotation-driven />

<mvc:default-servlet-handler />


<!-- 뷰 위치 설정 -->

<mvc:view-resolvers>

<mvc:jsp prefix="/WEB-INF/Views/" />

</mvc:view-resolvers>

</beans>

3step fom.xml

 

 

 

 

항상 url 확인해서 프로젝트 이름 확인 하기

복사한 프로젝트 설정법