zoukankan      html  css  js  c++  java
  • spring开篇

     Spring 开篇

    Data access结构体系图

    Spring的第一个案例

    1.引依赖  jar

    beans自动引入core

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

     

    Context 自动引入AOPexpression

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

    2.创建一个类

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

    3.applicationContext配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beansxmlns="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 id="happyService" class="cn.happy.Service.HappyService">

    //id可以是任何值     class: 全路径
      <property name="info" value="Spring"></property>

     

    4.测试类

     @Test
    public void  test01(){

    //如何获取到spring容器

    ApplicationContex ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

    HappyService service  =(HappyService)ctx.getBean("happyService");

    service.setInfo("Spring");

    service.work();  }

      编译结果:

  • 相关阅读:
    [置顶] 新修改ADB,支持Android 4.2 系统 ,全部中文命令,手机屏幕截图等等
    归并排序
    Sciter/HTMLayout内存占用评测
    ASP.NET面试题总结
    uva 1356 Bridge ( 辛普森积分 )
    在没备份undo的情况下,undo丢失,重启数据库报ORA-01157错误
    以天徒龙记
    struts-config.xml 文件:
    struts.xml文件:
    web.xml文件:
  • 原文地址:https://www.cnblogs.com/wangdan123/p/7398806.html
Copyright © 2011-2022 走看看