zoukankan      html  css  js  c++  java
  • spring简介以及快速使用

    spring框架是一个管理对象的创建、依赖以及销毁和事务管理的容器。spring主要是IOC(Inversion of Control)控制反转和AOP(Aspect Oriented Programming)面向切面编程。

    怎么使用:

    1.导入jar包(日志:commons-loggings,springjar包:beans,context,core,expression)

     

    2.配置spring配置文件

    <?xml version="1.0" encoding="UTF-8"?>

    <beans xmlns="http://www.springframework.org/schema/beans"

           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

           <!--

                  bean:管理的类

                  class:类的全类名

                  id:调用类的标识

            -->

           <bean id="mysql" class="com.zhiyou100.kfs.dao.MysqlDao"></bean>

           <bean id="oracle" class="com.zhiyou100.kfs.dao.OracleDao"></bean>

           <bean id="userService" class="com.zhiyou100.kfs.service.UserService">

                  <!--

                         property:调用set方法赋值

                         value:String类,基本类型以及基本类型包装类使用

                         ref:自定义类使用

                   -->

                  <property name="dao" ref="mysql"></property>

           </bean>

    </beans>

    测试:

           public static void main(String[] args) {

                  //引入spring配置文件

                  ApplicationContext app=new ClassPathXmlApplicationContext("applicationContext.xml");

                  //通过getBean方法从spring容器获取UserService对象

                  UserService us = (UserService)app.getBean("userService");

                  us.show();

           }

  • 相关阅读:
    NOI2014题解
    BZOJ 3514 (动态树)
    [HNOI 2013] 旅行 (数学)
    [HNOI 2013] 消毒 (搜索,二分图匹配)
    大学的第一个自己的程序
    回归了
    OI——不后悔的两年
    对于民科吧s5_or吧友自增树的复杂度计算
    好久没有冒过泡了。。。
    非常无聊——STD::sort VS 基数排序
  • 原文地址:https://www.cnblogs.com/kfsrex/p/11494600.html
Copyright © 2011-2022 走看看