spring 框架使用初步
作者:互联网
2009-12-30
由于刚刚开始学习spring,对于他的理解也不是非常的透彻,从我个人的角度来说,能够使用他进行mvc开发就已经足够了。
目标:能够把spring框架集成到开发环境中。
工具:eclipse + spring2.5.6
步骤:1、下载eclipse 或者是myeclipse 根据个人喜好从网上下载。
2、下载spring2.5.6(目前最高版本是3.0) 到spring官方网站下载 。注意:下载前
需要填写个人资料。要下载spring-framework-2.5.6-with-dependencies版本
3、解压spring。spring要运行必须需要两个jar文件
spring.jar(dist目录下面)
commons-logging.jar(libjakarta-commons目录下面)
4、接下来就是使用eclipse建立一个工程(java 或者 web工程都可以)
5、把上面的两个jar文件添加进入工程中。
6、测试是否集成成功
view plaincopy to clipboardprint?
package my.sh.spring;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class springtest {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
}
}
package my.sh.spring;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class springtest {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
}
}
观察控制台输出
正确输出:
view plaincopy to clipboardprint?
2009-12-30 9:03:28 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing : display name [org.springframework.context.support.ClassPathXmlApplicationContext@ecd7e]; startup date [Wed Dec 30 09:03:28 CST 2009]; root of context hierarchy
2009-12-30 9:03:28 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [applicationContext.xml]
2009-12-30 9:03:28 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
信息: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@ecd7e]:
2009-12-30 9:03:28 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in : defining beans []; root of factory hierarchy
2009-12-30 9:03:28 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing : display name [org.springframework.context.support.ClassPathXmlApplicationContext@ecd7e]; startup date [Wed Dec 30 09:03:28 CST 2009]; root of context hierarchy
2009-12-30 9:03:28 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [applicationContext.xml]
2009-12-30 9:03:28 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
信息: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@ecd7e]:
2009-12-30 9:03:28 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in : defining beans []; root of factory hierarchy
如果你没有引用 commons-logging.jar ,会输出如下错误提示
view plaincopy to clipboardprint?
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.context.support.AbstractApplicationContext.
at org.springframework.context.support.AbstractRefreshableApplicationContext.
at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.
at org.springframework.context.support.AbstractXmlApplicationContext.
at org.springframework.context.support.ClassPathXmlApplicationContext.
at org.springframework.context.support.ClassPathXmlApplicationContext.
at my.sh.spring.springtest.main(springtest.java:9)
本文来自CSDN博客,转载请标明出处:
-
相关标签:
相关推荐
专题
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
最新数据
相关文章
修改 Delphi 10.3.3 IDE 字体和字体大小
Delphi 3.0中连接数据库的三种方式
Oralce 调用Delphi写DLL去访问C# WebService的问题
一个C++及Delphi做的压缩程序
怎样在C#中调用Delphi6写的DLL
关于C#下写的Web Service 服务在Delphi下调用时的问题
在Delphi中的Access技巧集
传递和返回数据到一个Delphi编写的UDF
如何用Delphi和Web Services开发短信应用程序
如何用Delphi实现StringTokenizer功能
AI精选
