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 ...
随机推荐
- Tomcat 5.5启动需要用户名密码的解决方案
我在使用Tomcat的时候碰到这样的问题,然后在csdn里面找到方法,然后保存一份,原帖地址:Tomcat用户名密码,8#原来的tomcat-user.xml是 <?xml version=& ...
- 快速判断素数 --Rabin-Miller算法
以前我在判断素数上一直只会 sqrt(n) 复杂度的方法和所谓的试除法(预处理出sqrt(n)以内的素数,再用它们来除). (当然筛选法对于判断一个数是否是素数复杂度太高) 现在我发现其实还有一种方法 ...
- Cordova - 使用Cordova开发iOS应用实战4(调用摄像头拍照,并编辑)
使用Cordova可以很方便的通过js代码来使用设备摄像头拍照,只需把camera插件添加进来即可. 一,添加camera插件 首先我们要在“终端”中进入工程所在的目录,然后运行如下命令: 1 cor ...
- c++ 静态持续变量
c++为静态存储持续性变量提供了3种链接性: 外部链接性(可在其他文件中访问) 内部链接性(只能在当前文件中访问) 无链接性(别有用心能在当前函数或代码中访问) 如果没有显示的初始化静态变量会把它设置 ...
- WPF EventSetter Handler Command
最近做一个工具,突然发现ListBox和ListView等列表控件的MouseDoubleClick事件有时候是获取不到当前双击的行对象数据的,比如这样写: <ListBox Grid.Row= ...
- 闲扯 『 document.write 』
初春的晚上,闲来无事,聊聊 document.write 方法. document.write 使用方式非常简单,把 "字符串化"(不好意思,这可能是我自己创造的名词)的 html ...
- 制作鼠标移动到div上面显示弹出框
<div class="show-dialog hide"> <header> <div class="note"> < ...
- 用js转换joson返回数据库的时间格式为/Date(*************)/
原理是取中间的毫秒数,再转换成js的Date类型 function ChangeDateFormat(val) { if (val != null) { var date = new Date(par ...
- MATLAB中subplot的用法
写成subplot(m,n,p)或者subplot(mnp). subplot是将多个图画到一个平面上的工具.其中,m表示是图排成m行,n表示图排成n列,也就是整个figure中有n个图是排成一行的, ...
- git --- push到远端