在ssh框架整合的时候,尽管你按照官方网站上的做法一步一步的整合了struts2,hibernate,spring,但是当你运行的时候,还是经常会出现一个异常,那就是Unable to instantiate Action。此异常表达的意思很明显,那就是不能初始化你的action。而出现以下异常,普遍都是因为以下原因:
一、在web.xml中没有配置spring的监听器或者没有配置spring配置文件的路径,从而造成spring中的bean不能被初始化。配置如下:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:/applicationContext.xml,
classpath*:/applicationContext-shiro.xml
</param-value>
</context-param>
二、如果你配置上面所说的,问题还没有解决的话,那原因有可能是你的service和dao的注入没有成功,这时候可以检查你的代码。如果你使用的是annotation的话,注意在spring配置文件中记得配置scan文件夹,这样你的bean才能被初始化。
<context:annotation-config />
<context:component-scan base-package="com.note" />
希望能够帮助到你!!!