亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

若果需要應用作用域怎么辦

若果需要應用作用域怎么辦

正在回答

1 回答

//定義javaBean

import org.springframework.context.annotation.Scope;

import org.springframework.stereotype.Component;

@Component

@Scope("prototype")

public class Person {

private int id;

private String name;

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

}

//測試類

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;


/**

?* Hello world!

?*

?*/

public class App?

{

? ? public static void main( String[] args )

? ? {

? ? ? ? ApplicationContext appContext = new ClassPathXmlApplicationContext("/spring.xml");

? ? ? ? Person p1 = appContext.getBean(Person.class);

? ? ? ? System.out.println("p1's identityHashCode is " + System.identityHashCode(p1));

? ? ? ??

? ? ? ? Person p2 = appContext.getBean(Person.class);

? ? ? ? System.out.println("p2's identityHashCode is " + System.identityHashCode(p2));

? ? ? ??

? ? }

}

@Scope("")類型不同,作用域范圍不同

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

若果需要應用作用域怎么辦

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號