zoukankan      html  css  js  c++  java
  • eclipse之SSH配置spring【二】

    第一篇中配置struts完成(http://www.cnblogs.com/dev2007/p/6475074.html),在此基础上,继续配置spring。

    web.xml中增加listener,依然在节点web-app中。

    <listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>classpath:applicationContext.xml</param-value>
    	</context-param>
    

     Tip:applicationContext.xml是后面在src目录自己建立的spring的配置文件。

    struts.xml中增加constant,指定spring为objectFactory,增加在struts节点中第一行,同时修改action的class为applicationContext.xml中配置的别名。

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.3.dtd">
    <struts>
    	<constant name="struts.objectFactory" value="spring" />
    	<package name="default" namespace="/" extends="struts-default">
    		<default-action-ref name="index"></default-action-ref>
    		<action name="index" class="homeAction">
    			<result>/WEB-INF/views/index.jsp</result>
    		</action>
    		<action name="search" class="searchAction">
    			<result>/WEB-INF/views/result.jsp</result>
    		</action>
    	</package>
    </struts>
    

     src目录中增加applicationContext.xml文件,配置相应类的别名和引用对象等的注入对象。

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans  
                   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    	<bean id="homeAction" class="com.awu.actions.HomeAction" scope="prototype">
    	</bean>
    	<bean id="searchAction" class="com.awu.actions.SearchAction"
    		scope="prototype">
    	</bean>
    </beans>
    

     最后,最重要的WEB-INF的lib中需要添加的必需jar。

    • spring-asm-3.0.5.RELEASE.jar
    • spring-beans-3.0.5.RELEASE.jar
    • spring-context-3.0.5.RELEASE.jar
    • spring-core-3.0.5.RELEASE.jar
    • spring-expression-3.0.5.RELEASE.jar
    • spring-web-3.0.5.RELEASE.jar
    • struts2-spring-plugin-2.3.24.1.jar
  • 相关阅读:
    IOS开发--网络篇-->GCD(Grand Central Dispatch)的详解
    drf viewset
    12.6 drf 结构化组建
    12.5
    12.4
    12.3
    12.2
    12.1 angular vue react web前端三大主流框架的对比
    11.30
    11.28 过滤器的相关操作
  • 原文地址:https://www.cnblogs.com/dev2007/p/6477268.html
Copyright © 2011-2022 走看看