1. 程式人生 > >啟動tomcat伺服器報錯Context initialization failed

啟動tomcat伺服器報錯Context initialization failed

嚴重: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.annotation.internalAsyncAnnotationProcessor' defined in org.springframework.scheduling.annotation.ProxyAsyncConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor]: Factory method 'asyncAdvisor' threw exception; nested exception is java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)

at 。。。。。。。

   解決方法:在springmvc.xml配置檔案中 將<context:component-scanbase-package="*"/>

改為自己的專案類檔案所在的路徑 如:<context:component-scan base-package="com.srpingmvc.*">

--------------------以下進行解釋---------------------------------------

下面我們來看一下springmvc.xml檔案,瞭解一下為何這樣改

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"

xsi:schemaLocation="http://www.springframework.org/schema/beans

                            http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context

                            http://www.springframework.org/schema/context/spring-context-4.3.xsd">

<!--  配置 @Controller @Service-->
<context:component-scan
base-package="com.srpingmvc.*"></context:component-scan>
<!-- 檢視解析器  邏輯檢視,物理檢視-->
<bean class= "org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value= ".jsp"></property>
</bean>

</beans>

配置檔案中base-package="com.srpingmvc.*" 是指com.springmvc資料夾下的所有檔案都會被掃描,掃描的目的在於

將帶有特定註解的類如@Controller @component #repository等等,作為Bean註冊進Spring容器。

以下為轉載自: http://blog.csdn.net/zzjjiandan/article/details/22922847

Spring配置檔案是用於指導Spring工廠進行Bean生產、依賴關係注入(裝配)及Bean例項分發的"圖紙"。

Java EE程式設計師必須學會並靈活應用這份"圖紙"準確地表達自己的"生產意圖"。

Spring配置檔案是一個或多個標準的XML文件,applicationContext.xml是Spring的預設配置檔案,

當容器啟動時找不到指定的配置文件時,將會嘗試載入這個預設的配置檔案。

下面列舉的是一份比較完整的配置檔案模板,文件中各XML標籤節點的基本用途也給出了詳細的解釋,

這些XML標籤節點在後續的知識點中均會用到,熟練掌握了這些XML節點及屬性的用途後,

為我們動手編寫配置檔案打下堅實的基礎。