关于spring的简介以及说明:开涛的博客对spring的讲解

这里只是spring的使用。 (使用spring4)

一、eclipse安装springsource-tools插件

  • 插件安装方法说明(springsource-tool-suite-3.4.0.RELEASE-e4.3.1-updatesite.zip):

    • 1.Help --> Install New Software...

    • 2.点击 Add...

    • 3.点击, Archive...

    • 4.选择springsource-tool-suite-3.4.0.RELEASE-e4.3.1-updatesite.zip文件,然后点击ok

    • 5.然后选择带有spring IDE的选项。

    • 6.取消勾选右下角的 contact all update sites during...

    • 7.一直点击下一步知道完成。完成之后,会提示重启eclipse (期间最好联网验证一些东西)

  • 插件的好处

    • spring配置文件有提示的功能,且写错的时候,会以报错的方式提示你
    • 被spring创建对象的java文件以及配置文件有s标记

二、新建maven工程,引入spring配置

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

三、添加helloworld类

public class HelloWorld {
private String user; public HelloWorld() {
System.out.println("HelloWorld's constructor...");
} public void setUser(String user) {
System.out.println("setUser:" + user);
this.user = user;
} public HelloWorld(String user) {
this.user = user;
}
public void hello(){
System.out.println("Hello: " + user);
} }

四、使用springsource-tools插件 创建spring配置文件。并使用spring创建helloworld的实例

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"> <!-- 配置一个 bean -->
<bean id="helloWorld" class="com.hp.spring.helloworld.HelloWorld">
<!-- 为属性赋值 -->
<property name="user" value="Jerry"></property>
</bean>
</beans>

五、编写测试类,测试spring创建的helloworld对象

    public static void main(String[] args) {
// 传统的方式,使用new方式创建helloworld对象,并设置tom,然后执行hello方法
// HelloWorld helloWorld = new HelloWorld();
// helloWorld.setUser("Tom");
// helloWorld.hello(); // 使用spring创建helloworld对象
// 1. 创建 Spring 的 IOC 容器
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
// 2. 从 IOC 容器中获取 bean 的实例
HelloWorld helloWorld = (HelloWorld) ctx.getBean("helloWorld");
helloWorld.hello();
}

控制台打印:

HelloWorld's constructor...

setUser:Jerry

Hello: Jerry

整个系列项目代码: http://git.oschina.net/nmc5/spring

spring-helloworld (1)的更多相关文章

  1. 创建一个spring helloworld

    1.下载所需要的jar包 http://projects.spring.io/spring-framework/ 这里使用了maven方式给出jar <dependencies> < ...

  2. Spring配置与第一Spring HelloWorld

    林炳文Evankaka原创作品. 转载请注明出处http://blog.csdn.net/evankaka 本文将主讲了Spring在Eclipse下的配置,并用Spring执行了第一个HelloWo ...

  3. Eclipse安装springsource-tool-suite插件及spring helloworld入门实例

    转载至: https://www.cnblogs.com/aaron-shu/p/5156007.html 一.查看eclipse版本 Help-->About Eclipse,我的版本是4.4 ...

  4. Spring学习笔记2:Spring HelloWorld

    1:IntelliJ新建Maven工程 2:pom文件加入Spring依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" ...

  5. Spring基础02——Spring HelloWorld

    1.首先我们来创建一个HelloWorld类,通过Spring来对这个类进行实例化 package com.wzy.lesson1; /** * @author wzy * @version 1.0 ...

  6. 一、spring——helloWorld

    1.添加jar包,如下图所示: 2.建立spring项目,如下图所示: 3.验证,如下图所示:

  7. 第一个spring简单的helloworld

    spring 是一个开源的框架 也是轻量级框架 1.导入jar包 spring的版本 4.0 目录: spring-framework-4.0.0.RELEASE-libs 下的jar  spring ...

  8. 2. Spring 的 HelloWorld

    初学Spring,就先来写一个 Spring 的 HelloWorld 吧 1. 首先,新建一个 java Project(因为暂时不需要网页,所以就不用创建 web 项目了) 2. 导入 Sprin ...

  9. Spring界的HelloWorld

    1.Spring依赖的jar包下载网址: https://repo.spring.io/webapp/#/artifacts/browse/tree/General/libs-release-loca ...

  10. 【一头扎进Spring】 01 | 从 HelloWorld 开始看Spring

    Spring 是一个开源框架. Spring 为简化企业级应用开发而生. 使用 Spring 可以使简单的 JavaBean 实现以前只有 EJB 才能实现的功能. Spring 是一个 IOC(DI ...

随机推荐

  1. Python 直接赋值、浅拷贝和深度拷贝区别

    Python 直接赋值.浅拷贝和深度拷贝区别 转自https://www.runoob.com/w3cnote/python-understanding-dict-copy-shallow-or-de ...

  2. DNS稳定保障系列1--服务双保障“辅助DNS”产品介绍

    背景 2016 年 10 月 21 日,DNS 服务商 dyn 的服务器遭遇黑客大流量的 ddos 攻击,使得美国大量互联网公司如 twitter,github等都出现解析失败,无法提供服务.如下图可 ...

  3. 为delphi程序添加脚本功能,用脚本控制delphi程序

    使用微软的ActiveX Scripting技术,可以在应用程序中集成使用vbscript或这javascript脚本语言.在delphi中点击Component菜单的Import Activex C ...

  4. Visual Studio 2012常用快捷键总结

    合理使用快捷键可以提高开发效率.收集整理一些常用的快捷键以方便查看使用 1.回到上一个光标位置/前进到下一个光标位置 1)回到上一个光标位置:使用组合键"Ctrl + -": 2) ...

  5. (抓)ubuntu下安装mysql --- 我主要参考的文章

    转:http://cycnet.blog.51cto.com/117809/812625 现在的软件越来越好安装,尤其是在ubuntu下安装软件,更是没有技巧,只需要在联网的情况下使用apt-get ...

  6. Codeforces gym102222 C. Caesar Cipher 签到

    题意: 给定一对用凯撒密码加密的明文和密文,再给你一个密文,让你解密出明文,保证有唯一解. 题解: 对凯撒密码的已知明文攻击,签到题. #include<iostream> using n ...

  7. 12、jquery的tree组件

    1. <!--jquery 的主文件...--> <script type="text/javascript" src="../../js/jquery ...

  8. Linux下使用java获取cpu、内存使用率

    原文地址:http://www.voidcn.com/article/p-yehrvmep-uo.html 思路如下:Linux系统中可以用top命令查看进程使用CPU和内存情况,通过Runtime类 ...

  9. PAT_A1070#Mooncake

    Source: PAT A1070 Mooncake (25 分) Description: Mooncake is a Chinese bakery product traditionally ea ...

  10. 前端(二十三)—— Vue环境搭建

    目录 一.Vue环境搭建 一.Vue环境搭建 1.安装node 去官网下载node安装包 傻瓜式安装 万一安装后终端没有node环境,要进行node环境变量的配置(C:\Program Files\n ...