Spring學習

abcbbc發表於2007-05-04
framework tech app ------------------------------------ 事務是一個典型的切面 spring.jar beansfactory applicationcontext
webapplicationcontext
-----------------------------------=-
account user1 = new account
java賦值方法:
建構函式初始值
set
動態位元組碼asm reflect -
-------------------------------------- --------------------
protected ---------------------------------------------
step 1: initialize spring factory or bean factory
step2:[@more@]

package com.test.spring;

import java.sql.Timestamp;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.util.StringUtils;
import org.springframework.web.context.ConfigurableWebApplicationContext;

import com.test.hibernate.Account;

public class AccountTest {

static ApplicationContext context;
static String bizConfigLocations="application-context.xml";

public static void main(String[] args) {
//Step 1: initialize Spring Context (or Factory)
try {
context = new ClassPathXmlApplicationContext(new String[]{bizConfigLocations});
} catch (BeansException bex) {
bex.printStackTrace();
}

Account richard=(Account)context.getBean("richard");
Group grp=(Group)context.getBean("group1");

System.out.println(richard.getName());
System.out.println(grp.getManager().getId());

}

}

package com.test.hibernate;

public class Account {
private Integer id;
private String name;

public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

package com.test.spring;

import com.test.hibernate.Account;

public class Group {
private Account manager;
private String groupName;

public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public Account getManager() {
return manager;
}
public void setManager(Account manager) {
this.manager = manager;
}


}



Beans









來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/219138/viewspace-913304/,如需轉載,請註明出處,否則將追究法律責任。

相關文章