首页 > 编程语言 > 详细

Spring In Action-2.1-01-@Component注解

时间:2017-08-29 22:39:03      阅读:233      评论:0      收藏:0      [点我收藏+]

//@Component注解会告诉Spring创建这个类的实例bean(注意,启动Component注解功能需要在xml里面配置,下面会将)
@Component

package com.zte.springinaction.soundsystem.imp;

import org.springframework.stereotype.Component;

import com.zte.springinaction.soundsystem.CompactDisc;

//@Component注解会告诉Spring创建这个类的实例bean(注意,启动Component注解功能需要在xml里面配置)
@Component
public class SgtPeppers implements CompactDisc {

	private String title="Pepper‘s Lonely";
	private String artist="The beatles";
	
	public void play() {
		System.out.println("Sgt Playing:title="+title+" artist="+artist);
	}

}

  

扫描有两种方式:

一、java代码方式:

package com.zte.springinaction.soundsystem;

import org.springframework.context.annotation.ComponentScan;

//ComponentScan:本类所在包的所有子包都会被扫描,并自动为其创建bean
@ComponentScan
public class CDPlayerSpringConfig {

}

  

二、xml配置方式:

<context:component-scan base-package="soundsystem" />

  

Spring In Action-2.1-01-@Component注解

原文:http://www.cnblogs.com/zjsy/p/7450537.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!