分享

@Service注解使用

 木有银 2010-05-12
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www./schema/beans" xmlns:xsi="http://www./2001/XMLSchema-instance" xmlns:context="http://www./schema/context" xsi:schemaLocation="http://www./schema/beans   http://www./schema/beans/spring-beans-2.5.xsd   http://www./schema/context   http://www./schema/context/spring-context-2.5.xsd">
 <context:component-scan base-package=”com.eric.spring”>
</beans>
其中base-package为需要扫描的包(含所有子包),多个包可以用逗号分隔。@Service用于标注业务层组件,@Controller用于标注控制层组件(如struts中的action),@Repository用于标注数据访问组件,即DAO组件,而@Component泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注。
@Service
public class VentorServiceImpl implements iVentorService {
}
@Repository public class VentorDaoImpl implements iVentorDao {
}
getBean的默认名称是类名(头字母小写),如果想自定义,可以@Service(“aaaaa”)这样来指定,
这种bean默认是单例的,如果想改变,可以使用@Service(“beanName”) @Scope(“prototype”)来改变。
可以使用以下方式指定初始化方法和销毁方法(方法名任意):
@PostConstruct
public void init() {
}
@PreDestroy
public void destory() {
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多