헤르메스 LIFE

[Spring] 개발환경 구축 - Logback 본문

Spring Framework

[Spring] 개발환경 구축 - Logback

헤르메스의날개 2022. 12. 21. 01:31
728x90

SimpleSpring4.zip
0.02MB

Spring 개발환경을 갑자기 구축하려고 하다보니, 막막합니다.

하나 하나 구축해 보겠습니다


개발환경

Spring 4.3.30.RELEASE

MAVEN 3.8.4

Logback 1.2.9


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>SimpleSpring4</groupId>
    <artifactId>SimpleSpring4</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>SimpleSpring4</name>
    <description>Simple Spring4</description>

    <properties>
        <springframework.version>4.3.30.RELEASE</springframework.version>

        <org.slf4j-version>1.7.30</org.slf4j-version><!-- 1.7.26 -->
        <ch.qos.logback-version>1.2.9</ch.qos.logback-version>
    </properties>

    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${springframework.version}</version>
        </dependency>

        <!-- slf4j -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <!-- Bridge -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>log4j-over-slf4j</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jul-to-slf4j</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.25</version>
        </dependency>
        <!-- logback -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${ch.qos.logback-version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId><!-- logback을 slf4j-api에서 사용함을 의미 -->
                </exclusion>
            </exclusions>
            <scope>runtime</scope><!-- runtime 시 사용함 -->
        </dependency>

        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.3</version>
            </plugin>
        </plugins>
    </build>
</project>

HelloController.java

package simple.spring.basic;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class HelloController {

    private static Logger logger = LoggerFactory.getLogger( HelloController.class);
    
    @RequestMapping(value = { "/", "/welcome" }, method = RequestMethod.GET)
    public String getHomePage( ModelMap model ) {
        logger.info("[HelloController.getHomePage] 여기가 실행될까..?");
        return "index";
    }

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String hello( Map<String, Object> model ) {
        logger.info("[HelloController.hello] Hello World");
        
        model.put("name", "Spring4 MVC");
        model.put("msg", "Hello World");

        return "hello";
    }
}

https://hermeslog.tistory.com/647

 

[Spring] 개발환경 구축 - Hello World

Spring 개발환경을 갑자기 구축하려고 하다보니, 막막합니다. 하나 하나 구축해 보겠습니다. 개발환경 Spring 4.3.30.RELEASE MAVEN 3.8.4 1. New > Maven Project 2. Use default Workspace Location -> 체크 풀고, 경로를 생

hermeslog.tistory.com

https://hermeslog.tistory.com/448

 

[Spring Boot] SLF4J를 이용한 Log 설정 시 주의점

출처 : 백기선님의 강의 www.youtube.com/watch?v=o2-JaRD9qQE&t=907s&ab_channel=springcamp.io 1. 중요 !!! - SLF4J ( Simple Logging Facade for Java ) 는 Interface 입니다. - Spring Boot 은 기본적으로 JCL ( Jakarta Common Logging ) 을 이

hermeslog.tistory.com

 

728x90