hyeonga_code

Spring_AOP 심화 실습_ 1. 기본 설정 본문

Spring

Spring_AOP 심화 실습_ 1. 기본 설정

hyeonga 2024. 1. 8. 07:59
반응형


- Spring AOP 심화

- 일반 프로젝트와의 차이
    - web 프로젝트인 경우 src/main/webapp 폴더가 있습니다.

- 새로운 Maven Project 생성하기
- new > Maven > Maven Project
    > next > next
    - Select an Archetype
        - 버전에 따라 목록이 보여지지 않는 경우가 있습니다.
        - Catalog : Internal
            - maven-archetype-quickstart 1.1 선택
            > next
    
    - Group id : sts.spring
    - Artifact Id : SpringAOP
    - Package : sts.spring.aop
    > Finish

    >>> SpringAOP 메이븐 프로젝트가 생성됩니다.
        - 프로젝트에 오류가 발생할 수 있습니다. (jdk 연결 안되있는 경우)

    >>> 프로젝트 설정을 수정합니다.
    - 프로젝트 우클릭 > Properties > Project Facets
        - java 11
        - runtime : jdk 체크합니다.
        > Apply and Close


- 필수 라이브러리 추가하기 'pom.xml'
- 메이븐 프로젝트 생성 시 기본으로 생성되는  pom.xml
=====

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<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>sts.spring</groupId>
      <artifactId>AOPSpring</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
 
    <name>AOPSpring</name>
     <url>http://maven.apache.org</url>
 
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
 
      <dependencies>
          <dependency>
              <groupId>junit</groupId>
              <artifactId>junit</artifactId>
              <version>3.8.1</version>
              <scope>test</scope>
        </dependency>
      </dependencies>
    
</project>
 


- spring-context 라이브러리 추가 
            - 스프링 코어 라이브러리 중 하나입니다.
            - 애플리케이션 컨텍스트를 구성하는 데 필요한 빈 팩토리, 빈의 정의, 빈 스코프 등의 기능을 제공합니다.
    - maven  : spring-context 'https://mvnrepository.com/artifact/org.springframework/spring-context'
        - ioc DI 사용시 필요합니다.
        > 5.3.27 버전의 maven 코드를 복사합니다.
                     'https://mvnrepository.com/artifact/org.springframework/spring-context/5.3.27'
'''
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>5.3.27</version>
</dependency>
'''

- 로그 관련 라이브러리 추가
    - apache commons logging 1.2 복사하기
                       'https://mvnrepository.com/artifact/commons-logging/commons-logging/1.2'
'''
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.2</version>
</dependency>
'''


--- AOP 를 사용하기 위해 필요한 라이브러리입니다.
    - 'https://mvnrepository.com/artifact/org.aspectj/aspectjrt/1.9.19'
'''
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjrt -->
<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjrt</artifactId>
    <version>1.9.19</version>
    <scope>runtime</scope> // 삭제합니다.
</dependency>
'''

    - 'https://mvnrepository.com/artifact/org.aspectj/aspectjweaver/1.9.19'
'''
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.9.19</version>
    <scope>runtime</scope> // 삭제합니다.

</dependency>
'''

- 빌드 플러그인 설정 
            - 컴파일러 플러그인입니다.
            - 자바 소스코드를 컴파일하고 클래스 파일을 생성하는 데에 사용됩니다.
            - 소스,타겟 버전을 11로 설정했습니다.
            - 인코딩을 UTF-8로 진행합니다.
-  Apache Maven Compiler Plugin 3.11.0
             - 'https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin'
'''
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<dependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.11.0</version>
</dependency>
'''

 - build 태그에 내용을 추가합니다.
>>>
      <build>
            <plugins>
                  <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-compiler-plugin</artifactId>
                      <version>3.11.0</version>
                      <configuration>
                            <source>11</source>
                            <target>11</target>
                            <encoding>UTF-8</encoding>
                      </configuration>
                  </plugin>
            </plugins>
      </build>

'pom.xml'
=====

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<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>sts.spring</groupId>
      <artifactId>AOPSpring</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
 
    <name>AOPSpring</name>
     <url>http://maven.apache.org</url>
 
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
 
      <dependencies>
  
<!-- spring-context 라이브러리 추가 
        - 스프링 코어 라이브러리 중 하나입니다.
        - 애플리케이션 컨텍스트를 구성하는 데 필요한 빈 팩토리, 빈의 정의, 빈 스코프 등의 기능을 제공합니다.
-->
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.3.27</version>
        </dependency>
 
<!-- 로그 관련 라이브러리 추가 -->  
        <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
 
<!-- AOP 관련 의존 관계 추가 -->
        <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.9.19</version>
          
        </dependency>
        
        <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjrt -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.9.19</version>
           
        </dependency>
 
 
        <dependency>
              <groupId>junit</groupId>
              <artifactId>junit</artifactId>
              <version>3.8.1</version>
              <scope>test</scope>
        </dependency>
      </dependencies>
      
<!-- 빌드 플러그인 설정 
        - 컴파일러 플러그인입니다.
        - 자바 소스코드를 컴파일하고 클래스 파일을 생성하는 데에 사용됩니다.
        - 소스,타겟 버전을 11로 설정했습니다.
        - 인코딩을 UTF-8로 진행합니다.
-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
</project>
 





- src/main/java 폴더 내에 기본으로 생성된 모든 패키지와 클래스를 삭제합니다.
- src/text/java 폴더 내에 기본으로 생성된 모든 패키지와 클래스를 삭제합니다.




>>>> 메이븐 프로젝트를 시작할 기본 설정을 모두 마쳤습니다.

반응형