1. 程式人生 > >java.lang.IllegalStateException: Failed to load ApplicationContext

java.lang.IllegalStateException: Failed to load ApplicationContext

error for IT location method 錯誤 int pac 博客

java Spring AOP編寫MAVEN項目,編譯時出現錯誤提示如下:

java.lang.IllegalStateException: Failed to load ApplicationContext

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘customerService‘ defined in class path resource [applicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0‘: Cannot resolve reference to bean ‘mycut‘ while setting bean property ‘pointcut‘; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘mycut‘: Failed to introspect bean class [org.springframework.aop.aspectj.AspectJExpressionPointcut] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

剛開始以為是

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:applicationContext.xml")

路徑配置問題,

後來發現D:\Program Files\apache-maven-3.2.3\conf\settings.xml文件中<mirrors>配置有問題:

<!-- 使用私服倉庫,加上以下語句 -->

<!-- 若要使用網絡(官網中央倉庫),就註釋掉,默認沒有該語句,不用添加就行了 -->
<mirror>
<id>my</id>
<mirrorOf>*</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>私服倉庫地址</url>
</mirror>

即使更改過來後還是報同樣的錯誤,原因:

jar包一旦出現下載錯誤,則會在repository文件夾中生成.lastUpdated文件.

必須在D:\Program Files\apache-maven-3.2.3\repository中查找並刪掉對應的.lastUpdated文件,才會重新從中央倉庫中下載,否則是下載不了的.

批刪除.lastUpdated文件小技巧: 創建cleanLastUpdated.bat文件雙擊運行即可.

文件內容如下:

set REPOSITORY_PATH=D:\Program Files\apache-maven-3.2.3\repository
rem 正在搜索...
for /f "delims=" %%i in (‘dir /b /s "%REPOSITORY_PATH%\*lastUpdated"‘) do (
del /s /q %%i
)
rem 搜索完畢
pause

<!-- 初學者,第一次發表博客,若有不當之處還請見諒! -->

java.lang.IllegalStateException: Failed to load ApplicationContext