환경정보

   - eclipse indigo
   - java1.6
   - spring3.0
   - tomcat7


1. project 생성

 


- group id는 도메인으로 입력(본인취향대로)
- artifact id는 프로젝트명 


 2. 프로젝트 생성후 프로젝트 properties > project facets 변경


- convert to faceted from 클릭 

     

- Dynamic Web Module 체크
- 하단에 노란 박스 Further configuration available 클릭

 


- content directory 를 webapps로 변경
- Gernerate web.xml deployment descriptor 체크 

- 모두 OK후에 webapps 폴더를  src/main/으로 이동

   아래처럼 변경



 3. 프로젝트 생성후 프로젝트 properties > Deployment Assembly 변경 

- add 클릭하여 java build path Entries "Next" 후 maven 고르고 Finish


- 기존에 Deploy Path "/"를 Romove하고 새로 추가

- Folder 선택 후 src/main/webapps 로 선택하여 추가

 

 


-  모두 추가되어 완료된 모습.


4. 여기서부터 소스 추가 및 수정

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

  <modelVersion>4.0.0</modelVersion>

  <groupId>test</groupId>

  <artifactId>study</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  <name>beans9</name>

  <description>study project</description>

    

  <properties>

        <java-version>1.6</java-version>

        <org.springframework-version>3.0.6.RELEASE</org.springframework-version>

        <org.aspectj-version>1.6.9</org.aspectj-version>

        <org.slf4j-version>1.5.10</org.slf4j-version>

  </properties>

   

  <!-- repository -->

  <repositories>

    <repository>

     <id>mesir-repo</id>

     <url>http://mesir.googlecode.com/svn/trunk/mavenrepo</url>

    </repository>

  </repositories>

 

  <dependencies>

        <!-- Spring -->

        <dependency>

            <groupId>org.springframework</groupId>

            <artifactId>spring-context</artifactId>

            <version>${org.springframework-version}</version>

            <exclusions>

                <!-- Exclude Commons Logging in favor of SLF4j -->

                <exclusion>

                    <groupId>commons-logging</groupId>

                    <artifactId>commons-logging</artifactId>

                 </exclusion>

            </exclusions>

        </dependency>

        <dependency>

            <groupId>org.springframework</groupId>

            <artifactId>spring-webmvc</artifactId>

            <version>${org.springframework-version}</version>

        </dependency>

 

        <!-- Logging -->

        <dependency>

            <groupId>org.slf4j</groupId>

            <artifactId>slf4j-api</artifactId>

            <version>${org.slf4j-version}</version>

        </dependency>

        <dependency>

            <groupId>org.slf4j</groupId>

            <artifactId>jcl-over-slf4j</artifactId>

            <version>${org.slf4j-version}</version>

            <scope>runtime</scope>

        </dependency>

        <dependency>

            <groupId>org.slf4j</groupId>

            <artifactId>slf4j-log4j12</artifactId>

            <version>${org.slf4j-version}</version>

            <scope>runtime</scope>

        </dependency>

        <dependency>

            <groupId>log4j</groupId>

            <artifactId>log4j</artifactId>

            <version>1.2.15</version>

            <exclusions>

                <exclusion>

                    <groupId>javax.mail</groupId>

                    <artifactId>mail</artifactId>

                </exclusion>

                <exclusion>

                    <groupId>javax.jms</groupId>

                    <artifactId>jms</artifactId>

                </exclusion>

                <exclusion>

                    <groupId>com.sun.jdmk</groupId>

                    <artifactId>jmxtools</artifactId>

                </exclusion>

                <exclusion>

                    <groupId>com.sun.jmx</groupId>

                    <artifactId>jmxri</artifactId>

                </exclusion>

            </exclusions>

            <scope>runtime</scope>

        </dependency>

 

        <!-- maven -->

        <dependency>

            <groupId>org.mybatis</groupId>

            <artifactId>mybatis</artifactId>

            <version>3.0.1</version>

        </dependency>

 

        <!-- ojdbc -->

        <dependency>

         <groupId>com.oracle</groupId>

         <artifactId>ojdbc14</artifactId>

         <version>10.2.0.4.0</version>

        </dependency>

 

    </dependencies>

</project>

view rawgistfile1.xmlThis Gist brought to you by GitHub.


porm.xml 저장후 project 우클릭 > run as > maven install 클릭

src/main/webapps/WEB-INF/spring 폴더 추가
src/main/webapps/WEB-INF/spring/root-context.xml 파일생성

root-context.xml

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

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

    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-3.0.xsd">    

    <!-- Root Context: defines shared resources visible to all other web components -->        

</beans>

view rawgistfile1.xmlThis Gist brought to you by GitHub.


src/main/webapps/WEB-INF/spring/appServlet 폴더추가
src/main/webapps/WEB-INF/spring/appServlet/servlet-context.xml 파일생성

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 http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

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

        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.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/" />

 

    <!-- 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="www.beans9.com" />    

</beans:beans>

view rawservlet-context.xmlThis Gist brought to you by GitHub.


* 빨간글씨 부분은 본인 프로젝트 도메인 및 폴더명과 동일해야함.


src/main/webapps/WEB-INF/web.xml 파일 변경

web.xml

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

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

    id="WebApp_ID" version="3.0">

 

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->

    <context-param>

        <param-name>contextConfigLocation</param-name>

        <param-value>/WEB-INF/spring/root-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>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>

view rawweb.xmlThis Gist brought to you by GitHub.


* 경로가 써져있는부분이 실제 경로와 동일해야함

src/main/java/www/beans9/com/HomeController.java 파일생성

HomeController.java

package www.beans9.com;

 

import java.text.DateFormat;

import java.util.Date;

import java.util.Locale;

 

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

 

@Controller

public class HomeController {

    private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

 

    @RequestMapping(value = "/", method = RequestMethod.GET)

    public String home(Locale locale, Model model) {

        logger.info("Welcome home! the client locale is "+ locale.toString());

 

        Date date = new Date();

        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

 

        String formattedDate = dateFormat.format(date);

 

        model.addAttribute("serverTime", formattedDate );

 

        return "home";

    }

}

view rawHomeController.javaThis Gist brought to you by GitHub.

 

src/main/webapps/WEB-INF/views 폴더 생성
src/main/webapps/WEB-INF/views/home.jsp  파일 생성

home.jsp 

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

</head>

<body>

${serverTime }

</body>

</html>

view rawgistfile1.htmlThis Gist brought to you by GitHub.


자 이제 was를 기동시켜 Spring MVC가 제대로 동작하는지 확인 



이상없이 출력된다면 ^^ 기본 환경 구축 완료.

   

 해당 프로젝트 실제 파일경로들 /

혹 해당파일이 필요하신분들을 위해 프로젝트 Achiev파일을 올려놓으니^^ 사용하셔도 됩니다. 

 spring.zip

 
작성자 : beans9 (http://beans9.tistory.com)
출처 -
http://beans9.tistory.com/103

'IDE & Build > Maven' 카테고리의 다른 글

Maven 설치 2  (0) 2012.03.25
Maven 설치 1  (0) 2012.03.25
기존의 프로젝트에 Maven 도입하기  (0) 2012.03.23
pom.xml  (0) 2012.03.23
Apache Maven 개요  (0) 2012.03.23
Posted by linuxism
,