`

2010.06.23——— spring+struts2.0配置

阅读更多
2010.06.23——— spring+struts2.0配置

web.xml

<?xml version="1.0" encoding="utf-8"?>
<web-app version="2.5" 
 xmlns="http://java.sun.com/xml/ns/javaee" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 
 <!-- 配置spring的监听器 -->
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 <!-- 配置spring的监听器 -->

 <!-- spring的applicationContext载入 -->
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml</param-value>
 </context-param>
 <!-- spring的applicationContext载入 -->
 
 
  <!-- 这里用的是spring自带的编码过滤器。 -->
 <filter>
  <filter-name>encodingFilter</filter-name>
  <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  <init-param>
   <param-name>encoding</param-name>
   <param-value>utf-8</param-value>  
  </init-param>
  <init-param>
   <param-name>forceEncoding</param-name>
   <param-value>true</param-value>
  </init-param>
 </filter>
 
 <filter-mapping>
  <filter-name>encodingFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping> 
 <!-- 这里用的是spring自带的编码过滤器。 -->

 
 <!-- struts2配置 -->
 <filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
 </filter>
 
 <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>


 <!--  
  web应用关闭时IntrospectorCleanupListener类负责对javabean
  内省缓存进行清除;该类实现接口ServletContextListener,
  对缓存在context中的javabean类进行清除操作的。
  -->
 <listener>
  <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
 </listener>
 
    
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>




applicationContext.xml spring配置文件



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	     xmlns:aop="http://www.springframework.org/schema/aop"
	     xmlns:tx="http://www.springframework.org/schema/tx"
	     xmlns:context="http://www.springframework.org/schema/context"
	     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
           default-autowire="byName"> 
	<!-- 数据库外部文件配置 -->
	<bean
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:db.properties</value>
			</list>
		</property>
		<property name="fileEncoding" value="utf-8" />
	</bean>
	<!-- 数据库外部文件配置 -->

	<!-- 配置数据源  -->
	<bean id="dataSource"
		class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName"
			value="${jdbc.driverClassName}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
	</bean>

	<!-- 配置数据源  -->
	 
	<!-- jdbcTemplate -->
	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource"><ref bean="dataSource"/></property>
	</bean>
	<!-- jdbcTemplate -->
	
	<!-- transactionManager -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"></property>
	</bean>
	<!-- transactionManager -->
	
	<!-- dao -->
	
	<!-- 行政编码dao -->
	<bean id="GC_RGNCDDao" class="dao.imp.GC_RGNCDDaoImp">
		<property name="jdbcTemplate">
			<ref bean="jdbcTemplate"/>
		</property>
	</bean>
	
	<!-- dao -->
	
	<!-- service -->
	
	<!-- 行政编码service -->
	<bean id="GC_RGNCDService" class="service.imp.GC_RGNCDServiceImp">
		<property name="GC_RGNCDDao">
			<ref bean="GC_RGNCDDao"/>
		</property>
	</bean>
	
	<!-- service -->
	
</beans>  


struts.xml struts2的配置文件

<?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.0.dtd">
<struts>
	<constant name="struts.i18n.encoding" value="utf-8"></constant>
	<!-- extends说明该配置文件继承自struts-default.xml -->
	<package name="action" extends="struts-default">
		<!-- action 的 name属性是必需的,其他属性都是可选的。 -->
		<!-- 工程信息查询(类别)Action -->
		<action name="initGongChengXinXi" class="action.GongChengXinXiChaXun_LieBieAction" method="initGongChengXinXi">
			<result >gongchengxinxichaxun/new3.jsp</result>
		</action>
		<!-- 工程信息查询(类别)Action -->
		
	</package>
	
	<!-- ajax struts ajax的配置
	<package name="sajax" extends="json-default" namespace="/ajax">
        <action name="getAllAddSort" method="getAllAddSort" class="action.AddListSortAction2">
            <result type="json" >
				<param name="root">str</param>
			</result>
        </action>
        <action name="getAddressListBySortId" method="getAddressListBySortId" class="action.AddListSortAction2">
            <result type="json" >
				<param name="root">str2</param>
			</result>
        </action>
        <action name="getAllMsgMould" method="getAllMsgMould" class="action.AddListSortAction2">
            <result type="json" >
				<param name="root">str3</param>
			</result>
        </action>
    </package>	
	ajax -->
</struts>

   
 
dao里面注入jdbcTemplage,service里面注入dao

在action里面用service时,也不需要注入了 只需要action类里面的service的名字和spring配置文件里面的一致 再加上get set方法 就可以了





分享到:
评论

相关推荐

    spring2.5+struts2.0+hibernate3.0例子 下载

    这个"Spring2.5+Struts2.0+Hibernate3.0例子"的压缩包文件,很可能是为了展示如何将这三个框架集成在一起,实现数据持久化、业务逻辑控制和视图呈现的无缝配合。开发者通常会在这个例子中找到配置文件(如web.xml、...

    spring-ssj.rar_spring_spring+Struts2+jpa集成

    Spring、Struts2和JPA是Java开发中常用的三大框架,它们各自负责应用程序的不同层面:Spring作为基础架构框架,提供依赖注入(DI)和面向切面编程(AOP)等功能;Struts2是一个用于构建MVC(Model-View-Controller)...

    struts2+spring+mybatis框架

    Struts2、Spring和MyBatis是Java Web开发中经典的三大框架,它们组合起来可以构建出高效、可维护的Web应用程序。以下是对这三个框架及其整合的详细解释。 **Struts2框架** Struts2是一个基于MVC(Model-View-...

    微信小程序——新闻客户端(截图+源码).zip

    微信小程序——新闻客户端(截图+源码).zip 微信小程序——新闻客户端(截图+源码).zip 微信小程序——新闻客户端(截图+源码).zip 微信小程序——新闻客户端(截图+源码).zip 微信小程序——新闻客户端(截图+...

    spring2.5 struts2.0 hibernate3.1

    标题 "spring2.5 struts2.0 hibernate3.1" 涉及到的是一个经典的Java企业级开发框架组合,通常被称为“SSH”(Spring、Struts和Hibernate)。这个组合在过去的许多年里被广泛应用,为构建高效、可维护的Web应用程序...

    Struts2.0中文教程权威版

    06 在Struts 2.0中实现表单数据校验(Validation) 07 Struts 2的基石——拦截器(Interceptor) 08 在Struts 2中实现IoC 09 在Struts 2中实现文件上传 10 在Struts 2中实现CRUD 11 Struts 2中的OGNL 12 trus 2的新...

    struts1.2+batis+spring2.0+oracle10g集成例子

    Struts1.2、Batis、Spring2.0和Oracle10g是经典的Java企业级应用框架和技术组合,常用于构建高效、可扩展的Web应用程序。这个集成例子旨在展示如何将这些组件协同工作,实现MVC(Model-View-Controller)架构、数据...

    java(spring+struts2+ibaits)整合框架

    1. **引入依赖**:在项目中引入Spring、Struts2和iBatis的相关库,并配置相应的Maven或Gradle依赖。 2. **配置Spring**:创建Spring的配置文件,定义Bean并进行依赖注入。可以配置数据源、事务管理器以及Struts2和...

    Vue2.0+ThreeJs写的一个3D粮仓管理系统源码.zip

    Vue2.0+ThreeJs写的一个3D粮仓管理系统源码,该项目基于ThreeJs+Vue2.0+Vue-Element+Admin实现了3D粮仓管理系统。 Vue2.0+ThreeJs写的一个3D粮仓管理系统源码,该项目基于ThreeJs+Vue2.0+Vue-Element+Admin实现了...

    spring cloud + vue + oAuth2.0全家桶实战,前后端分离商城源码.zip

    spring cloud + vue + oAuth2.0全家桶实战,前后端分离商城,完整的购物流程、后端运营平台,可以实现快速搭建企业级微服务项目。支持微信等三方登录。 spring cloud + vue + oAuth2.0全家桶实战,前后端分离...

    Struts2.0中文教程.chm

    12. **插件机制**:Struts2.0的插件架构允许开发者轻松扩展框架功能,如Spring插件可以整合Spring框架,Freemarker插件支持FreeMarker模板引擎。 通过学习Struts2.0中文教程,你可以掌握如何配置Struts2.0项目,...

    Eclipse+Struts2+Spring+MyBatis+jQuery整合教程

    Eclipse+Struts2+Spring+MyBatis+jQuery整合教程,Eclipse+Struts2+Spring+MyBatis+jQuery整合教程.

    轻量级J2EE+企业应用实战+Struts+Spring+Hibernate整合开发.pdf

    轻量级J2EE+企业应用实战+Struts+Spring+Hibernate整合开发.pdf

    一键ROOT工具+Easy+Rooting+Toolkit+v2.0.zip

    一键ROOT工具+Easy+Rooting+Toolkit+v2.0.zip

    Eclipse Java_EE整合spring+ struts2开发环境配置

    【Eclipse Java_EE 整合spring+ struts2开发环境配置】 在Java企业级开发中,Eclipse作为流行的集成开发环境(IDE),常被用于构建基于Java EE的应用程序。整合Spring框架和Struts2框架可以创建高效且可维护的Web...

    基于因子分析的我国A股上市...争力评价——以医药企业为例_张澳.caj

    基于因子分析的我国A股上市...争力评价——以医药企业为例_张澳.caj

    HCIE-Cloud+Service+Solutions+Architect+V2.0+实验手册.pdf

    华为HCIP考试学习资料,从官方内部获得的资料。HCIE-Cloud+Service+Solutions+Architect+V2.0+实验手册.pdf

    struts2.0教程合集

    此外,它可能还会讲解Struts2.0如何与Spring、Hibernate等其他框架集成,以实现更高效的开发。 "Struts2.0中文教程.zip"可能是一系列的教程集合,包含了Struts2.0的进阶主题,如动态方法调用(Dynamic Method ...

    struts2.0+freemarker实例.rar

    Struts2.0和FreeMarker是Java Web开发中常用的两个技术框架,它们分别负责MVC模式中的控制器和视图部分。Struts2.0作为一款强大的MVC框架,提供了丰富的功能来简化Web应用的开发,而FreeMarker则是一款模板引擎,...

    Jsp+servlet+spring+struts-API用户手册.zip

    在IT行业中,Web开发是至关重要的领域,而`JSP`、`Servlet`、`Spring`和`Struts`是构建高效、可扩展的企业级应用的基石。这些技术结合使用,能够实现强大的前后端交互,提供高效的数据处理和用户体验。 首先,`JSP ...

Global site tag (gtag.js) - Google Analytics