spring-HelloWorld
准备工作,安装SpringIDE,找到SpringSource-tool-suit,然后按照,
关键的一部在与找到之后该安转那些呢,答案是只安转带有SpringIDE的,
有四个,且不要点击联网进行更新
第一步:新建一个Dynamic Web Project,名字叫SpringMvc-1
第二步:jar 包:
commons-logging-1.1.3.jar
spring-aop-4.0.0.RELEASE.jar
spring-beans-4.0.0.RELEASE.jar
spring-context-4.0.0.RELEASE.jar
spring-core-4.0.0.RELEASE.jar
spring-expression-4.0.0.RELEASE.jar
spring-web-4.0.0.RELEASE.jar
spring-webmvc-4.0.0.RELEASE.jar
添加配置文件(在src目录下)
<?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,反射,创建类,set方法 -->
<bean id="helloWorld" class="com.atguigu.spring.beans.HelloWorld">
<property name="name" value="Spring"></property> </bean>
</beans>
实体类
package com.atguigu.spring.beans; public class HelloWorld
{
String name;
public void setName(String name)
{
this.name = name;
}
public void hello()
{
System.out.println("hello "+name);
}
public HelloWorld()
{
System.out.println("construct...");
}
}
测试类
package com.atguigu.spring.beans; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main
{
public static void main(String[] args)
{
//创建对象,
HelloWorld helloWorld = new HelloWorld();
//为属性赋值
helloWorld.setName("atguigu");
//调用方法
helloWorld.hello();
//创建spring的IOC容器
// 1.Appl ctx = new ClassPathXmlApplica
ApplicationContext act = new ClassPathXmlApplicationContext("applicationContext.xml");
//2.从IOC中获取bean实例
//HelloWorld helloWorld2 = (HelloWorld) act.getBean("helloWorld");
//3.调用hello方法
//helloWorld2.hello();
}
}
* IOC(Inversion of Control):其意思是反转资源获取的方向.传统的资源查找方式要求组件向容器发起请求查找资源(比如程序读取配置文件).
* 作为回应,容器适时的返回资源,而应用了IOC之后,则是容器主动地将资源推送给他所管理的组件,组件所要做的仅是选择一种合适的方式来接受资源
* 这种行为也被称为查找的被动形式,
* DI(dependency Injection)---IOC的另一中表达方式:即组件以一些预先定义的方式(例如setter方法)接受来自容器的资源注入
* 相对于IOC而言,这种表述更加直接
spring-HelloWorld的更多相关文章
- 创建一个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 ...
随机推荐
- HashTable, HashMap, LinkedHashMap, ConcurrentHashMap
HashTable: 不允许null的key或value, 线程安全 HashMap: 允许一个null的key, 无限的null value, 非线程安全 LinkedHashMap: HashMa ...
- 【MySQL】使用trim函数删除两侧字符
第一个LEADING,可以删除左侧指定的字符以及字符串 SELECT trim(LEADING '/' FROM `path`) 第二个TRAILING,可以删除右侧的指定字符以及字符串 SELECT ...
- NET Core中怎么使用HttpContext.Current
NET Core中怎么使用HttpContext.Current 阅读目录 一.前言 二.IHttpContextAccessor 三.HttpContextAccessor 回到目录 一.前言 我们 ...
- Ros学习注意点
编译问题 回调函数不能有返回类型,严格按照实例程序编写 第三方库的问题,packet.xml里面必须加上自己的依赖文件 之前文档里面介绍的有点问题. 主要表现在:当你建立包的时候就写入了依赖,那就不需 ...
- LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree
LeetCode:Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth ...
- Alpha阶段事后分析报告
每个团队编写一个事后分析报告,对于团队在Alpha阶段的工作做一个总结. 请在2016年11月24日上课之前根据下述博客中的模板总结前一阶段的工作,发表在团队博客上,并在课上的事后分析会上进行汇报,并 ...
- PAT1078 Hashing
11-散列2 Hashing (25分) The task of this problem is simple: insert a sequence of distinct positive in ...
- Oracle 常见错误排查
1. java.sql.SQLException: ORA-01000: 超出打开游标的最大数 step 1: 查看数据库当前的游标数配置slqplus:show parameter open_cur ...
- variable-precision SWAR算法介绍
BITCOUNT命令是统计一个位数组中非0进制位的数量,数学上称作:”Hanmming Weight“ 目前效率最好的为variable-precision SWAR算法,可以常数时间内计算出多个字节 ...
- ASP.NET 系列:单元测试之ConfigurationManager
通过ConfigurationManager使用.NET配置文件时,可以通过添加配置文件进行单元测试,虽然可以通过测试但达不到解耦的目的.使用IConfigurationManager和Configu ...