`
z_jiankun
  • 浏览: 159838 次
  • 性别: 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

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics