本文共 2295 字,大约阅读时间需要 7 分钟。
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;}}<?xml version="1.0" encoding="GB2312"?>
ttp://www.springframework.org/dtd/spring-beans-2.0.dtd">http://www.springframework.org/dtd/spring-beans-2.0.dtd"> Beans
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/219138/viewspace-913304/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/219138/viewspace-913304/