프로젝트 생성 & 환경 설정
만약 Spring MVC Project가 없을 경우에 워크스페이스에
.metadata\.plugins\org.springsource.ide.eclipse.commons.content.core
해당 파일을 넣을 것
Next로 가서 패키지 이름 생성 해줄것 (kr.or.ddit)
라이브러리 설정 - JAVA
라이브러리 설정 - 서버
서버 설정
톰캣 설정 후
Project Facets 설정
속도 빠르게하는법
pom.xml 변경
pom.xml
메이븐(maven)은 프로젝트를 생성하고 라이브러리를 관리하고 빌드하는 것까지 프로젝트의
라이프 사이클을 관리하는 소프트웨어.
즉, 자동으로 라이브러리를 사용할 수 있게 해줌
java버전과 스프링프레임워크 버전 변경
<java-version>1.8</java-version>
<org.springframework-version>5.2.5.RELEASE</org.springframework-version>
더보기
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<!--
pom.xml
메이븐(maven)은 프로젝트를 생성하고 라이브러리를 관리하고 빌드하는 것까지 프로젝트의
라이프 사이클을 관리하는 소프트웨어.
즉, 자동으로 라이브러리를 사용할 수 있게 해줌
-->
<modelVersion>4.0.0</modelVersion>
<groupId>kr.or</groupId>
<artifactId>ddit</artifactId>
<name>springProj</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>1.8</java-version>
<org.springframework-version>5.2.5.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
</properties>
<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>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-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>
<!-- @Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.test.int1.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
pom.xml이 수정되면 Maven빌드를 통해 변경된 Maven 내용을 프로젝트에 반영해야 함
해당 console이 뜨면 정상적으로 pom.xml이 업데이트된 것을 확인할 수 있다
web.xml설정 (프로젝트) - 버전 변경+필터 추가
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="4.0" 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 https://java.sun.com/xml/ns/javaee/web-app_4_0.xsd">
<!-- 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>
<!-- 한글 처리
웹 브라우저(크롬)에서 서버(톰캣)로 보내는 요청(Requeset)과 그 반대 방향인 응답(Response)을
모두 UTF-8로 고정하기 위해 인코딩 필터를 설정함
-->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<!-- 모든 요청에서 -->
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
log4j - main 설명
(ctrl+shift+R 을 통한 검색)
appender : 전달된 로그를 어디에 출력할지 결정(콘솔, 파일 기록, DB 저장)
priority : 로그 레벨
- fatal : 심각한 오류 발생
- error : 요청 처리 중 문제 발생
- warn : 프로그램 실행에는 문제가 없으나 오류 발생 경고
- info : 상태변경 등 정보성 메시지
- debug : 개발 시 디버깅 용도*
- trace : 상세한 이벤트 용도
해당 root에서 변경이 가능
<root>
<priority value="warn" />
<appender-ref ref="console" />
</root>
new 설정 변경 (shortcut설정)
'Spring' 카테고리의 다른 글
[Spring] lprod CRUD (0) | 2024.07.22 |
---|---|
[Spring] 애노테이션 Annotation (0) | 2024.07.22 |
[Spring] 도서 관리 CRUD (2) | 2024.07.19 |
[Spring] Spring MVC (0) | 2024.07.19 |
[Spring] OT (1) | 2024.07.18 |