Spring——第二章 Spring与IoC(三)

 

cirl + shift + F 格式化代码

 

2.3.6 使用内部Bean注入

	
		
		
		
			
				
			
		
	

2.3.7 同类抽象Bean

  若子Bean有需要公共部分,可以继承这个Bean。



    
       
	
		
		
	

	
		
		
		
		
	
	
		
		
		
		
	
	
		
		
		
		
	
	

2.3.8 异类抽象Bean



    
    
    	        
		
    
    
    
		
		
	
    
    
	
		
		
	
	
	
	

2.3.9 为应用指定多个Spring配置文件

包含关系和平等关系

按照模块来分。

一个文件资源、多个文件资源、一个带通配符的资源

平等关系:

package com.bjpowernode.di13;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MyTest {
	@Test
	public void Test01(){
		/*
		String resource = "com/bjpowernode/di13/spring-base.xml";
		String resource2 = "com/bjpowernode/di13/spring-beans.xml";
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext(resource,resource2);
		*/
		/*
		String resource = "com/bjpowernode/di13/spring-base.xml";
		String resource2 = "com/bjpowernode/di13/spring-beans.xml";
		String[] resources = {resource,resource2};
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext(resources);
		*/
		String resource = "com/bjpowernode/di13/spring-*.xml";
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext(resource);
		Student student = (Student) applicationContext.getBean("myStudent");
		System.out.println(student);
		
		Teacher teacher = (Teacher) applicationContext.getBean("myTeacher");
		System.out.println(teacher);
		
	}
}

包含关系:



        
	
	

 

你可能感兴趣的:(SSM)