프로젝트 세팅전 이해할 주의사항들

Ioc→ 제어의 역전

사용자가 객체를 생성하는 대신 스프링이 객체를 생성 및 관리(생명주기) 해주는 것

Singleton Parrtern + 래퍼런스 변수를 스프링이 관리 해주겠는다 뜻

원인: Heapnew A() 계속 생성이 됨, Heap 또한 계속 생성

해결방안→ 일일이 관리하기 어려우니 스프링이 관리함, 필요할때 객체 생성해 줌

class Test { 

 void hello() {
       A a  = new A();
		 }
}

Component Scan이란? 어떤 패키지안에 있는 폴더를 필요한 걸들을 전부 메모리에 로드 함, 이 부분을 IOC라고 하고 싱글톤으로 스프링 컨테이너에서 관리함.

**ex) com.cos.blog**→ 패키지 이하만 스프링 스캔을 함 , 하지만 맘대로 com.cos.test 생성해서 작업을 하면 스캔을 하지않음

pom.xml 로 실행→ 성공했음

<?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/xsd/maven-4.0.0.xsd>">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>blog1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>blog1</name>
    <description>blog1</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>

<!-- 추가 라이브러리 시작     -->
        <!-- 시큐리티 태그 라이브러리 -->
<!--        <dependency>-->
<!--            <groupId>org.springframework.security</groupId>-->
<!--            <artifactId>spring-security-taglibs</artifactId>-->
<!--        </dependency>-->

        <!-- JSP 템플릿 엔진 -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>

        <!-- JSTL -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
<!-- 추가 라이브러리 끝     -->
 실행시 오류 발생으로 주석처리 
<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-starter-data-jpa</artifactId>-->
<!--        </dependency>-->
   실행시 CORS 설정으로 주석처리 
<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-starter-security</artifactId>-->
<!--        </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>com.mysql</groupId>-->
<!--            <artifactId>mysql-connector-j</artifactId>-->
<!--            <scope>runtime</scope>-->
<!--        </dependency>-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Untitled

Untitled