热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

eclipse搭建spring,eclipse导入springboot项目

大家都说Spring框架好,而且之后的培训也会遇到框架,所以趁今天有点时间就看了一下Spring框架,这篇文章也是看后的一点小小的理解,非常的基础,大神请主动走开.好了不说的

大家都说Spring框架好,而且之后的培训也会遇到框架,所以趁今天有点时间就看了一下Spring框架,这篇文章也是看后的一点小小的理解,非常的基础,大神请主动走开....好了不说的,看看我理解的Spring框架吧。

首先是框架,我认为框架是为了某种目的更好的实现而编写的。或者说是为了更加方便的实现某种功能而编写的。Spring框架我们知道无论是一般的应用程序还是javaEE都是可以应用。自然有其方便之处。但是在一开始接触的时候被各种名词搞的晕头转向,什么工厂生成模式,控制反转,(我感觉控制反转就是我们之前编写程序的时候需要某一个类的对象都是new出来的,但是我们在框架中是不用new的,我们在框架中只需要getBean(name)就可以得到我们想要的对象了,这个就是框架给我们提供的方便)比如说我们有一个Course类,在编写的过程中我们需要一个Course的对象,之前我们new Course来创建一个Course对象,这样很麻烦哎,于是我们使用Spring框架可以解决这样的麻烦。那么我们下面就通过一个小的例子来看一下更为简单的方法。

第一步当然是下载Spring框架,这个我相信应该难不倒你吧.

第二步我们在Ecplise创建一个java工程,或者是web工程,都可以的,我们在这个地方创建一个web工程项目。


现在我们创建好的项目需要做的事情是将我们下载的Spring/lib里面的各种包导入到项目中,那么我们需要导入那些包呢


将这些包导入到项目中,是我们开始需要做的,如果我们后来需要扩展怎样的功能可以进一步的导入一下包,一开始我们可能还不知道这些包都具有什么样的作用,现在不要问这些,继续下一步的操作。

就是到我们熟悉的地方,我们在src中创建两个包,一个是dao包,一个是domain包,这两个包创建好之后,我们正在domain包中创建一个实体类,比如说Course类:如下:

package domain;import java.util.Date;public class Course {private String id;private String courseName;private Date startTime;private int suitable;private int type;private int totalHours;private int hotLevel;@Overridepublic String toString() {return "Course [id=" + id + ", courseName=" + courseName + ", startTime=" + startTime + ", suitable=" + suitable+ ", type=" + type + ", totalHours=" + totalHours + ", hotLevel=" + hotLevel + ", selectedCount="+ selectedCount + ", note=" + note + "]";}public Course(String id, String courseName) {super();this.id = id;this.courseName = courseName;}private int selectedCount;private String note;public String getId() {return id;}public void setId(String id) {this.id = id;}public String getCourseName() {return courseName;}public void setCourseName(String courseName) {this.courseName = courseName;}public Date getStartTime() {return startTime;}public void setStartTime(Date startTime) {this.startTime = startTime;}public int getSuitable() {return suitable;}public void setSuitable(int suitable) {this.suitable = suitable;}public int getType() {return type;}public void setType(int type) {this.type = type;}public int getTotalHours() {return totalHours;}public void setTotalHours(int totalHours) {this.totalHours = totalHours;}public int getHotLevel() {return hotLevel;}public void setHotLevel(int hotLevel) {this.hotLevel = hotLevel;}public int getSelectedCount() {return selectedCount;}public void setSelectedCount(int selectCount) {this.selectedCount = selectCount;}public String getNote() {return note;}public void setNote(String note) {this.note = note;}public Course() {super();// TODO Auto-generated constructor stub}public Course(String id, String courseName, Date startTime, int type2, int type, int totalHours, String note) {super();this.id = id;this.courseName = courseName;this.startTime = startTime;this.suitable = type2;this.type = type;this.totalHours = totalHours;this.note = note;}public Course(String id, String courseName, Date startTime, int suitable, int type, int totalHours, int hotLevel,int selectCount, String note) {super();this.id = id;this.courseName = courseName;this.startTime = startTime;this.suitable = suitable;this.type = type;this.totalHours = totalHours;this.hotLevel = hotLevel;this.selectedCount = selectCount;this.note = note;}}当然你可以写自己的实体类比如说person或者Student等等

然后我们需要做的事情是写配置文件,这个需要我们自己动手写名字就为:applicationContext.xml,如下:

配置好这些之后我们需要做的事情就是看一下我们的Spring框架是不是安装成功了

我们在dao包下编写一个Test类,如下:

package dao;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import domain.Course;public class Test { public static void main(String []args) { String location="classpath:applicationContext.xml"; ApplicationContext ctx=new ClassPathXmlApplicationContext(location); Course cous=(Course)ctx.getBean("course"); System.out.println(cous.getId()); }}然后执行我们的程序,如果最后在控制台成功的输出0001就表示我们的框架搭建是成功的。

最后控制台输出:

十二月 29, 2016 5:04:35 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@7eda2dbb: startup date [Thu Dec 29 17:04:35 CST 2016]; root of context hierarchy十二月 29, 2016 5:04:35 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions信息: Loading XML bean definitions from class path resource [applicationContext.xml]十二月 29, 2016 5:04:36 下午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2ff4f00f: defining beans [course]; root of factory hierarchy0001如果说你最后输出的日志文件不是这样的,你可以将log4j.jar这个包移除然后添加另外的一个包

commmon-logging-jar这个包试一下,

我这构建的Spring框架也许有不足,如果你有更好的办法也欢迎一起交流。。。

希望对你有所帮助























推荐阅读
  • 本文介绍了一款名为TimeSelector的Android日期时间选择器,采用了Material Design风格,可以在Android Studio中通过gradle添加依赖来使用,也可以在Eclipse中下载源码使用。文章详细介绍了TimeSelector的构造方法和参数说明,以及如何使用回调函数来处理选取时间后的操作。同时还提供了示例代码和可选的起始时间和结束时间设置。 ... [详细]
  • 开发笔记:spring boot项目打成war包部署到服务器的步骤与注意事项
    本文介绍了将spring boot项目打成war包并部署到服务器的步骤与注意事项。通过本文的学习,读者可以了解到如何将spring boot项目打包成war包,并成功地部署到服务器上。 ... [详细]
  • 前一天学习了视图按键事件的监听。首先新建了一个自定义的视图,在自定义视图中,重新编了其构造函数和onDraw()方法。之后将该视图用于应用程序,最后添加该视图的按键监听器,在监听器中对KeyEvent ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • Hibernate延迟加载深入分析-集合属性的延迟加载策略
    本文深入分析了Hibernate延迟加载的机制,特别是集合属性的延迟加载策略。通过延迟加载,可以降低系统的内存开销,提高Hibernate的运行性能。对于集合属性,推荐使用延迟加载策略,即在系统需要使用集合属性时才从数据库装载关联的数据,避免一次加载所有集合属性导致性能下降。 ... [详细]
  • 我将SpringMVC升级到Spring3.2.5.我的一些剩余调用即使存在,也会返回无法识别的字段异常.这是错误.Resolvingexceptionfrom ... [详细]
  • 涉及的知识点-ViewGroup的测量与布局-View的测量与布局-滑动冲突的处理-VelocityTracker滑动速率跟踪-Scroller实现弹性滑动-屏幕宽高的获取等实现步 ... [详细]
  • IhaveconfiguredanactionforaremotenotificationwhenitarrivestomyiOsapp.Iwanttwodiff ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • ASP.NET2.0数据教程之十四:使用FormView的模板
    本文介绍了在ASP.NET 2.0中使用FormView控件来实现自定义的显示外观,与GridView和DetailsView不同,FormView使用模板来呈现,可以实现不规则的外观呈现。同时还介绍了TemplateField的用法和FormView与DetailsView的区别。 ... [详细]
  • Elasticsearch1Elasticsearch入门1.1Elasticsearch术语1.1.16.0以前的Elasticsearch术语1.1.26.0以后的Elasti ... [详细]
  • SpringBoot整合SpringSecurity+JWT实现单点登录
    SpringBoot整合SpringSecurity+JWT实现单点登录,Go语言社区,Golang程序员人脉社 ... [详细]
  • 本文讨论了在使用Git进行版本控制时,如何提供类似CVS中自动增加版本号的功能。作者介绍了Git中的其他版本表示方式,如git describe命令,并提供了使用这些表示方式来确定文件更新情况的示例。此外,文章还介绍了启用$Id:$功能的方法,并讨论了一些开发者在使用Git时的需求和使用场景。 ... [详细]
author-avatar
mobiledu2502917185
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有