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();

           }

  • 相关阅读:
    bzoj1257 [CQOI2007]余数之和sum
    bzoj1053 [HAOI2007]反素数ant
    bzoj3680 吊打XXX
    CodeVS1344 线型网络
    bzoj1925 [Sdoi2010]地精部落
    2016年北大高代考研题解答
    巴塞尔问题(Basel problem)的多种解法
    积分计算题
    PDF添加水印的办法
    Matlab技巧1:在同一坐标系上绘制两个函数图像
  • 原文地址:https://www.cnblogs.com/kfsrex/p/11494600.html
Copyright © 2011-2022 走看看