使用IDEA搭建spring
从前使用eclipse开发,集成jar包,现在使用maven来管理
一:
1.框架

2.pom
需要spring core与spring context。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>SpringTest</groupId>
<artifactId>SpringTest</artifactId>
<version>1.0-SNAPSHOT</version> <dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.0.RELEASE</version>
</dependency> </dependencies>
</project>
3.接口HelloWorld
package com.it.service;
public interface HelloWorld {
public void sayHello();
}
4.实现类
package com.it.service;
public class SpringHelloWorld implements HelloWorld {
public void sayHello() {
System.out.println("say hello");
}
}
5.bean
package com.it.bean;
import com.it.service.HelloWorld;
public class HelloWorldService {
private HelloWorld helloWorld;
public HelloWorldService() {
}
public void setHelloWorld(HelloWorld helloWorld) {
this.helloWorld = helloWorld;
}
public HelloWorld getHelloWorld() {
return this.helloWorld;
}
}
6.运行main
package com.it.main; import com.it.service.HelloWorld;
import com.it.bean.HelloWorldService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class HelloMain {
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); HelloWorldService service = (HelloWorldService) context.getBean("helloWorldService"); HelloWorld hw= service.getHelloWorld(); hw.sayHello();
}
}
7.beans.xml
<?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 id="helloWorldService" class="com.it.bean.HelloWorldService">
<property name="helloWorld" ref="springHelloWorld"/>
</bean> <bean id="springHelloWorld" class="com.it.service.SpringHelloWorld"></bean>
</beans>
8.效果

使用IDEA搭建spring的更多相关文章
- MAC OS X El CAPITAN 搭建SPRING MVC (1)- 目录、包名、创建web.xml
一. 下载STS(Spring Tool Suite) 官方地址:http://spring.io/tools/sts 下载spring tool suite for mac 最新版本.这个IDE是很 ...
- 从零开始学 Java - 搭建 Spring MVC 框架
没有什么比一个时代的没落更令人伤感的了 整个社会和人都在追求创新.进步.成长,没有人愿意停步不前,一个个老事物慢慢从我们生活中消失掉真的令人那么伤感么?或者说被取代?我想有些是的,但有些东西其实并不是 ...
- 搭建Spring + SpringMVC + Mybatis框架之二(整合Spring和Mybatis)
整合Spring和Mybatis 首先给出完整的项目目录: (1)引入项目需要的jar包 使用http://maven.apache.org作为中央仓库即可. Spring核心包,mybatis核心包 ...
- 搭建Spring、Spring MVC、Mybatis和Freemarker
搭建Spring.Spring MVC.Mybatis和Freemarker 1.pom文件 <project xmlns="http://maven.apache.org/POM/4 ...
- 使用IDEA搭建Spring Boot入门项目
简介 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置 ...
- idea搭建spring的demo
这是本人在回顾知识点时记录的内容,如有错误,谢谢指正! 1.先来介绍下spring是什么? spring是一个轻量级的开源框架,是一个大型的容器,也是一个很好的“管家”,可以接管web层,业务层,da ...
- maven 聚合工程 用spring boot 搭建 spring cloud 微服务 模块式开发项目
项目的简单介绍: 项目采用maven聚合工程 用spring boot 搭建 spring cloud的微服务 模块式开发 项目的截图: 搭建开始: 能上图 我少打字 1.首先搭建maven的聚合工程 ...
- Eclipse上搭建Spring的开发环境
一.安装Spring Tool Suite插件 如图: 点击Finish之后等待安装,安装完之后弹窗点击yes重启Eclipse,重启后显示如下界面: 二.搭建Spring开发环境 1.导入jar包到 ...
- 框架:Intellij搭建Spring框架
第二章.Intellij搭建Spring框架 前提条件:jdk.jre已经安装完成 方法一.intellij下载jar 附:自带的jar的版本为4.3[2018/11/22] 第一步:选择File&g ...
- Spring Boot系列学习文章(一) -- Intellij IDEA 搭建Spring Boot项目
前言: 最近做的一个项目是用Spring Boot来做的,所以把工作中遇到的一些知识点.问题点整理一下,做成一系列学习文章,供后续学习Spring Boot的同仁们参考,我也是第一次接触Spring ...
随机推荐
- 【BZOJ2067】SZN(二分,动态规划,贪心)
[BZOJ2067]SZN(二分,动态规划,贪心) 题面 权限题额 Description String-Toys joint-stock 公司需要你帮他们解决一个问题. 他们想制造一个没有环的连通图 ...
- SoapUI使用笔记备忘
1.安装好SoapUI后,新建一个REST项目 注意新建REST项目时,需要输入测试站点的地址,即IP+端口 之后点击OK就建立好了项目,但是新项目会默认自带一个根路径访问请求,可以删除(一般没用) ...
- 前端学习 -- Css -- overflow
子元素默认是存在于父元素的内容区中,理论上讲子元素的最大可以等于父元素内容区大小.如果子元素的大小超过了父元素的内容区,则超过的大小会在父元素以外的位置显示,超出父元素的内容,我们称为溢出的内容.父元 ...
- 解题:HAOI 2015 按位或
题面 Min-Max容斥:对于集合S $min(S)=\sum_{s∈S}(-1)^{|s|+1}max(s)$ $max(S)=\sum_{s∈S}(-1)^{|s|+1}min(s)$ 那么这个题 ...
- POJ 2516 Minimum Cost (网络流,最小费用流)
POJ 2516 Minimum Cost (网络流,最小费用流) Description Dearboy, a goods victualer, now comes to a big problem ...
- 洛谷P3241 开店
题意:紫妹和幽香是17岁的少女,喜欢可爱的东西. 给定一棵树,有点权,边权.每次求所有权值在[l, r]范围内的点到点x的距离和.强制在线. 解:动态点分治怎么搞啊...... 一开始想的是权值的限制 ...
- jsoncpp的安装与使用示例
安装: 生成静态库 生成静态库: 第一步:生成目标文件: g++ -g -Wall -c json_reader.cpp json_value.cpp json_writer.cpp -I. -I.. ...
- 创建 OpenStack云主机(十一)
创建过程 创建虚拟网络 创建m1.nano规格的主机(相等于定义虚拟机的硬件配置) 生成一个密钥对(openstack的原理是不使用密码连接,而是使用密钥对进行连接) 增加安全组规则(用iptable ...
- Python 发射导弹的正确方式
——此文以纪念南京大屠杀79周年 今天Toby教你如何用python的basemap包绘制轰炸东京的地图. 在数据可视化过程中,我们常常需要将数据根据其采集的地理位置在地图上显示出来.比如说我们会想要 ...
- Object和泛型
这俩东东呢实现的效果是一样的,但是它们俩的效率不一样,原理也不一样.直接说结论吧,泛型比Object好用,效率高.因为Object有一个装箱和拆箱的过程,倘若是很多的数据那效率就低到不行了,而泛型没有 ...