spring and Quick Introduction

spring is to create a framework for object management, transaction management and dependence and destruction of container. The main spring is IOC (Inversion of Control) control inversion and AOP (Aspect Oriented Programming) Oriented Programming.

how to use:

1. Import jar package (log: commons-loggings, springjar package: beans, context, core, expression)

 

 

 

2. Configure the spring configuration file

<?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: Management class

              class: class full class name

              Identifies the calling 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: call set method assignment

                     value: String class, primitive or primitive type wrapper classes use

                     ref: using custom classes

               -->

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

       </bean>

</beans>

test:

       public static void main(String[] args) {

              // imports spring configuration file

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

              // Get UserService object from the container through the spring getBean method

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

              us.show();

       }

Guess you like

Origin www.cnblogs.com/kfsrex/p/11494600.html