spring容器启动
程序员文章站
2022-06-10 20:05:05
...
什么时候spring容器启动?
其实就是程序中执行加载 xml配置文件的时候
- 1.应用程序下加载
ApplicationContext ctx = new ClassPathXmlApplicationContext("testspring2.xml");
- 2.web模式下加载
web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-hibernate-mysql.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
可以看日志,每次执行new ClassPathXmlApplicationContext(),都会显示下面日志:
程序执行到: new ClassPathXmlApplicationContext("testspring2.xml"); |
2010-5-29 0:48:48 org.springframework.context.support.AbstractApplicationContext prepareRefresh 先刷新ApplicationContext,调用AbstractApplicationContext类的 prepareRefresh 注: AbstractApplicationContext是 ClassPathXmlApplicationContext的父类 public abstract class AbstractApplicationContext extends DefaultResourceLoader implements ConfigurableApplicationContext, DisposableBean { |
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@bf32c: display name [org.springframework.context.support.ClassPathXmlApplicationContext@bf32c]; startup date [Sat May 29 00:48:48 CST 2010]; root of context hierarchy |
2010-5-29 0:48:48 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from class path resource [testspring.xml] 开始加载spring配置文件,调用xml.XmlBeanDefinitionReader类的loadBeanDefinitions方法进行加载 注意:spring 和 hibernate 常见的错误之一,经常在读取xml文件时出现语法和格式的错误,如DTD错误等.多数是使用者自己在书写xml时犯的语法错误,但也有一些是hibernate和 spring不同版本的BUG |
2010-5-29 0:48:48 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory 信息: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@bf32c]: org.springframework.beans.factory.support.DefaultListableBeanFactory@af8358 2010-5-29 0:48:48 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons 获得缺省的工厂对象,spring缺省的工厂对象是 DefaultListableBeanFactory.preInstantiateSingletons |
信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@af8358: defining beans [personServiceBean]; root of factory hierarchy 最后为所有xml文件中定义(以及采用标注方式定义)的bean建立实例 |
上一篇: 女性气血不足易衰老 按摩穴位调血气
下一篇: 耳鸣怎么办 中医四法治疗最见效