-
Spring MVC 초기설정Web (Spring ) 2016. 8. 3. 15:02
이클립스 실행
File -> New -> Other -> Spring -> Spring Legacy Project -> Spring MVC Project
프로젝트 생성 후
Server 설정
Window -> Preferences -> Server -> Runtime Environments
Add -> "자신의 톰캣버전 선택" -> jdk 버전 선택 후 -> Finish
Maven 설정
Window -> Preferences -> Maven -> User Settings ->"자신의 메이븐 경로 찾아가기"
D:\java\maven\apache-maven-3.3.9\conf (필자 기준)
setting.xml
<localRepository>D:\java\maven\repo</localRepository>
변경
target 설정
컴파일된 결과까지 올라갈 필요는 없다. 개발 소스만 관리하면 되고, 클래스 파일까지 올라가면, 여러가지 문제점들이 발생될 수도 있다
따라서 컴파일된 결과는 제외하고 개발소스만 올라가도록 설정한다.
Window -> Preferences -> Team -> Ignored Resources -> Add Pattern -> */target/*
Servlet 설정
12345678910111213141516171819202122232425262728<?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 http://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://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="/**" location="/webapp/" /><!-- 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/jsp/" /><beans:property name="suffix" value=".jsp" /></beans:bean><context:component-scan base-package="com.my.bin" /></beans:beans>cs 16번 라인 resource mapping
JS,CSS,IMAGE 등등 모든 Resource(자원을) 해당 경로에서 가져온다.
20번 라인 prefix
View Resolver 뷰가 보여지는 폴더를 매핑
21번 라인 suffix
.jsp로 시작하는 파일을 Controller에서 String명으로 받게끔 설정해준다.
Web.xml설정
1234567891011121314151617181920212223242526272829303132333435363738<?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 http://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:config/spring/context-*.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>action</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/config/*-servlet.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>action</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping></web-app>cs 26번 라인 Servlet Mapping
해당경로에 있는 -servlet.xml 매핑 해준다.
34번 라인 Url Pattern
.do로 Url을 인식한다.
Controller 실행
1234567891011121314151617package com.my.bin;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;@Controllerpublic class TestController {@RequestMapping(value="/test.do")public String test(){System.out.println("=================================test=================================");return "/test";}}cs 결과 화면
'Web (Spring )' 카테고리의 다른 글
[스프링시큐리티] DB를 사용한 로그인인증 & 권한 처리 (0) 2016.08.04 Eclipse Theme 설정 (0) 2016.08.04 Eclipse 주석 설정 (0) 2016.08.04 Spring + MyBatis 연동방법 (0) 2016.08.04 [Hack] 개발 폰트 (0) 2016.08.03