Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 리눅스
- sql
- 참조타입
- ospf
- javaee
- Java
- 오라클
- Cisco
- jsp
- php
- ciscopacket
- html
- VLAN
- 네트워크관리사
- rinux
- cisco packet
- 원형그래프
- jsp연결
- 이것이 자바다
- Oracle
- 자바
- 네트워크
- NCS
- 정보처리기사
- autoset
- 데이터베이스
- w3school
- 버추얼머신
- 정처기필기
- 라우터
Archives
- Today
- Total
기록해! 정리해!
어노테이션 기반 설정 본문
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="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">
<context:component-scan base-package="polymorphism" />
</beans>
package polymorphism;
import org.springframework.stereotype.Component;
@Component("apple")
public class AppleSpeaker implements Speaker {
AppleSpeaker(){
System.out.println("AppleSpeaker 생성자 ");
}
@Override
public void volumeUp() {
System.out.println("==> AppleSpeaker volumeUp ");
}
@Override
public void volumeDown() {
System.out.println("==> AppleSpeaker volumeDown ");
}
}
package polymorphism;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
@Component("SamSungTV")
public class SamSungTV implements TV{
@Autowired
@Qualifier("apple")
private Speaker speaker;
private int price = 0;
SamSungTV(){
System.out.println("SamSungTV 생성자");
}
SamSungTV( Speaker speaker ){
System.out.println("SamSungTV 생성자(1)");
this.speaker = speaker;
}
SamSungTV( Speaker speaker, int price ){
System.out.println("SamSungTV 생성자(2)");
this.speaker = speaker;
this.price = price ;
}
public void setSpeaker(Speaker speaker) {
System.out.println("setSpeaker()호출");
this.speaker = speaker;
}
public void setPrice(int price) {
System.out.println("setPrice()호출");
this.price = price;
}
@Override
public void powerOn() {
System.out.println("==>SamSungTV powerOn");
System.out.println("==>가격 : " + price );
}
@Override
public void powerOff() {
System.out.println("==>SamSungTV powerOff");
}
@Override
public void volumeUp() {
// System.out.println("SamSungTV volumeUp");
speaker.volumeUp();
}
@Override
public void volumeDown() {
// System.out.println("SamSungTV volumeDown");
speaker.volumeDown();
}
}
package polymorphism;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
@Component("LgTV")
public class LgTV implements TV{
/*
@Autowired
@Qualifier("sony")
*/
@Resource(name="sony")
private Speaker speaker;
private int price =0;
LgTV(){
System.out.println("LgTV 생성자");
}
LgTV( Speaker speaker ){
System.out.println("LgTV 생성자(1)");
this.speaker = speaker;
}
LgTV( Speaker speaker, int price ){
System.out.println("LgTV 생성자(1)");
this.speaker = speaker;
this.price = price;
}
public void setSpeaker(Speaker speaker) {
this.speaker = speaker;
System.out.println("setSpeaker 호출");
}
public void setPrice(int price) {
this.price = price;
System.out.println("setPrice 호출");
}
@Override
public void powerOn() {
System.out.println("==>LgTV powerOn");
}
@Override
public void powerOff() {
System.out.println("==>LgTV powerOff");
}
@Override
public void volumeUp() {
// System.out.println("LgTV volumeUp");
speaker.volumeUp();
}
@Override
public void volumeDown() {
// System.out.println("LgTV volumeDown");
speaker.volumeDown();
}
}
'Spring' 카테고리의 다른 글
비즈니스 컴포넌트 실습 1 - table과 vo (0) | 2022.09.20 |
---|---|
어노테이션과 XML 설정 병행하여 사용하기 (0) | 2022.09.20 |
Setter 사용하기 (2) - p 네임스페이스 사용하기 (0) | 2022.09.20 |
Setter 사용하기 (1) (0) | 2022.09.20 |
Spring - 서블릿 클래스 확인 (0) | 2022.09.20 |
Comments