Idea创建Spring项目
环境 win7 + Idea2018
Classpath commons-logging-1.2 + spring-framework-4.1.6.RELEASE
Step1 创建工程
File -> New -> Project
选择Spring项目,“Addtionnal Lib and Frameworks” 选择第一个 ”Spring”, next 命名项目HelloSpring
Step2 添加jar
选择项目HelloSpring File –> Project Structure->Modules,选中项目HelloSpring,选中Dependancies 页签,点击“+” 添加jar包,效果如下
commons-logging-1.1.1
spring-aop-4.1.6.RELEASE
spring-aspects-4.1.6.RELEASE
spring-beans-4.1.6.RELEASE
spring-context-4.1.6.RELEASE
spring-context-support-4.1.6.RELEASE
spring-core-4.1.6.RELEASE
spring-expression-4.1.6.RELEASE
spring-instrument-4.1.6.RELEASE
spring-instrument-tomcat-4.1.6.RELEASE
spring-jdbc-4.1.6.RELEASE
spring-jms-4.1.6.RELEASE
spring-messaging-4.1.6.RELEASE
spring-orm-4.1.6.RELEASE
spring-oxm-4.1.6.RELEASE
spring-test-4.1.6.RELEASE
spring-tx-4.1.6.RELEASE
spring-web-4.1.6.RELEASE
spring-webmvc-4.1.6.RELEASE
spring-webmvc-portlet-4.1.6.RELEASE
spring-websocket-4.1.6.RELEASE
Step3 创建源代码
HelloWorld.java MainApp.java
主程序逻辑如下:
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
obj.getMessage();
}
首先适用framework API ClassPathXmlApplicationContext()创建application context,这个API接口会加载beans配置文件,并根据所提供api去创建、初始化对象(即 配置文件中的beans);
其次,使用上步创建的contex getBean()方法获取对象bean ID,并最终向上cast得到实际对象,进而调用所有对象方法。
Step4 创建bean配置文件
Bean.xml配置文件的功能是将所有的bean粘合在一起;命名可以任意,但必须在ClassPath路径配置,并且创建application context时使用的名称一致;
Beans.xml 给beans分别指派唯一Id,并且创建对象时可以传入参数值,例如“message”变量:
<bean id = "helloWorld" class = "com.tutorialspoint.HelloWorld">
<property name = "message" value = "Hello World!"/>
</bean>
Step5 运行程序
控制台输出
Your Message : Hello World!
Idea创建Spring项目的更多相关文章
- Spring入门(一):创建Spring项目
本篇博客作为Spring入门系列的第一篇博客,不会讲解什么是Spring以及Spring的发展史这些太理论的东西,主要讲解下如何使用IntelliJ IDEA创建第一个Spring项目以及通过一个示例 ...
- Spring入门案例 idea创建Spring项目
spring入门案例 idea创建spring项目 Spring介绍 Spring概述 Spring是一个开源框架,Spring是2003年兴起的轻量级java开发框架,由Rod Johnson 在其 ...
- IntelliJ IDEA 创建Spring项目
第一步:点击file --> new --> project... 第二步: 在左侧选择Spring, 然后勾选Spring , 最后点击Next 第三步 : 填写项目名称和项目地址,点击 ...
- 手动创建spring项目(maven/IDEA环境)
1.创建maven项目 按照步骤一步一步来 创建项目 这里选择maven的模板 设置包名 设置项目的maven的配置信息.maven仓库路径(会从maven配置文件中获取) 这里设置项目名.项目保存路 ...
- IDEA 创建Spring项目后org.springframework.boot报错
IDEA 创建 Spring boot 项目后 ,在pom.xml文件中 org.springframework.boot出错,刷新也没有作用. 如图: 可以降低 org.springframewor ...
- MyEclipse2017创建Spring项目
1.创建一个Web Project 2.右击项目-->Properties 3.搜索Spring -->Peoject Facets-->在右边找到Spring,打勾并保存 4.测试 ...
- IDEA下创建Spring项目
IDEA下创建Java SE Spring项目示例 1.创建项目 第4步:是否自动创建空的Spring容器配置文件,默认文件名是spring-config.xml.勾不勾选都行,如果没勾选,后面要自己 ...
- 手动创建Spring项目 Spring framework
之前学习框架一直是看的视频教程,并且在都配套有项目源码,跟着视频敲代码总是很简单,现在想深入了解,自己从官网下载文件手动搭建,就遇到了很多问题记载如下. 首先熟悉一下spring的官方网站:http: ...
- Eclipse创建Spring项目 未完
使用的软件及版本 1)Eclipse:Eclipse Java EE IDE for Web Developers :Version: 2018-09 (4.9.0) 2)JDK:java versi ...
随机推荐
- Spark 资源调度包 stage 类解析
spark 资源调度包 Stage(阶段) 类解析 Stage 概念 Spark 任务会根据 RDD 之间的依赖关系, 形成一个DAG有向无环图, DAG会被提交给DAGScheduler, DAGS ...
- Spark笔记(一)
简介 Apache Spark 是专为大规模数据处理而设计的快速通用的计算引擎.Spark是UC Berkeley AMP lab (加州大学伯克利分校的AMP实验室)所开源的类Hadoop MapR ...
- Spring开发环境搭建(Eclipse)
开发环境搭建,主要包含2部分: Java安装 Eclipse安装 为易于学习,我们只安装这2个部分,对于一般开发学习也足够了.如果你有其他要安装的,酌情添加. Java安装 我们使用Java8: 下载 ...
- POJ 3311 Hie with the Pie 最短路+状压DP
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11243 Accepted: 5963 ...
- 文献阅读报告 - Context-Based Cyclist Path Prediction using RNN
原文引用 Pool, Ewoud & Kooij, Julian & Gavrila, Dariu. (2019). Context-based cyclist path predic ...
- 文献阅读报告 - Move, Attend and Predict
Citation Al-Molegi A , Martínez-Ballesté, Antoni, Jabreel M . Move, Attend and Predict: An Attention ...
- SDN(Software Defined Network):软件定义网络----转载
SDN(Software Defined Network):软件定义网络 传统的网络转发行为: 1)逐设备单独控制,纯分布式控制. 2)控制面和转发面在同一个设备中,耦合紧密. 管理员无法直接操控转发 ...
- DES与MD5加密
using System; using System.Data; using System.Configuration; using System.Web; using System.Security ...
- Elasticsearch分布式搜索
ElasticSearch之介绍 一 Elasticsearch产生背景 1.1 大规模数据如何检索 如:当系统数据量上了10亿.100亿条的时候,我们在做系统架构的时候通常会从以下角度去考虑问题:1 ...
- sql优化从300秒到7秒
原始sql select b.jd 街道,b.rglm 楼宇,zzrl 楼宇编号,count(oname) 入楼企业总数, (select count(oname) from ${tablename} ...