@Service注解的使用

@Service注解的使用

首先,在applicationContext.xml文件中加一行:

加上这一行以后,将自动扫描路径下面的包,如果一个类带了@Service注解,将自动注册到Spring容器,不需要再在applicationContext.xml文件定义bean了,类似的还包括@Component、@Repository、@Controller。
比如下面这个类:

@Service("courseDAO")
@Scope("prototype")
public class CourseDAOImpl extends HibernateDaoSupport implements CourseDAO{ ...... }

其作用就相当于applicationContext.xml文件里面的:

你可能感兴趣的:(@Service注解的使用)