Spring Ioc、Aop學習,springiocaop學習

來源:互聯網
上載者:User

Spring Ioc、Aop學習,springiocaop學習

Ioc:反轉控制

  反轉控制實際上就是將建立對象的許可權從開發人員自己手裡交到了Spring手中

DI:依賴注入 

  依賴注入是實現反轉控制所依賴的手段之一

Ioc:反轉控制

  //這是傳統的建立對象的方式

 User user=new User();

  Spring 建立對象的方式

    1.Xml檔案方式

<bean name="User" class="com.item.bean.User"></bean>

    2.註解方式  @Component 是通用的註解 實際上@Service @Controller @Repository 這三個註解和@Component是一個意思只不過為了分層區分開來才有了這三個註解

@Component
@Service
@Controller
@Repository
public class User {

}

DI:依賴注入

  1.Xmlw檔案配置方式

<bean name="User" class="com.item.bean.User">    </bean>    <bean name="Student" class="com.item.bean.Student">        <property name="user" ref="User"></property> //注入在上面配置的bean user    </bean>

 

  2.註解方式

  @Autowired    private TbItemCatMapper itemCatMapper;

Aop:面向切面編程

  Spring Aop的實現方式實際上分為兩種動態代理和cglib

  動態代理和cglib的區別在於動態代理是需要使用到介面的而cglib是通過繼承的方式實現的。

  我們常見的aop應用還有Filter

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.