博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring笔记
阅读量:4476 次
发布时间:2019-06-08

本文共 1628 字,大约阅读时间需要 5 分钟。

1、安装Spring Tool Sui

登录http://spring.io/tools/sts/all 下载所需的Spring Tool Suit安装包

下载完成后

Eclipse --- Help--- Install new Sofware

点击Add按钮 ,再点击Archive 选择你刚刚下载的zip文件

选择带有“Spring IDE”字样的项,一个4个:

最好取消联网更新,否则会很慢

2、加Maven

参考http://projects.spring.io/spring-framework/

org.springframework
spring-context
4.2.4.RELEASE

3、范例

src下新建Spring Bean Configuration File,命名applicationContext.xml

 全类名用反射的方式由spring创建对象,id用来标示这个对象。用name对应setter

以下是Spring前后对比:

public class App {    public static void main(String[] args) {        // HelloWorld helloWorld = new HelloWorld();        // helloWorld.setName("colin");        // 1、创建Spring的IOC容器对象        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");        // 2、从IOC容器中获取Bean实例        HelloWorld helloWorld = (HelloWorld) ctx.getBean("helloWorld");        // 3、        helloWorld.hello();    }}

创建容器时,他会根据配置文件,调用构造器创建相应对象,并调用setter给属性赋值

 

附:Maven web 依赖

org.springframework
spring-web
4.2.4.RELEASE
org.springframework
spring-webmvc
4.2.4.RELEASE
org.springframework
spring-context
4.2.4.RELEASE
javax.servlet
servlet-api
2.5
provided

 

转载于:https://www.cnblogs.com/sysout/p/5191313.html

你可能感兴趣的文章
python用递归函数解汉诺塔游戏
查看>>
Redis与Python交互
查看>>
Maximum-SubsequenceSum
查看>>
常用的一些shell变量
查看>>
Android无法删除项目+导入项目报错
查看>>
poj 2349(最小生成树应用)
查看>>
python接口自动化测试二十五:执行所有用例,并生成HTML测试报告
查看>>
c# 指定的存储区提供程序在配置中找不到,或者无效
查看>>
最简陋的python数据
查看>>
第一堂java web课
查看>>
操作系统简介
查看>>
第1周小组博客作业--1703班06组
查看>>
vue项目中icon图标的完美引入
查看>>
C语言指针
查看>>
Java的安装
查看>>
0920 JSON数据 蓝懿
查看>>
Azure Cosmos DB 使用费用参考
查看>>
【嵌入式开发】写入开发板Linux系统-模型S3C6410
查看>>
C# 子线程与主线程通讯方法一
查看>>
006——修改tomacat的编码
查看>>