zoukankan      html  css  js  c++  java
  • (一)问候Spring4

    第一节:Spring 简介

    Spring 作者:Rod Johnson;

    官方网站:http://spring.io/

    最新开发包及文档下载地址:http://repo.springsource.org/libs-release-local/org/springframework/spring/

    核心思想:IOC 控制反转;AOP 面向切面;(这是学习spring的两个重点中的重点)

    介绍:百度百科;

    第二节:Spring4 版Hello World 实现

     核心jar包:

    百度云下载:http://pan.baidu.com/s/1jIEphqQ

    密码:3xb3

    beans.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">
    
    
      
    </beans>

    例子:

    首先我们必须先导入相对应spring的jar包

    beans.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">
    
        <bean id="helloWorld" class="com.wishwzp.test.HelloWorld"></bean>
    
      
    </beans>

    HelloWorld.java

    package com.wishwzp.test;
    
    public class HelloWorld {
    
        public void say(){
            System.out.println("Spring4你好!");
        }
    }

    Test.java

    package com.wishwzp.service;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    import com.wishwzp.test.HelloWorld;
    
    public class Test {
    
        public static void main(String[] args) {
            ApplicationContext ac=new ClassPathXmlApplicationContext("beans.xml");
            HelloWorld helloWorld=(HelloWorld)ac.getBean("helloWorld");
            helloWorld.say();
        }
    }

    说明:beans.xml文件在src目录下面,以为使用的是ClassPathXmlApplicationContext,会根据classpath加载。

    还有一种是FileSystemXmlApplicationContext,根据文件绝对路径去查找

    运行结果显示:

  • 相关阅读:
    pandas常用操作
    python读取文件并写入内容到文件
    《软件工程》学习进度博客13
    01梦断代码读后感1—上帝游戏
    软件工程学习进度博客12
    《软件工程》个人作业5----单词统计
    用户模板和用户场景
    软件工程学习进度博客11
    PHP学习3:简单的流程控制
    《软件工程》个人作业6---找水王
  • 原文地址:https://www.cnblogs.com/wishwzp/p/5491613.html
Copyright © 2011-2022 走看看