1. 程式人生 > >Web專案使用Spring框架伺服器啟動載入xml檔案的過程學習

Web專案使用Spring框架伺服器啟動載入xml檔案的過程學習

個人在Tomcat簡單部署了一個web專案,console啟動日誌。

2015-9-13 20:36:39 org.apache.catalina.core.AprLifecycleListener init
資訊: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jdk1.6.0_45\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\DMIX;D:\Program Files\TortoiseSVN\bin;C:\Program Files\Java\jdk1.7.0_79\bin;D:\wls1036_dev\wlserver\common\bin;D:\Program Files (x86)\instantclient_11_2;.
2015-9-13 20:36:40 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:helloworld' did not find a matching property.
2015-9-13 20:36:40 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:springmvc' did not find a matching property.
2015-9-13 20:36:41 org.apache.coyote.http11.Http11Protocol init
資訊: Initializing Coyote HTTP/1.1 on http-8080
2015-9-13 20:36:41 org.apache.catalina.startup.Catalina load
資訊: Initialization processed in 2786 ms
2015-9-13 20:36:41 org.apache.catalina.core.StandardService start
資訊: Starting service Catalina
2015-9-13 20:36:41 org.apache.catalina.core.StandardEngine start
資訊: Starting Servlet Engine: Apache Tomcat/6.0.44
2015-9-13 20:36:42 org.apache.catalina.core.ApplicationContext log
資訊: Initializing Spring FrameworkServlet 'hello'
2015-9-13 20:36:42 org.springframework.web.servlet.DispatcherServlet initServletBean
資訊: FrameworkServlet 'hello': initialization started
2015-9-13 20:36:43 org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
資訊: Refreshing WebApplicationContext for namespace 'hello-servlet': startup date [Sun Sep 13 20:36:42 CST 2015]; root of context hierarchy
2015-9-13 20:36:43 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
資訊: Loading XML bean definitions from ServletContext resource [/WEB-INF/hello-servlet.xml]
2015-9-13 20:36:43 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
資訊: Pre-instantiating singletons in org.s

[email protected]83e1e: defining beans [welcomeController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.view.InternalResourceViewResolver#0,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
2015-9-13 20:36:44 org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
資訊: Mapped URL path [/hello] onto handler 'welcomeController'
2015-9-13 20:36:44 org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
資訊: Mapped URL path [/hello.*] onto handler 'welcomeController'
2015-9-13 20:36:44 org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
資訊: Mapped URL path [/hello/] onto handler 'welcomeController'
2015-9-13 20:36:44 org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
資訊: Mapped URL path [/welcome] onto handler 'welcomeController'
2015-9-13 20:36:44 org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
資訊: Mapped URL path [/welcome.*] onto handler 'welcomeController'
2015-9-13 20:36:44 org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
資訊: Mapped URL path [/welcome/] onto handler 'welcomeController'
2015-9-13 20:36:44 org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
資訊: Mapped URL path [/welcome.html] onto handler 'welcomeController'
2015-9-13 20:36:44 org.springframework.web.servlet.DispatcherServlet initServletBean
資訊: FrameworkServlet 'hello': initialization completed in 1830 ms
2015-9-13 20:36:44 org.apache.catalina.startup.HostConfig deployDescriptor
資訊: Deploying configuration descriptor host-manager.xml
2015-9-13 20:36:44 org.apache.catalina.startup.HostConfig deployDescriptor
資訊: Deploying configuration descriptor manager.xml
2015-9-13 20:36:44 org.apache.catalina.startup.HostConfig deployDirectory
資訊: Deploying web application directory docs
2015-9-13 20:36:44 org.apache.catalina.startup.HostConfig deployDirectory
資訊: Deploying web application directory examples
2015-9-13 20:36:45 org.apache.catalina.core.ApplicationContext log
資訊: ContextListener: contextInitialized()
2015-9-13 20:36:45 org.apache.catalina.core.ApplicationContext log
資訊: SessionListener: contextInitialized()
2015-9-13 20:36:45 org.apache.catalina.startup.HostConfig deployDirectory
資訊: Deploying web application directory ROOT
2015-9-13 20:36:45 org.apache.coyote.http11.Http11Protocol start
資訊: Starting Coyote HTTP/1.1 on http-8080
2015-9-13 20:36:45 org.apache.jk.common.ChannelSocket init
資訊: JK: ajp13 listening on /0.0.0.0:8009
2015-9-13 20:36:45 org.apache.jk.server.JkMain start
資訊: Jk running ID=0 time=0/53  config=null
2015-9-13 20:36:45 org.apache.catalina.startup.Catalina start
資訊: Server startup in 4039 ms
2015-9-13 20:39:28 org.springframework.web.servlet.PageNotFound noHandlerFound
警告: No mapping found for HTTP request with URI [/springmvc/welcome1] in DispatcherServlet with name 'hello'

spring框架版本:spring-framework-3.2.9.RELEASE

首先,說明一下console日誌的特殊之處,下面兩行是一條日誌。時間+類名+方法名+日誌級別+提示內容(這個日誌的配置檔案我還沒來得及查詢其位置,可能是Tomcat或Spring框架的jar包中,後期找到也分享出來)

瞭解控制檯日誌格式,對理解整個過程很有幫助。

2015-9-13 20:36:42 org.springframework.web.servlet.DispatcherServlet initServletBean
資訊: FrameworkServlet 'hello': initialization started


下面摘自:http://blog.csdn.net/zhulinu/article/details/7305247  寫得很不錯

ApplicationContext是Spring的核心,Context我們通常解釋為上下文環境,我想用“容器”來表述它更容易理解一些,ApplicationContext則是“應用的容器”了;在Web應用中,我們會用到WebApplicationContext,WebApplicationContext繼承自ApplicationContext;WebApplicationContext的初始化方式和BeanFactory.ApplicationContext有所區別,因為WebApplicationContext需要ServletContext例項,也就是說它必須擁有Web容器的前提下才能完成啟動的工作.有過Web開發經驗的讀者都知道可以在web.xml中配置自啟動的Servlet或定義Web容器監聽器(ServletContextListener),藉助著兩者中的任何一個,我們就可以啟動Spring Web應用上下文的工作.

Spring分別提供了用於啟動WebApplicationContext的Servlet和Web容器監聽器:

org.springframework.web.context.ContextLoaderServlet;

org.springframework.web.context.ContextLoaderListener.

這兩個方法都是在web應用啟動的時候來初始化WebApplicationContext,我個人認為Listerner要比Servlet更好一些,因為Listerner監聽應用的啟動和結束,而Servlet得啟動要稍微延遲一些,如果在這時要做一些業務的操作,啟動的前後順序是有影響的。

配置例子如下:
context-param> 
<param-name>contextConfigLocation</param-name> 
<param-value>/WEB-INF/applicationContext.xml</param-value> 
</context-param> 

<listener> 
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

那麼在ContextLoaderListener和ContextLoaderServlet中到底做了什麼呢? 
以ContextLoaderListener為例,我們可以看到 
public void contextInitialized(ServletContextEvent event) { 
this.contextLoader = createContextLoader(); 
this.contextLoader.initWebApplicationContext(event.getServletContext()); 

protected ContextLoader createContextLoader() { 
return new ContextLoader(); 

ContextLoader是一個工具類,用來初始化WebApplicationContext,其主要方法就是initWebApplicationContext,我們繼續追蹤initWebApplicationContext這個方法(具體程式碼我不貼出,大家可以看Spring中的原始碼),我們發現,原來ContextLoader是把WebApplicationContext(XmlWebApplicationContext是預設實現類)放在了ServletContext中,ServletContext也是一個“容器”,也是一個類似Map的結構,而WebApplicationContext在ServletContext中的KEY就是WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,我們如果要使用WebApplicationContext則需要從ServletContext取出,Spring提供了一個WebApplicationContextUtils類,可以方便的取出WebApplicationContext,只要把ServletContext傳入就可以了。 

相關推薦

Web專案使用Spring框架伺服器啟動載入xml檔案過程學習

個人在Tomcat簡單部署了一個web專案,console啟動日誌。 2015-9-13 20:36:39 org.apache.catalina.core.AprLifecycleListener init 資訊: The APR based Apache Tomcat

maven web專案部署在伺服器時出現無法載入css和js的問題

最近做一個往老專案中新增新功能的活,該專案是一個運用ssm框架做的maven專案,將老專案匯入自己的編輯器後添加了新的程式碼,部署在tomcat中,啟動伺服器,開啟瀏覽器發現頁面混亂,點選F12發現是沒有正常載入css和js檔案。經過長時間的檢查發現在root.css檔案頭部

AngularJS進階(三十九)基於專案實戰解析ng啟動載入過程

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!        

部署java-web專案到linux伺服器

記錄自己部署javaweb專案的基本操作以及遇到的坑 我用的是eclipse,匯出war包。 (這裡有個巨坑,eclipse有專案快取,所以你改的東西可能沒有用,tomcat伺服器也有快取,所以匯出的時候記得清一下快取) 在linux伺服器上安裝配置tomcat伺服器,把

在Java web專案springMVC框架中實現定時任務

在工作中遇到一個需求,需要定時自動執行某項功能,這就需要用到定時任務了。首先先來理一下實現思路,定時任務可以用Java.util中的timer類,把需要定時執行的任務封裝到timer類的排程表中,這個timer物件需要在程式初始化時建立,這樣才可以讓它自動執行。那麼我們就可以想到需要借用

關於mvnen專案下hibernate mybaits打包無法載入xml檔案

maven專案打包時,如果java目錄下有xml檔案,則打包時不會載入xml檔案,但是有時我們mybatis或hibernate的xml會寫在java目錄下。 解決方案: 在專案pom檔案build中加入如下配置即可解決問題 <resources>

Java web專案釋出,伺服器部署(完整版)

本文章只為幫助大家學習專案的釋出,為基礎篇,在此給大家示範在window環境下的專案部署及運維。 以下版本為講解示例,可自行改至匹配版本。 伺服器:window service2008 R2 Standard(提前準備好伺服器,可以在伺服器商家租伺服器,這裡就不過多講解了

AngularJS進階 三十九 基於專案實戰解析ng啟動載入過程

基於專案實戰解析ng啟動載入過程 前言       在AngularJS專案開發過程中,自己將遇到的問題進行了整理。回過頭來總結一下angular的啟動過程。       下面以實際專案為例進行簡要講解。 1.載入ng庫 &

spring框架之AspectJ基於xml和基於註解

AOP為Aspect Oriented Programming的縮寫,意為:面向切面程式設計,通過預編譯方式和執行期動態代理實現程式功能的統一維護的一種技術。AOP是OOP的延續,是軟體開發中的一個熱點,也是Spring框架中的一個重要內容,是函數語言程式設計的

本地專案部署到伺服器 啟動 報錯 資料表不存原因 解決

由於linux上mysql是區分大小寫的,所以導致本地存在的表,提示不存在   解決: 設定mysql 配置檔案 ,禁止區分大小寫   1.切換到root使用者,進入 /etc/mysql/mysql.conf.d目錄  2.開啟mysqld.cnf檔案,在【my

Spring框架啟動IOC容器的三種方式

前期準備工作 使用IDE:IDEA 建立專案時需要用到的框架有Java和Web 就像下圖的進行勾選。 建立專案完成之後的目錄 如下圖所示。 建立專案時,gradle中用到的依賴: // Java EE 通過本地Jar包

web專案前臺框架無法右擊檢視頁面原始碼

第一種是 在你想要檢視的網頁前面新增    view-source:  即可 舉例,view-source:http://localhost:8085/default.action

部署Python Web專案到CentOS伺服器踩過的坑

CentOS 沒有 apt-get 命令,也沒有easy-install 像centos這類衍生出來的發行版,他們的源有時候內容更新的比較滯後,或者說有時候一些擴充套件的源根本就沒有。所以在使用yum來search  python-pip的時候,會說沒有找到該軟體包。 安裝

spring 設定通過程式碼啟動載入配置檔案和設定啟動順序

通過這種方式載入可以使用maven模組化,拋開web.xml的束縛。 @Order(1) public class SpringConfigInitializer extends AbstractContextLoaderInitializer   implements

Spring 執行中 動態載入xml並例項化Bean

工作中總有各種各樣另類問題發生,比如像我遇到的需要動態載入指定jar檔案並例項化執行。拿到這個問題,主要問題就是 動態指定的jar檔案不存在於classpath中,如何讓Spring知道並引用 都知道jvm是通過classloader載入class,並且是

如何將Java web專案部署到伺服器

  學習Java 程式設計一年了, 下面就和大家一起分享一下如何將 java web 專案釋出到伺服器 使外網可以訪問          1.首先得有一臺伺服器, 可以購買也可以租          2.這裡拿租的伺服器為例:            下圖中的伺服器型別為wi

java web專案釋出到伺服器

環境的搭建請參考我之前的文章:https://blog.csdn.net/a1181986340/article/details/86087393   從eclipse中匯出war包,右鍵專案名,依次選擇 Export -- WAR file,選擇匯出位置,然後點選Finish

使用myeclipse搭建帶maven的ava web專案(Spring+SpringMVC+Mybatis)

環境說明:       開發環境:win7+Myclipase2015      專案屬性:使用maven的javaWeb專案      使用框架:Spring+SpringMVC+MyBatis      使用資料庫:sqlserver2008R2 建立專案:    建立

java web 專案 ssh框架使用中的 ClassNotFoundException 異常【找不到**Action】

對 visitAction 類進行了註解配置, 但是在訪問 visitAction 的時候,一直出現下面這個異常提示: 22:23:35,387 ERROR DefaultDispatcherErrorHandler:42 - Exception occurred dur

spring boot伺服器啟動報錯'spring.datasource.url' is not specified

報錯資訊'spring.datasource.url' is not specified and no embedded datasource could be auto-configured.原因資料庫沒有配置,在啟動的檔案的註解@SpringBootApplication