@component、@RestController

 

@RestController

远程调用接口spring

一、@controller 控制器(注入服务)

  • 用于标注控制层,至关于struts中的action层

二、@service 服务(注入dao)

  • 用于标注服务层,主要用来进行业务的逻辑处理

三、@repository(实现dao访问)

  • 用于标注数据访问层,也能够说用于标注数据访问组件,即DAO组件.

四、@component (把普通pojo实例化到spring容器中,至关于配置文件中的 
<bean id="" class=""/>

      • 泛指各类组件,就是说当咱们的类不属于各类归类的时候(不属于@Controller、@Services等的时候),咱们就能够使用@Component来标注这个类

        下面写这个是引入component的扫描组件 spa

        1prototype

        <context:component-scan base-package=”com.mmnc”>

         其中base-package为须要扫描的包(含全部子包) code

               一、@Service用于标注业务层组件 
               二、@Controller用于标注控制层组件(如struts中的action) 
               三、@Repository用于标注数据访问组件,即DAO组件. 
               四、@Component泛指组件,当组件很差归类的时候,咱们能够使用这个注解进行标注。    
                     @Service public class UserServiceImpl implements UserService { }      component

                    @Repository public class UserDaoImpl implements UserDao { } getBean的默认名称是类名(头字母小写),若是想自定义,能够@Service(“***”)               这样来指定,这种bean默认是单例的,若是想改变,能够使用@Service(“beanName”) 接口

                   @Scope(“prototype”)来改变。能够使用如下方式指定初始化方法和销毁方法(方法名任意): @PostConstruct public void init() { }ci

相关文章
相关标签/搜索