spring-helloworld (1)
关于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)的更多相关文章
- 创建一个spring helloworld
1.下载所需要的jar包 http://projects.spring.io/spring-framework/ 这里使用了maven方式给出jar <dependencies> < ...
- Spring配置与第一Spring HelloWorld
林炳文Evankaka原创作品. 转载请注明出处http://blog.csdn.net/evankaka 本文将主讲了Spring在Eclipse下的配置,并用Spring执行了第一个HelloWo ...
- Eclipse安装springsource-tool-suite插件及spring helloworld入门实例
转载至: https://www.cnblogs.com/aaron-shu/p/5156007.html 一.查看eclipse版本 Help-->About Eclipse,我的版本是4.4 ...
- Spring学习笔记2:Spring HelloWorld
1:IntelliJ新建Maven工程 2:pom文件加入Spring依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" ...
- Spring基础02——Spring HelloWorld
1.首先我们来创建一个HelloWorld类,通过Spring来对这个类进行实例化 package com.wzy.lesson1; /** * @author wzy * @version 1.0 ...
- 一、spring——helloWorld
1.添加jar包,如下图所示: 2.建立spring项目,如下图所示: 3.验证,如下图所示:
- 第一个spring简单的helloworld
spring 是一个开源的框架 也是轻量级框架 1.导入jar包 spring的版本 4.0 目录: spring-framework-4.0.0.RELEASE-libs 下的jar spring ...
- 2. Spring 的 HelloWorld
初学Spring,就先来写一个 Spring 的 HelloWorld 吧 1. 首先,新建一个 java Project(因为暂时不需要网页,所以就不用创建 web 项目了) 2. 导入 Sprin ...
- Spring界的HelloWorld
1.Spring依赖的jar包下载网址: https://repo.spring.io/webapp/#/artifacts/browse/tree/General/libs-release-loca ...
- 【一头扎进Spring】 01 | 从 HelloWorld 开始看Spring
Spring 是一个开源框架. Spring 为简化企业级应用开发而生. 使用 Spring 可以使简单的 JavaBean 实现以前只有 EJB 才能实现的功能. Spring 是一个 IOC(DI ...
随机推荐
- Vulhub-漏洞环境的搭建
安装Docker #安装pip curl -s https://bootstrap.pypa.io/get-pip.py | python3 #安装最新版docker curl -s https:// ...
- leetcode-168周赛-1298-你能从盒子中获得的最大糖果数
题目描述: 方法一:bfs class Solution: def maxCandies(self, status: List[int], candies: List[int], keys: List ...
- js中浏览器对象BOM
参考 : https://www.cnblogs.com/Peng2014/p/4725524.html 1. window对象 https://www.runoob.com/jsref/ob ...
- HTML-参考手册: HTTP 状态消息
ylbtech-HTML-参考手册: HTTP 状态消息 1.返回顶部 1. HTTP 状态消息 当浏览器从 web 服务器请求服务时,可能会发生错误. 以下列举了有可能会返回的一系列 HTTP 状态 ...
- 我看Spring MVC系列(一)
1.Spring MVC是什么: Spring MVC:Spring框架提供了构建Web应用程序的全功能MVC模块. 2.Spring helloWorld应用(基于Spring 4.2) 1.添加S ...
- 18、Page Object 设计模式
Page Object 设计模式的优点如下: 减少代码的重复. 提高测试用例的可读性. 提高测试用例的可维护性, 特别是针对 UI 频繁变化的项目. 当你针对网页编写测试时,你需要引用该网页中的元素, ...
- 机器学习基石笔记:Homework #4 Regularization&Validation相关习题
原文地址:https://www.jianshu.com/p/3f7d4aa6a7cf 问题描述 程序实现 # coding: utf-8 import numpy as np import math ...
- node 创建静态web服务器(下)(处理异步获取数据的两种方式)
接上一章. 上一章我们说创建的静态web服务器只能识别html,css,js文件,功能较为单一,且图片格式为text/html,这是不合理的. 本章,我们将解决该问题. 这里,我们先准备好一个json ...
- 入门 Webpack,看这篇就够
写在前面的话 阅读本文之前,先看下面这个webpack的配置文件,如果每一项你都懂,那本文能带给你的收获也许就比较有限,你可以快速浏览或直接跳过:如果你和十天前的我一样,对很多选项存在着疑惑,那花一段 ...
- hdu 6437 /// 最小费用最大流 负花费 SPFA模板
题目大意: 给定n,m,K,W 表示n个小时 m场电影(分为类型A.B) K个人 若某个人连续看了两场相同类型的电影则失去W 电影时间不能重叠 接下来给定m场电影的 s t w op 表示电影的 开始 ...