스프링 준비

2024. 2. 5. 18:10Daily Codig Reminder

sts 기본 설정

  1. general - workspace - 한글설정
  2. css/jsp/html 한글설정
  3. jre jdk11
  4. 기본 브라우저 chrome
  5. 스프링 import 후 ⇒ pom파일을 읽고 다운로드 pom파일

maven update : alt+ f5

build path 확인

classpath 확인 하기!!!!!!!!!!!!!!

xml bean 에 id 찾기 ❗❗

no search bean 이면 id 가 틀린 것❗❗

똑같은 아이디 두 개 를 bean 에 넣지 말 것 ❗❗

 

xml에 id 부여하기

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="com.spring.Person" id="xxx"></bean>

</beans>

Person.java

package com.spring;

public class Person {
String name ="홍길동";
	public Person() {
		super();
		System.out.println("person 셍성자 호출");
	}
public String getName() {
	return this.name;
}
}

 

기존방식

import com.spring.Person;

public class main {

	public static void main(String[] args) {
		Person p = new Person();
		String name = p.getName();
		System.out.println(name);
		
		
	}

}

getBean 에 Person.class

public class main2 {

	public static void main(String[] args) {
		System.out.println("2.xml에서 빈 생성 , 생성 빈 사용 방법=========");
		ApplicationContext ctx = new
				GenericXmlApplicationContext("classpath:configuration.xml");
		Person p1 = ctx.getBean("xxx", Person.class);
		System.out.println(p1);
		System.out.println(p1.getName());
		System.out.println("==============");
		
		
	}

}

getBean 의 id 만 하면 앞에 (Person) 붙이기

public class main3 {

	public static void main(String[] args) {
		System.out.println("2.xml에서 빈 생성 , 생성 빈 사용 방법=========");
		ApplicationContext ctx = new
				GenericXmlApplicationContext("classpath:configuration.xml");
		Person p3 =
				(Person)ctx.getBean("xxx");
		System.out.println(p3);
		
		
	}

}

'Daily Codig Reminder' 카테고리의 다른 글

props, autowired  (1) 2024.02.07
spring - property  (1) 2024.02.06
cors  (0) 2024.01.15
json , ajax  (1) 2024.01.15
jquery:CSS  (0) 2024.01.13