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

           }

  • 相关阅读:
    质量标准
    期权只是一张纸而已,但它的背后是心机
    Spring注解 @Resource和@Autowired
    Java7新语法 -try-with-resources
    Spring中Bean的命名问题及ref和idref之间的区别
    mybatis注解详解
    jquery ajax局部加载方法介绍
    SpringMVC批量上传
    【uploadify3.1使用二】批量文件、图片上传
    IE浏览器上传文件时本地路径变成”C:fakepath”的问题
  • 原文地址:https://www.cnblogs.com/kfsrex/p/11494600.html
Copyright © 2011-2022 走看看