org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'userAction' ...
Caused by: org.springframework.beans.BeanInstantiationException:
Could not instantiate bean class [com.ssh2.action.UserAction] ...
Caused by: java.lang.NullPointerException
at org.apache.struts2.ServletActionContext.getResponse(...)
at com.ssh2.action.UserAction.<init>(UserAction.java:20)
配置文件中 <bean id="dlDaoImp" class="..."/>,但在引用時寫成 ref="DlDaoImp"。Spring 默認**區分大小寫**,導致找不到定義,注入失敗,Action 構造器中使用 ServletActionContext.getResponse() 時上下文未就緒拋出 NPE。
<bean id="dlDaoImp" class="..."/>
<property name="dao" ref="dlDaoImp"/> <!-- 統一小寫 -->
AnnotationConfigApplicationContext 掃描包路徑,減少 XML 手寫錯誤。