spring配置bean的几种方式

11420171026

package com.tiger.main;

import java.util.ArrayList;
import java.util.Collections;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import com.tiger.bean.Book;

/**
 * 替代beans.xml的功能
 * 使用到自动装配
 * @author tiger
 * @time 2017年10月23日
 */
@Configuration
@ComponentScan(basePackages= {"com.tiger"})//
public class AppConfig {
	
	/**
	 * 数据源,相当于beans.xml中,如下
	 * 
	 * 	
	 * 	
	 * 	
	 * 
	 * @return
	 */
	@Bean
	public ArrayList book_list(){
		ArrayList books = new ArrayList<>();
		Book[] bookArr = {new Book("时间简史", "霍金"),
				new Book("人性的弱点", "卡耐基"),
				new Book("编程思想", "Bruce Eckel")};
		Collections.addAll(books, bookArr);
		return books;
	}
}



你可能感兴趣的:(笔记,spring)