<1>[color=orange]S2SH web.xml内加载beans.xml配置出现了找不到jdbc.properties文件,问题如下:[/color]
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/jdbc.properties]
...
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/jdbc.properties]
web.xml内配置监听器加载:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- <param-value>/WEB-INF/applicationContext*.xml</param-value>-->
<param-value>classpath:beans.xml</param-value>
</context-param>
第一反应是<param-value>内的值,即struts默认加载为WEB-INF下的一些配置文件,但是我不可能把jdbc.properties写到<param-value>内,找到beans.xml 找到
<beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>jdbc.properties</value>
</property>
</bean>
修改为:classpath:jdbc.properties 问题解决。
<2>[color=orange] 在struts2与spring整合的时候,struts2在初始化时候对相应的Action内部属性进行注入(从spring容器内进行匹配)操作,而sturts2-spring-pligin里struts.objectfactory.spring.autowire 内装配是默认以名称来:[/color]
故Action在spring容器内的名称尽量不要与其某属性的名称相同,否则会出现无法转换诡异错误。
[color=red][size=medium] 实际上Action对象的产生是由strut2的 sturts2-spring-plugin 来管理的,但是其内部属性如UserManager之类是由插件从spring容器内部注入的,强制性 。。。也即strut2这边也有个专门存放Action的容器 ,由插件产生。。。[/size][/color]
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/jdbc.properties]
...
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/jdbc.properties]
web.xml内配置监听器加载:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- <param-value>/WEB-INF/applicationContext*.xml</param-value>-->
<param-value>classpath:beans.xml</param-value>
</context-param>
第一反应是<param-value>内的值,即struts默认加载为WEB-INF下的一些配置文件,但是我不可能把jdbc.properties写到<param-value>内,找到beans.xml 找到
<beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>jdbc.properties</value>
</property>
</bean>
修改为:classpath:jdbc.properties 问题解决。
<2>[color=orange] 在struts2与spring整合的时候,struts2在初始化时候对相应的Action内部属性进行注入(从spring容器内进行匹配)操作,而sturts2-spring-pligin里struts.objectfactory.spring.autowire 内装配是默认以名称来:[/color]
故Action在spring容器内的名称尽量不要与其某属性的名称相同,否则会出现无法转换诡异错误。
[color=red][size=medium] 实际上Action对象的产生是由strut2的 sturts2-spring-plugin 来管理的,但是其内部属性如UserManager之类是由插件从spring容器内部注入的,强制性 。。。也即strut2这边也有个专门存放Action的容器 ,由插件产生。。。[/size][/color]
本文解决了S2SH(web.xml)中加载beans.xml配置时找不到jdbc.properties的问题,并讨论了Struts2与Spring整合时Action内部属性注入可能出现的错误。

被折叠的 条评论
为什么被折叠?



