• Spring基础


    一.简单案例   打印hello  spring

    1.导包

     <!--beans-->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
                <version>4.2.3.RELEASE</version>
            </dependency>
            <!--context-->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>4.2.2.RELEASE</version>
            </dependency>

    2.创建HappyService类

    public class HappyService {
    
        private String info;
    
        public void work(){
            System.out.println("Hello "+info);
        }
    
        public String getInfo() {
            return info;
        }
    
        public void setInfo(String info) {
            this.info = info;
        }
    }

    3.创建applicationContext.xml文件

    <?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
         
    
        <!--IOC-->
        <bean id="HappyService" class="cn.bdqn.service.HappyService">
            <!--DI依赖注入-->
            <property name="info" value="Spring"></property>
        </bean>
    </beans>

    4.测试类

     @Test
        public void test01(){
            ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
            HappyService service=(HappyService)ac.getBean("HappyService");
            service.work();
        }
  • 相关阅读:
    android SD卡文件的读写
    Android Junit 单元测试步骤
    android xml解析之SAX
    android赚钱 植入有米广告方法
    android广告平台介绍
    读、写其他应用的SharedPreferences
    SQL数据基本操作
    res/raw下的资源文件读写
    容易吗?
    写给实习生的邮件
  • 原文地址:https://www.cnblogs.com/qjt970518--/p/7227479.html
Copyright © 2020-2023  润新知