2017년 11월 5일 일요일

[Spring] Two ways to implements.

Sample.java

package test01_scope;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component("sss")
@Scope("prototype")
public class Sample {
 //
 }

Test.java

Sample sample1 = context.getBean("sss", Sample.class);

application.xml

<?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"
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.2.xsd">
<bean class="test01_scope.Sample" id="sample1" scope="prototype"/>
<bean class="test01_scope.Sample" id="sample2" scope="singleton"/>

<context:annotation-config/>
<context:component-scan base-package="test01_scope"/>
</beans>

댓글 없음:

댓글 쓰기