码迷,mamicode.com
首页 > 编程语言 > 详细

(一)问候Spring4

时间:2016-05-19 23:22:54      阅读:299      评论:0      收藏:0      [点我收藏+]

标签:

 

第一节: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();
    }
}

 

运行结果显示:

技术分享

 

(一)问候Spring4

标签:

原文地址:http://www.cnblogs.com/wishwzp/p/5491613.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!