struts1 和Spring整合
struts1 和Spring整合:
1.(1)添加与Spring有关的jar包(spring.jar,log4j-1.2.9.jar、commons-logging.jar)
如果用Spring的AOPhuo则再填其相应的jar包
(2)对于Spring2.5以后的版本(本项目实际是Spring2.5.5版本)
主要涉及spring.jar、spring-webmvc-struts.jar和log4j-1.2.9.jar、commons-logging.jar
注意spring-webmvc-struts.jar文件的位置(spring-framework-2.5.5\dist\modules)
(3)添加log4j.properties
内容为:
log4j.rootLogger=INFO, stdout, logfile
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=StrutsSpringHibernateWeb.log
log4j.appender.logfile.MaxFileSize=512KB
# Keep three backup files.
log4j.appender.logfile.MaxBackupIndex=3
# Pattern to output: date priority [category] - message
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
如果log4j.properties不在WEB-INF/classes中(即不是右击src新建的)
比如在WEB-INF下:
在web.xml 文件中添加<context-param>标签以定位:
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
(4)在web.xml 文件中添加<listener>标签以添加Log4jConfigListener类
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener- class>
</listener>
2.在struts-config中的action 的type属性药改成Spring提供代理(固定的org.springframework.web.struts.DelegatingActionProxy)。
3.(2)再修改struts-config.xml配置文件以增加plugin的设置
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB- INF/classes/applicationContext.xml"/>//value值为设置了Spring的xml文件的路径
</plug-in>
4.在src的目录下新建applicationContext.xml文件
5.在spring的xml中 配置Action中
bean 中的name属性值为在struts-config中的action的path属性值。属性class值为action的包名+类名
<bean name="/adminForwordAction" scope="prototype" class="com.px1987.webbank.strutsaction.AdminForwordAction">
</bean>
struts1 和Spring整合:
1.(1)添加与Spring有关的jar包(spring.jar,log4j-1.2.9.jar、commons-logging.jar)
如果用Spring的AOPhuo则再填其相应的jar包
(2)对于Spring2.5以后的版本(本项目实际是Spring2.5.5版本)
主要涉及spring.jar、spring-webmvc-struts.jar和log4j-1.2.9.jar、commons-logging.jar
注意spring-webmvc-struts.jar文件的位置(spring-framework-2.5.5\dist\modules)
(3)添加log4j.properties
内容为:
log4j.rootLogger=INFO, stdout, logfile
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=StrutsSpringHibernateWeb.log
log4j.appender.logfile.MaxFileSize=512KB
# Keep three backup files.
log4j.appender.logfile.MaxBackupIndex=3
# Pattern to output: date priority [category] - message
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
如果log4j.properties不在WEB-INF/classes中(即不是右击src新建的)
比如在WEB-INF下:
在web.xml 文件中添加<context-param>标签以定位:
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
(4)在web.xml 文件中添加<listener>标签以添加Log4jConfigListener类
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener- class>
</listener>
2.在struts-config中的action 的type属性药改成Spring提供代理(固定的org.springframework.web.struts.DelegatingActionProxy)。
3.(2)再修改struts-config.xml配置文件以增加plugin的设置
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB- INF/classes/applicationContext.xml"/>//value值为设置了Spring的xml文件的路径
</plug-in>
4.在src的目录下新建applicationContext.xml文件
5.在spring的xml中 配置Action中
bean 中的name属性值为在struts-config中的action的path属性值。属性class值为action的包名+类名
<bean name="/adminForwordAction" scope="prototype" class="com.px1987.webbank.strutsaction.AdminForwordAction">
</bean>