`
z_jiankun
  • 浏览: 164317 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

Spring—下载与配置

    博客分类:
  • Java
 
阅读更多

下载主页http://www.springframework.org/download.html ,或者直接使用链接地址:http://voxel.dl.sourceforge.net/sourceforge/springframework/spring-framework-1.1.4-with-dependencies.zip

Spring的下载包有两种:spring-framework-1.1.4-with-dependencies.zipspring-framework-1.1.4.zip,上面的第二个链接就是下载前者,建议你也下载前者,因为前者比后者多了一些Spring要用到的第三方包,如hibernatej2eedom4jaopalliancejakarta-commons等。下载包名称的dependencies就是“依赖”的意思。

1、解压后的目录结构如下:

<!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter" /> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0" /> <v:f eqn="sum @0 1 0" /> <v:f eqn="sum 0 0 @1" /> <v:f eqn="prod @2 1 2" /> <v:f eqn="prod @3 21600 pixelWidth" /> <v:f eqn="prod @3 21600 pixelHeight" /> <v:f eqn="sum @0 0 1" /> <v:f eqn="prod @6 1 2" /> <v:f eqn="prod @7 21600 pixelWidth" /> <v:f eqn="sum @8 21600 0" /> <v:f eqn="prod @7 21600 pixelHeight" /> <v:f eqn="sum @10 21600 0" /> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect" /> <o:lock v:ext="edit" aspectratio="t" /> </v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" alt="" style='width:214.5pt; height:240.75pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image001.jpg" o:href="http://blog.csdn.net/images/blog_csdn_net/glchengang/97615/r_20050217image001.jpg" /> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

 

目录说明:

l           dist  Spring自已的核心库

l           docs    有一些文档。

l           lib   是一些用到的第三方库。

l           mock  仿制品?????????????我也不知道

l           samples 一些项目例子

l           src  Spring的源代码

l           test  测试用例

 

2、新建一个Eclipse项目

1)项目名myspring

<!--[if gte vml 1]><v:shape id="_x0000_i1026" type="#_x0000_t75" alt="" style='width:375pt;height:346.5pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image002.jpg" o:href="http://blog.csdn.net/images/blog_csdn_net/glchengang/97615/r_20050217image002.jpg" /> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

 

2)直接单击“下一步”,再单击“完成”

3)在项目下创建一个lib目录

<!--[if gte vml 1]><v:shape id="_x0000_i1027" type="#_x0000_t75" alt="" style='width:189.75pt;height:90.75pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image003.jpg" o:href="http://blog.csdn.net/images/blog_csdn_net/glchengang/97615/r_20050217image003.jpg" /> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

 

4)将Spring的解压缩目录distlib都复制到这个lib目录中,然后前者改名成spring,后者先暂时不动吧,以后用到时才管它。

 

3、将spring库加入到库引用

spring库加入到库引用中,有如下两种方法。

方法一:单击“添加JAR”把spring的核心包加入。

<!--[if gte vml 1]><v:shape id="_x0000_i1029" type="#_x0000_t75" alt="" style='width:328.5pt;height:328.5pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image004.jpg" o:href="http://blog.csdn.net/images/blog_csdn_net/glchengang/97615/r_20050217image004.jpg" /> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

 

方法二:上面的“方法一”简单易行,但如果一个项目要引入的包种类很多,那么就显示得较乱。还有一种操作麻烦,但较清晰一些的方法。这种方法是使用Eclipse中的“用户库”的方式,如下图所示:

<!--[if gte vml 1]><v:shape id="_x0000_i1028" type="#_x0000_t75" alt="" style='width:414.75pt;height:342pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image005.jpg" o:href="http://blog.csdn.net/images/blog_csdn_net/glchengang/97615/r_20050217image005.jpg" /> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

 

<!--[if gte vml 1]><v:shape id="_x0000_i1030" type="#_x0000_t75" alt="" style='width:415.5pt;height:297.75pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image006.jpg" o:href="http://blog.csdn.net/images/blog_csdn_net/glchengang/97615/r_20050217image006.jpg" /> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if gte vml 1]><v:shape id="_x0000_i1031" type="#_x0000_t75" alt="" style='width:414.75pt;height:385.5pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image007.jpg" o:href="http://blog.csdn.net/images/blog_csdn_net/glchengang/97615/r_20050217image007.jpg" /> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

 

最后的结果如下图所示,然后单击“确定”


<!--[if gte vml 1]><v:shape id="_x0000_i1032" type="#_x0000_t75" alt="" style='width:414.75pt;height:287.25pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image009.jpg" o:href="http://blog.csdn.net/images/blog_csdn_net/glchengang/97615/r_20050217image008.jpg" /> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

 

返回上一界面后,再单击“完成”,得到如下图所示的效果

<!--[if gte vml 1]><v:shape id="_x0000_i1033" type="#_x0000_t75" alt="" style='width:414.75pt;height:342pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image010.jpg" o:href="http://blog.csdn.net/images/blog_csdn_net/glchengang/97615/r_20050217image009.jpg" /> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

 

最后,项目里的spring包的引用都在一个目录下,显示层次感强很多。

<!--[if gte vml 1]><v:shape id="_x0000_i1034" type="#_x0000_t75" alt="" style='width:3in;height:236.25pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image011.jpg" o:href="http://blog.csdn.net/images/blog_csdn_net/glchengang/97615/r_20050217image010.jpg" /> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

 

以后如果要引入myspring/lib/lib目录下的第三方包,也按方法二较好:将第三方包的目录复制到myspring/lib下,再参照方法二,将其加入库引用中即可

4、设置日志包的库引用

jakarta-commonslog4j包主要是做为Spring的运行时输出log(日志)用,如果不设置日志包,那么日志就没法输出到控制台,不利于开发和调试。设置方式如下:

1)就照上面的方法,放myspring/lib/lib目录下的log4j目录和jakarta-commons目录往上移一层到myspring/lib目录下。最后设置的结果如下图所示,这里我们把log4j移到了others目录,因为log4j就一个JAR包,专门为它象jakarta-commons创建一个目录和用户库太不值了,以后可能还会有这种引用单个包的时候,到时都放到others目录里好了。

<!--[if gte vml 1]><v:shape id="_x0000_i1035" type="#_x0000_t75" alt="" style='width:384.75pt;height:464.25pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image012.jpg" o:href="http://blog.csdn.net/images/blog_csdn_net/glchengang/97615/r_20050217image011.jpg" /> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

2)日志的库引用完成之后,还要创建一个日志的配置文件:log4j.properties,其文件内容如下:

log4j.rootLogger=DEBUG, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%c{1} - %m%n

 

log4j.properties文件的创建位置在src目录下,如下图所示:

<!--[if gte vml 1]><v:shape id="_x0000_i1036" type="#_x0000_t75" alt="" style='width:193.5pt;height:111pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image014.jpg" o:href="http://blog.csdn.net/images/blog_csdn_net/glchengang/97615/r_20050217image012.jpg" /> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

 

如果没有设置日志设置或设置不对,在使用控制台时会出现下面所示的红字。

java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

 

分享到:
评论

相关推荐

    spring 下载与配置

    以上就是关于Spring框架的下载与配置的基本介绍。在实际开发中,我们还需要考虑如何整合其他Spring项目,如Spring MVC用于构建Web应用,Spring Data用于数据库操作,以及Spring Boot用于简化Spring应用的初始搭建和...

    Spring下载与配置.pdf

    《Spring框架的下载与配置详解》 Spring框架是Java开发中的核心组件,它提供了丰富的功能,包括依赖注入、面向切面编程、数据访问、事务管理等。本文将详细介绍如何下载和配置Spring框架。 首先,Spring框架的下载...

    Spring下载与配置[整理].pdf

    本文将详细介绍如何下载并配置Spring框架。 首先,你可以通过访问Spring的官方网站下载页面(http://www.springframework.org/download.html)来获取Spring框架。在提供的链接中,有两个版本可供选择:spring-...

    spring配置 spring配置 spring配置 spring配置 spring配置

    spring配置 spring配置 spring配置 spring配置 spring配置

    ssm配置spring配置

    ssmspring配置ssmspring配置ssmspring配置ssmspring配置ssmspring配置ssmspring配置ssmspring配置ssmspring配置ssmspring配置ssmspring配置ssmspring配置ssmspring配置ssmspring配置ssmspring配置ssmspring配置ssm...

    SpringCloud——分布式配置中心(Spring Cloud Config)

    Spring Cloud Config 可以与 Spring Security 集成,对配置进行加密和解密。同时,可以限制哪些用户或服务有权访问配置信息。 **七、高可用配置中心** 为了提高配置中心的可用性,我们可以部署多个 Config Server ...

    spring bean XML配置入门

    虽然这个教程不提供Maven构建步骤,但通常我们需要在`pom.xml`文件中声明Spring相关的依赖,Maven会自动下载并管理这些库。例如: ```xml &lt;groupId&gt;org.springframework &lt;artifactId&gt;spring-context ...

    Spring动态加载配置文件

    接下来,一旦检测到Spring配置文件发生变化,我们需要重新加载配置文件。这可以通过Spring的`ApplicationContext`的`refresh()`方法来实现。`refresh()`会重新初始化Bean工厂,读取新的配置信息,并更新所有Bean的...

    Spring配置加注释

    Spring配置 Spring 配置 映射 加注释!!!!Spring配置 Spring 配置 映射 加注释!!!!

    Spring Cloud配置中心获取不到最新配置信息的问题

    解决这个问题的关键是了解配置中心的工作机制特别是与基于VCS的backend(如Git、SVN)相关的配置。 Spring Cloud Config 使用基于VCS的backend来存储配置信息,在默认情况下,配置信息会被checkout或clone到本地文件...

    SpringRedis哨兵配置

    SpringRedis哨兵配置,包括RedisTemplete、CacheManger

    Spring配置文件集合

    在本压缩包中,我们找到了一系列与Spring相关的配置文件,这些文件在构建JavaWeb应用时起着至关重要的作用。 1. `jdbc.properties`: 这个文件通常用于存储数据库连接的相关信息,如URL、用户名、密码等。它是Spring...

    spring配置文件实例

    spring配置文件实例

    Spring项目主配置文件

    初学Spring的小伙伴,还在为找不到主配置文件而着急吗,该配置文件是基于Spring4.10版本的,不用再自己到官网页面上到处找了,分享给大家,也希望大家别再像我一样因为这个坑耽误了大半天的时间,如果要自己配置也...

    spring配置文件

    spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件spring配置文件...

    springCloud分布式配置中心

    本demo springCloud版本为1.5.9,...本项目使用本地分布式配置(非git远程配置),启动顺序为服务注册中心(discovery)、配置中心(confugure)、微服务(micro-server),配置文件ip需修改为你自己的ip或localhost。

    spring配置文件详解

    Spring 配置文件详解 Spring 配置文件是 Spring 框架中最重要的配置文件之一,它负责定义和配置应用程序的Bean对象,以及它们之间的依赖关系。Spring 配置文件通常以XML文件的形式存在,文件名通常为...

    springcloud配置中心个人demo

    5. **环境与标签**:在配置中,可以使用 `label` 来指定 Git 分支,如 `master` 或者特定的版本分支。`profile` 用于区分不同的环境,如 `dev`、`test` 和 `prod`。 6. **Spring Cloud Bus**:在某些示例中,可能会...

    Spring cloud的配置中心

    对Spring cloud的配置中心如何配置进行指导,包括Spring boot和Spring mvc

Global site tag (gtag.js) - Google Analytics