반응형
NOOWGNAJ
Run To IT
NOOWGNAJ
전체 방문자
오늘
어제
  • 분류 전체보기 (163)
    • Flutter (3)
    • Back (77)
      • JAVA (13)
      • JAVA 응용문제 (8)
      • JSP (16)
      • Spring (5)
      • Python (26)
      • nexacro (3)
      • jstl (6)
    • Database (8)
      • MySQL (6)
      • MSSQL (2)
    • Front (44)
      • HTML (34)
      • CSS (0)
      • JavaScript (5)
      • Vue.js (5)
    • 코딩테스트 (4)
      • SQL (3)
      • JS (1)
    • MUSIC (1)
      • 장운박스 (1)
    • 임시 메모장 (21)
      • 메모장1 (21)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 주민번호정규식
  • 이메일정규식
  • 정규식모음
  • 정규식
  • 자바스크립트
  • regex
  • 핸드폰번호정규식
  • 자바스크립트정규식

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
NOOWGNAJ

Run To IT

Back/Spring

Spring AOP1

2022. 9. 14. 13:15
반응형
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="
	   http://www.springframework.org/schema/mvc
	   http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
	   http://www.springframework.org/schema/beans 
	   http://www.springframework.org/schema/beans/spring-beans.xsd
	   http://www.springframework.org/schema/context 
	   http://www.springframework.org/schema/context/spring-context-4.3.xsd
   ">
	<!-- singleton : 객체의 인스턴스가 오직 1개만 생성되는 패턴 -->

	<bean id="test1" class="aop.aop_class5"></bean>
	<bean id="test2" class="aop.aop_class5"></bean>


</beans>

bean

 

package aop;

public class aop_class5 {

}

aop_class5

package aop;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class aop5 {
	ApplicationContext ac = new ClassPathXmlApplicationContext("bean3.xml");

	@RequestMapping("/aop5.do")
	public void aop5_method() {

		/* 계속 새로 만들어짐 */
		aop_class5 ac5 = new aop_class5();
		System.out.println(ac5);

		aop_class5 ac5_1 = new aop_class5();
		System.out.println(ac5_1);
		// -------------------------------------------------------
		
		/* bean id 같으면 같음(같은 class라고해도 id가 다르면 다름) */
		// test1 이라는 객체가 메모리에 등재
		aop_class5 a = ac.getBean("test1", aop_class5.class);
		// test2 이라는 객체가 메모리에 등재
		aop_class5 b = ac.getBean("test2", aop_class5.class);
		// test1 이라는 객체를 메모리에서 로드
		aop_class5 c = ac.getBean("test1", aop_class5.class);

		
		if(a == c) {
			System.out.println("a 와 c에 있는 인스턴스는 같습니다.");
		}
		
		if (a != b) {
			System.out.println("b의 인스턴스는 새로운 주소값 입니다. (a 와 b에 있는 인스턴스는 같지 않습니다.)");
		}
		else {
			System.out.println("a 와 b에 있는 인스턴스는 같습니다.");
		}
	}
}

aop5

반응형
저작자표시 (새창열림)

'Back > Spring' 카테고리의 다른 글

Spring  (0) 2022.10.13
Spring AOP3  (0) 2022.09.15
Spring AOP2  (0) 2022.09.14
Spring  (0) 2022.08.30
    'Back/Spring' 카테고리의 다른 글
    • Spring
    • Spring AOP3
    • Spring AOP2
    • Spring
    NOOWGNAJ
    NOOWGNAJ
    Innovation. Development. Evolution. Passion. Smart. Teamwork.

    티스토리툴바