admin

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

1) pom에 slf4j, slf4j-class추가

2) logback.xml 추가

 src/main/resources/logback.xml



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

<configuration>

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">

   <layout class="ch.qos.logback.classic.PatternLayout">

<Pattern>

%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n

</Pattern>

   </layout>

</appender>

    <appender name="FILE" class="ch.qos.logback.core.FileAppender">

        <file>/springframework_prj/logs/apache.log</file>

        

        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

             <fileNamePattern>gsb_log.%d{yyyy-MM-dd}.log</fileNamePattern>

            <minIndex>1</minIndex>

            <maxIndex>3</maxIndex>

        </rollingPolicy>


        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">

            <maxFileSize>50MB</maxFileSize>

        </triggeringPolicy>

       

        <append>true</append>

        <encoder>

            <pattern>%d [%thread] %-5level %logger - %msg%n</pattern>

        </encoder>


    </appender>

    <logger name="org.springframework.jdbc.core.StatementCreatorUtils">

      <level value="debug" />

    </logger>

    <logger name="org.springframework">

        <level value="debug" />

    </logger>

    <logger name="net.sf.ehcache">

        <level value="debug" />

    </logger>

<logger name="com.my.framework">

<level value="debug" />

</logger>  

    <root level="debug">

        <appender-ref ref="CONSOLE" />

        <appender-ref ref="FILE" />

    </root>

</configuration> 

 

3) sample 프로그램 작성

SampleController.java을 열어 Logger를 추가한다.



4) 브라우져을 열어 http://localhost:8080/FrameWork/sample을 입력

Eclipse의 로그 내용을 확인한다.

D:\springframework_prj\logs폴더의 log파일을 확인.



336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

1) src/main/webapp/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"

         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

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

         id="WebApp_ID" version="2.5">


    <display-name>FrameWork</display-name>

    

   <!--

- Location of the XML file that defines the root application context.

- Applied by ContextLoaderListener.

-->

    <context-param>

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

        <param-value>classpath:spring/applicationcontext.xml</param-value>

    </context-param>


    <listener>

        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>

    

    

    <!--

- Servlet that dispatches request to registered handlers (Controller implementations).

-->

    <servlet>

        <servlet-name>dispatcherServlet</servlet-name>

        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <init-param>

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

            <param-value>/WEB-INF/mvc-config.xml</param-value>

        </init-param>

        <load-on-startup>1</load-on-startup>

    </servlet>

    <servlet-mapping>

        <servlet-name>dispatcherServlet</servlet-name>

        <url-pattern>/</url-pattern>

    </servlet-mapping>

</web-app>

2) dispatcherServlet에서 설정한 mvc-config.xml파일을 설정한다.



src/main/java에 com.my.framework.common.controller 패키지를 추가하고 "<context:component-scan base-package="com.my.framework.common.controller"/>" controller 스캔 설정을 한다.

그리고 view에 해당하는 jsp 폴더를 추가하고 

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

       <property name="prefix" value="/jsp/"/>

       <property name="suffix" value=".jsp"/>

</bean>

<mvc:annotation-driven />


3) applicationcontext.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"

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

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

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

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/tx

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

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

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

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

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

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

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

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

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


</beans> 

4) sample 프로그램 작성 및 확인 하기

4-1) sample.jsp 파일 작성.

  src/java/webapp/jsp/sample.jsp 파일을 작성

4.2) Controller 작성

com.myframework.common.controller.SampleController의 내용

package com.my.framework.common.controller;

import java.util.Map;


import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


import org.springframework.stereotype.Controller;

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

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

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

import org.springframework.web.servlet.ModelAndView;


@Controller

public class SampleController {


public SampleController(){}

@RequestMapping(value="/jsp/sample",method=RequestMethod.GET, produces ="text/html;charset=UTF-8")

public ModelAndView viewCode(@RequestParam Map<String,String> params, HttpServletRequest request ,HttpServletResponse response)

{

ModelAndView modelAndView = new ModelAndView();

modelAndView.setViewName("/jsp/sample");

return modelAndView;

}

}

5) tomcat Server 실행.


    실행히 위와 같이 에러가 난다면 Proejct에서 오른쪽마우스 클릭 Properties를 실행 

5-1) Deployment Assembly 실행 



6) sample 호출.



'0.SpringFrameWork > 1.환경설정하기' 카테고리의 다른 글

eclipse에서 tomcat Server 실행하기  (0) 2016.02.26

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

1)  File >> new Project를 선택하고 창이 열리면 아래와 같이 Maven Project를 선택한다.

2) 저장위치를 선택

3) maven proejct의 종류를 선택한다. 여기서는 web 프로젝트이므로 maven-archetype-webapp를 선택 함.

4) 프로젝트의 기본정보를 입력함.

  Group Id : 프로젝트의 식별 문자열

Artifact Id: 하위 프로젝트 구분을 입력(프로젝트명)


5) 생성이 완료된 프로젝트 모습

java/main/resources => logback.xml,properties 파일들이 위치함

java/main/webapp => web ROOT 폴더


6) 프로젝트의 pom.xml파일을 열어 추가한다.

7) 추가가 완료되면 프로젝트 >오른쪽 마우스 클릭 > Maven > Update Project.. 를 선택하여 jar파일 업데이트를 진행한다.

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

  <modelVersion>4.0.0</modelVersion>


  <groupId>com.my</groupId>

  <artifactId>FrameWork</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  <packaging>jar</packaging>


  <name>FrameWork</name>

  <url>http://maven.apache.org</url>

  <properties>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

  </properties>

<build>

   <plugins>

       <plugin>

       <groupId>org.apache.maven.plugins</groupId>

       <artifactId>maven-compiler-plugin</artifactId>

       <version>3.1</version>

       <configuration>

           <source>1.7</source>

           <target>1.7</target>

       </configuration>

   </plugin>

   </plugins>

</build>

  <dependencies>

    <dependency>

      <groupId>junit</groupId>

      <artifactId>junit</artifactId>

      <version>3.8.1</version>

      <scope>test</scope>

    </dependency>

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>servlet-api</artifactId>

<version>2.5</version>

</dependency>

<dependency>

<groupId>javax.servlet.jsp</groupId>

<artifactId>jsp-api</artifactId>

<version>2.2</version>

</dependency>


<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-aop</artifactId>

<version>4.2.4.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-beans</artifactId>

<version>4.2.4.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-context</artifactId>

<version>4.2.4.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-core</artifactId>

<version>4.2.4.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-expression</artifactId>

<version>4.2.4.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-web</artifactId>

<version>4.2.4.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-webmvc</artifactId>

<version>4.2.4.RELEASE</version>

</dependency>

  </dependencies>

</project>