๊ธด ๋ง ์์ด ๋ฐ๋ก ์ค์ ํด๋ณด์.
Spring MVC Setting
Spring (STS) ๊ตฌ์กฐ์ ๋ง์ถ๊ธฐ
์ข์ธก์ ์ด์ ๊ธ์์ ์๋ฃํ ํ๋ก์ ํธ์ ๋ชจ์ต์ด๊ณ , ์ฐ์ธก์ STS ๊ตฌ์กฐ์ ๋ง์ถ ํ๋ก์ ํธ์ ๋ชจ์ต์ด๋ค.
๋จผ์ 'web' ๋๋ ํ ๋ฆฌ๋ฅผ 'src/main' ๋๋ ํ ๋ฆฌ ํ์๋ก ์ด๋์ํค๊ณ , ์ด๋ฆ์ ๋ณ๊ฒฝํ์.
๋จ์ถํค๋ Shift + F6 / ํ์ผ์ Refactor ํ ๋ ์ฌ์ฉํ๋ ๋จ์ถํค์ด๋ค. ์ธํ ๋ฆฌ์ ์ด ๊ธฐ๋ฐ IDE์ ์ฅ์ ์ค ํ๋๋ก,
'A' ํ์ผ์ Refactor ํ๋ฉด ํด๋น ํ์ผ์ ์ฐธ์กฐํ๋ ๋ชจ๋ ํ์ผ๋ค์ 'A' ์ ๋ช ์นญ์ด Refactorํ ๋ช ์นญ์ผ๋ก ์๋์ผ๋ก ๋ณ๊ฒฝ๋๋ค.
๊ฒฝ๋ก๊ฐ ์ด๋ํ๊ธฐ์ ์๋ฌด๋๋ ํ๋ก์ ํธ์ ์ค์ ๋ํ ๋ณ๊ฒฝํด์ฃผ์ด์ผ ๊ฒ ์ง?
File / Project Structure๋ก ๋ค์ด๊ฐ๋ค.
Modules๋ฅผ ์ ํํ๊ณ ๊ฐ์ด๋ฐ์ Web ์ ํด๋ฆญํ๋ฉด Web Resource Dir ์ด ๋นจ๊ฐ์์ผ๋ก ํ๊ธฐ๊ฐ ๋์ด์๋ค.
๋๋ธํด๋ฆญํ์ฌ ์ฐ๋ฆฌ๊ฐ ์ค์ ํ ๊ฒฝ๋ก๋ก ์ฌ์ค์ ํด์ฃผ์! ์๋ฃ ํ OK !
Spring Context Setting
์ด์ ์ปจํ ์คํธ ํ์ผ์ ๊ด๋ฆฌํ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํด์ผํ๋ค. (STS๊ตฌ์กฐ์ ๋ง์ถ๊ธฐ ์ํด์)
๊ฒฝ๋ก๋ src/main/webapp/WEB-INF ํ์๊ฒฝ๋ก์ ์์ฑํ๋ค.
๋๋ ํ ๋ฆฌ ๋ช ์ spring/appServlet
์ด๋ ๊ฒ ๋ ๊ฐ์ ๋๋ ํ ๋ฆฌ๋ฅผ ๋์์ ์ ์ผ๋ฉด ํ์์ ๋๋ ํ ๋ฆฌ๊น์ง ํ ๋ฒ์ ์์ฑ๋๋ค.
์์ ๊ฐ์ ๋ฐฉ์์ผ๋ก WEB-INF ๋๋ ํ ๋ฆฌ ํ์์ STS ์์ ์ฌ์ฉํ๋ views ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํด์ฃผ๊ณ ,
test ๋๋ ํ ๋ฆฌ์๋ resources ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํด์ค๋ค.
์ ์์ ์ด ์๋ฃ๋๋ฉด ์๋์ ๊ฐ์ ๊ตฌ์กฐ๊ฐ ์์ฑ์ด ๋๋ค.
Context ๋ช ์ ์ฌ์ค ์์ ํ์ง ์์๋ ๋์ง๋ง.. STS ์ ๋๊ฐ์ด ๋ง์ถ๊ธฐ ์ํด์ ๋ง์ฐฌ๊ฐ์ง๋ก ์์ ํด๋ณด์
์์์ ํ๋ Refactor ๊ธฐ๋ฅ์ ์ฌ์ฉํ์ฌ(Shift+F6) ํ์ผ๋ช ์ ๋ณ๊ฒฝํด๋ณด์.
applicationContext.xml → root-context.xml
dispatcher-servlet.xml → servlet-context.xml
์ ์ด๋ ๋ง ๋ง์ง๋ง ๋จ๊ณ์ ๋ค์ด์ฐ๋ค.
์ฒ์๋ถํฐ ์ง๊ธ๊น์ง ๋์ฃ๊ฐ์์๋ context ํ์ผ๋ค์ ์ ๋นจ๊ฐ์ ๋ฐ์ค์ ์์ ๋ ค๊ณ ํ๋ค.
ํด๋ต์ pom.xml์ ์๋ค.
์๋ ๋ด์ฉ์ ๊ทธ๋๋ก ๊ฐ์ ธ๊ฐ์ ๋ถ์ฌ๋ฃ๊ธฐ ํ๊ณ ๋ณธ์ธ์ ํ๋ก์ ํธ groupId์ artifactId๋ฅผ ์ ๋ง์ ๋ง๊ฒ ์์ ํ๋ค.
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.system.api</groupId>
<artifactId>localAPI</artifactId>
<name>localAPI</name>
<packaging>war</packaging>
<version>1.0</version>
<properties>
<java-version>1.8</java-version>
<org.springframework-version>4.2.4.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
<org.apache.tiles-version>3.0.7</org.apache.tiles-version>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</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.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.api-client/google-api-client -->
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.26.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.oauth-client/google-oauth-client -->
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
<version>1.26.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.http-client/google-http-client -->
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.26.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.http-client/google-http-client-jackson2 -->
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-jackson2</artifactId>
<version>1.26.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.0.1-jre</version>
</dependency>
<!-- DB :3๊ฐ -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<!--jackson-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
</dependency>
<!-- maria db -->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.3.0</version>
</dependency>
<!-- JASYPT: Spring 3.1x Simplified Encryption -->
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt-spring31</artifactId>
<version>1.9.2</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>5.0.8.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-web -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.0.8.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-config -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>5.0.8.RELEASE</version>
</dependency>
<!-- tiles: 3๊ฐํ์ผ -->
<!-- https://mvnrepository.com/artifact/org.apache.tiles/tiles-core -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>${org.apache.tiles-version}</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-api</artifactId>
<version>${org.apache.tiles-version}</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>${org.apache.tiles-version}</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>${org.apache.tiles-version}</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-template</artifactId>
<version>${org.apache.tiles-version}</version>
</dependency>
<!-- @Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</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>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</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 Update๋ฅผ ํ๋ฉด ์จ์!! ์ด์ ์ ๋ง ๋!
๋ง๋ฌด๋ฆฌ
์ด๋ ค์ํ์ง๋ง๊ณ ์ฒ์์ ๋จธ๋ฆฌ๋ฅผ ๋น์ด ํ, ๋ฌด์์ ๋ฐ๋ผํด๋ณด๊ณ ๊ถ๊ธํ ์ ์ ๋ฐ๋์ ๊ฒ์ํ๊ธธ ๋ฐ๋๋ค.