zoukankan      html  css  js  c++  java
  • 基于注解的装配方式

    对于依赖注入使用注解方式,将不再需要在Spring配置文件中声明Bean实例,具体方式如下

    修改spring-context.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
        <bean id="springContext" class="com.zck.my.shop.commons.context.SpringContext" />
        <bean id="userService" class="com.zck.my.shop.service.impl.UserServiceImpl" />
    
        <!--开启注解模式-->
        <context:annotation-config />
        <context:component-scan base-package="com.zck.my.shop" />
    </beans>

    注解1:@componentt (该注解的value值为bean的id值)主要用于实例对象

     

    Spring提供3个注解与component效果等效

    @Repository:用于对DAO实现类注解

    @Service:用于对Service实现类注解

    @Controller:用于对Controller实现类进行注解

    @Scope:(用于声明作用域,默认是单例模式)

  • 相关阅读:
    如何处理数集据不平衡的问题
    xgb&lgb&ctb区别
    LDA与gibbs采样
    撸了一个 Feign 增强包
    行为驱动模型-Behave
    MySQL 主从复制常见错误答疑
    POJ 1191
    POJ 1141
    HDU 1754
    POJ 3468
  • 原文地址:https://www.cnblogs.com/2016-zck/p/13300861.html
Copyright © 2011-2022 走看看