Since I have just started learning spring, my understanding of it is not very thorough. From my personal point of view, it is enough to be able to use it for mvc development.
Goal: Be able to integrate the spring framework into the development environment.
Tools: eclipse + spring2.5.6
Steps: 1. Download eclipse or myeclipse from the Internet according to personal preference.
2. Download spring 2.5.6 (the highest version currently is 3.0) and go to the spring official website to download http://www.springsource.org/download . Note: before downloading
Personal information is required. To download the spring-framework-2.5.6-with-dependencies version
3. Unzip spring. Spring requires two jar files to run
spring.jar (under the dist directory)
commons-logging.jar (under the libjakarta-commons directory)
4. The next step is to use eclipse to create a project (either java or web project)
5. Add the above two jar files into the project.
6. Test whether the integration is successful
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");
}
}
Observe the console output
Correct output:
view plaincopy to clipboardprint?
2009-12-30 9:03:28 org.springframework.context.support.AbstractApplicationContext prepareRefresh
Message: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@ecd7e : 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
Message: Loading XML bean definitions from class path resource [applicationContext.xml]
2009-12-30 9:03:28 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
Information: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@ecd7e]: org.springframework.beans.factory.support.DefaultListableBeanFactory@60e128
2009-12-30 9:03:28 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
Message: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@60e128 : defining beans []; root of factory hierarchy
2009-12-30 9:03:28 org.springframework.context.support.AbstractApplicationContext prepareRefresh
Message: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@ecd7e : 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
Message: Loading XML bean definitions from class path resource [applicationContext.xml]
2009-12-30 9:03:28 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
Information: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@ecd7e]: org.springframework.beans.factory.support.DefaultListableBeanFactory@60e128
2009-12-30 9:03:28 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
Message: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@60e128 : defining beans []; root of factory hierarchy
If you do not reference commons-logging.jar, the following error message will be output
view plaincopy to clipboardprint?
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:145)
at org.springframework.context.support.AbstractRefreshableApplicationContext.<init>(AbstractRefreshableApplicationContext.java:84)
at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.<init>(AbstractRefreshableConfigApplicationContext.java:59)
at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:58)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:136)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at my.sh.spring.springtest.main(springtest.java:9)
This article comes from the CSDN blog. Please indicate the source when reprinting: http://blog.csdn.net/msjqd/archive/2009/12/30/5103718.aspx
-