国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

directory search
前言 簡介 概覽 使用場景 Spring 2.0和 2.5的新特性 簡介 控制反轉(zhuǎn)(IoC)容器 新的bean作用域 更簡單的XML配置 可擴(kuò)展的XML編寫 Annotation(注解)驅(qū)動配置 在classpath中自動搜索組件 面向切面編程(AOP) 更加簡單的AOP XML配置 對@AspectJ 切面的支持 對bean命名pointcut( bean name pointcut element)的支持 對AspectJ裝載時織入(AspectJ load-time weaving)的支持 中間層 在XML里更為簡單的聲明性事務(wù)配置 對Websphere 事務(wù)管理的完整支持 JPA 異步的JMS JDBC Web層 Spring MVC合理的默認(rèn)值 Portlet 框架 基于Annotation的控制器 Spring MVC的表單標(biāo)簽庫 對Tiles 2 支持 對JSF 1.2支持 JAX-WS支持 其他 動態(tài)語言支持 增強(qiáng)的測試支持 JMX 支持 將Spring 應(yīng)用程序上下文部署為JCA adapter 計(jì)劃任務(wù) 對Java 5 (Tiger) 支持 移植到Spring 2.5 改變 支持的JDK版本 Spring 2.5的Jar打包 XML配置 Deprecated(淘汰)的類和方法 Apache OJB iBATIS Hibernate JDO UrlFilenameViewController 更新的樣例應(yīng)用 改進(jìn)的文檔 核心技術(shù) IoC(控制反轉(zhuǎn))容器 簡介 基本原理 - 容器和bean 容器 配置元數(shù)據(jù) 實(shí)例化容器 XML配置元數(shù)據(jù)的結(jié)構(gòu) 多種bean bean的命名 bean的別名 實(shí)例化bean 用構(gòu)造器來實(shí)例化 使用靜態(tài)工廠方法實(shí)例化 使用實(shí)例工廠方法實(shí)例化 使用容器 依賴 注入依賴 構(gòu)造器注入 構(gòu)造器參數(shù)解析 構(gòu)造器參數(shù)類型匹配 構(gòu)造參數(shù)索引 Setter注入 一些例子 依賴配置詳解 直接變量(基本類型、Strings類型等。) idref元素 引用其它的bean(協(xié)作者) 內(nèi)部bean 集合 集合的合并 強(qiáng)類型集合(僅適用于Java5+) Nulls XML配置文件的簡寫及其他 XML-based configuration metadata shortcuts 使用p名稱空間配置屬性 組合屬性名稱 使用depends-on 延遲初始化bean 自動裝配(autowire)協(xié)作者 將bean排除在自動裝配之外 依賴檢查 方法注入 Lookup方法注入 自定義方法的替代方案 Bean的作用域 Singleton作用域 Prototype作用域 Singleton beans和prototype-bean的依賴 其他作用域 初始化web配置 Request作用域 Session作用域 global session作用域 作用域bean與依賴 選擇創(chuàng)建代理的類型 自定義作用域 創(chuàng)建自定義作用域 使用自定義作用域 定制bean特性 生命周期回調(diào) 初始化回調(diào) 析構(gòu)回調(diào) 缺省的初始化和析構(gòu)方法 組合生命周期機(jī)制 在非web應(yīng)用中優(yōu)雅地關(guān)閉Spring IoC容器 了解自己 BeanFactoryAware BeanNameAware bean定義的繼承 容器擴(kuò)展點(diǎn) 用BeanPostProcessor定制bean 使用BeanPostProcessor的Hello World示例 RequiredAnnotationBeanPostProcessor示例 用BeanFactoryPostProcessor定制配置元數(shù)據(jù) PropertyPlaceholderConfigurer示例 PropertyOverrideConfigurer示例 使用FactoryBean定制實(shí)例化邏輯 The ApplicationContext BeanFactory 還是 ApplicationContext? 利用MessageSource實(shí)現(xiàn)國際化 事件 底層資源的訪問 ApplicationContext在WEB應(yīng)用中的實(shí)例化 粘合代碼和可怕的singleton 以J2EE RAR文件的形式部署Spring ApplicationContext 基于注解(Annotation-based)的配置 @Autowired 基于注解的自動連接微調(diào) CustomAutowireConfigurer @Resource @PostConstruct 與 @PreDestroy 對受管組件的Classpath掃描 @Component和更多典型化注解 自動檢測組件 使用過濾器自定義掃描 自動檢測組件的命名 為自動檢測的組件提供一個作用域 用注解提供限定符元數(shù)據(jù) 注冊一個LoadTimeWeaver 資源 簡介 Resource接口 內(nèi)置 Resource 實(shí)現(xiàn) UrlResource ClassPathResource FileSystemResource ServletContextResource InputStreamResource ByteArrayResource ResourceLoader接口 ResourceLoaderAware 接口 把Resource作為屬性來配置 Application context 和Resource 路徑 構(gòu)造application context 創(chuàng)建 ClassPathXmlApplicationContext 實(shí)例 - 簡介 Application context構(gòu)造器中資源路徑的通配符 Ant風(fēng)格的pattern 潛在的可移植性 classpath*: 前綴 其他關(guān)于通配符的說明 FileSystemResource 說明 校驗(yàn),數(shù)據(jù)綁定,BeanWrapper,與屬性編輯器 簡介 使用Spring的Validator接口進(jìn)行校驗(yàn) 從錯誤代碼到錯誤信息 Bean處理和BeanWrapper 設(shè)置和獲取屬性值以及嵌套屬性 內(nèi)建的PropertyEditor實(shí)現(xiàn) 注冊用戶自定義的PropertyEditor 使用PropertyEditorRegistrars 使用Spring進(jìn)行面向切面編程(AOP) 簡介 AOP概念 Spring AOP的功能和目標(biāo) AOP代理 @AspectJ支持 啟用@AspectJ支持 聲明一個切面 聲明一個切入點(diǎn)(pointcut) 切入點(diǎn)指示符(PCD)的支持 組合切入點(diǎn)表達(dá)式 共享通用切入點(diǎn)定義 示例 聲明通知 前置通知 后置通知(After returning advice) 異常通知(After throwing advice) 最終通知(After (finally) advice) 環(huán)繞通知 通知參數(shù)(Advice parameters) 訪問當(dāng)前的連接點(diǎn) 傳遞參數(shù)給通知 確定參數(shù)名 處理參數(shù) 通知順序 引入(Introduction) 切面實(shí)例化模型 例子 基于Schema的AOP支持 聲明一個切面 聲明一個切入點(diǎn) 聲明通知 前置通知 后置通知 異常通知 最終通知 環(huán)繞通知 通知參數(shù) 通知順序 引入 切面實(shí)例化模型 Advisor 例子 AOP聲明風(fēng)格的選擇 Spring AOP還是完全用AspectJ? Spring AOP中使用@AspectJ還是XML? 混合切面類型 代理機(jī)制 理解AOP代理 以編程方式創(chuàng)建@AspectJ代理 在Spring應(yīng)用中使用AspectJ 在Spring中使用AspectJ進(jìn)行domain object的依賴注入 @Configurable對象的單元測試 Working with multiple application contexts Spring中其他的AspectJ切面 使用Spring IoC來配置AspectJ的切面 在Spring應(yīng)用中使用AspectJ加載時織入(LTW) 第一個例子 切面 'META-INF/aop.xml' 相關(guān)類庫(JARS) Spring配置 特定環(huán)境的配置 通用Java應(yīng)用 Tomcat WebLogic 更多資源 Spring AOP APIs 簡介 Spring中的切入點(diǎn)API 概念 切入點(diǎn)運(yùn)算 AspectJ切入點(diǎn)表達(dá)式 便利的切入點(diǎn)實(shí)現(xiàn) 靜態(tài)切入點(diǎn) 正則表達(dá)式切入點(diǎn) 屬性驅(qū)動的切入點(diǎn) 動態(tài)切入點(diǎn) 控制流切入點(diǎn) 切入點(diǎn)的超類 自定義切入點(diǎn) Spring的通知API 通知的生命周期 Spring里的通知類型 攔截環(huán)繞通知 前置通知 異常通知 后置通知 引入通知 Spring里的Advisor API 使用ProxyFactoryBean創(chuàng)建AOP代理 基礎(chǔ) JavaBean屬性 基于JDK和CGLIB的代理 對接口進(jìn)行代理 對類進(jìn)行代理 使用“全局”通知器 簡化代理定義 使用ProxyFactory通過編程創(chuàng)建AOP代理 操作被通知對象 使用“自動代理(autoproxy)”功能 自動代理bean定義 BeanNameAutoProxyCreator DefaultAdvisorAutoProxyCreator AbstractAdvisorAutoProxyCreator 使用元數(shù)據(jù)驅(qū)動的自動代理 使用TargetSource 熱交換目標(biāo)源 池化目標(biāo)源 原型目標(biāo)源 ThreadLocal目標(biāo)源 定義新的Advice類型 更多資源 測試 簡介 單元測試 Mock對象 JNDI Servlet API Portlet API 單元測試支持類 通用工具類 Spring MVC 集成測試 概覽 使用哪個支持框架 通用目標(biāo) 上下文管理及緩存 測試fixtures依賴注入 事務(wù)管理 集成測試支持類 JDBC測試支持 常用注解 JUnit 3.8遺留支持 上下文管理及緩存 測試fixture依賴注入 字段級別(Field Level)注入 事務(wù)管理 JUnit 3.8 遺留支持類 Java 5+ 專有支持 使用注解的事務(wù)相關(guān)測試 JPA支持類 Spring TestContext Framework 主要的抽象 上下文管理和緩存 測試fixture的依賴注入 事務(wù)管理 TestContext支持類 JUnit 3.8支持類 JUnit 4.4支持類 定制JUnit 4.4運(yùn)行器 TestNG支持類 TestContext框架注解支持 PetClinic示例 更多資源 中間層數(shù)據(jù)訪問 事務(wù)管理 簡介 動機(jī) 關(guān)鍵抽象 使用資源同步的事務(wù) 高層次方案 低層次方案 TransactionAwareDataSourceProxy 聲明式事務(wù)管理 理解Spring的聲明式事務(wù)管理實(shí)現(xiàn) 第一個例子 回滾 為不同的bean配置不同的事務(wù)語義 <tx:advice/> 有關(guān)的設(shè)置 使用 @Transactional @Transactional 有關(guān)的設(shè)置 事務(wù)傳播 required RequiresNew Nested 通知事務(wù)操作 結(jié)合AspectJ使用 @Transactional 編程式事務(wù)管理 使用TransactionTemplate 指定事務(wù)設(shè)置 使用PlatformTransactionManager 選擇編程式事務(wù)管理還是聲明式事務(wù)管理 與特定應(yīng)用服務(wù)器集成 IBM WebSphere BEA WebLogic Oracle OC4J 常見問題的解決方法 對一個特定的 DataSource 使用了錯誤的事務(wù)管理器 更多的資源 DAO支持 簡介 一致的異常層次 一致的DAO支持抽象類 使用JDBC進(jìn)行數(shù)據(jù)訪問 簡介 選擇一種工作模式 Spring JDBC包結(jié)構(gòu) 利用JDBC核心類控制JDBC的基本操作和錯誤處理 JdbcTemplate類 一些示例 查詢(SELECT) 更新(INSERT/UPDATE/DELETE) 其他操作 JdbcTemplate 的最佳實(shí)踐 NamedParameterJdbcTemplate類 SimpleJdbcTemplate類 DataSource接口 SQLExceptionTranslator接口 執(zhí)行SQL語句 執(zhí)行查詢 更新數(shù)據(jù)庫 獲取自動生成的主鍵 控制數(shù)據(jù)庫連接 DataSourceUtils類 SmartDataSource接口 AbstractDataSource類 SingleConnectionDataSource類 DriverManagerDataSource類 TransactionAwareDataSourceProxy類 DataSourceTransactionManager類 NativeJdbcExtractor JDBC批量操作 使用JdbcTemplate進(jìn)行批量操作 使用SimpleJdbcTemplate進(jìn)行批量操作 通過使用SimpleJdbc類簡化JDBC操作 使用SimpleJdbcInsert插入數(shù)據(jù) 使用SimpleJdbcInsert來獲取自動生成的主鍵 指定SimpleJdbcInsert所使用的字段 使用SqlParameterSource提供參數(shù)值 使用SimpleJdbcCall調(diào)用存儲過程 聲明SimpleJdbcCall使用的參數(shù) 如何定義SqlParameters 使用SimpleJdbcCall調(diào)用內(nèi)置函數(shù) 使用SimpleJdbcCall返回的ResultSet/REF Cursor 用Java對象來表達(dá)JDBC操作 SqlQuery類 MappingSqlQuery類 SqlUpdate類 StoredProcedure類 SqlFunction類 參數(shù)和數(shù)據(jù)處理的基本原則 為參數(shù)設(shè)置SQL類型信息 處理BLOB 和 CLOB對象 在IN語句中傳入一組參數(shù)值 處理復(fù)雜類型的存儲過程調(diào)用 使用ORM工具進(jìn)行數(shù)據(jù)訪問 簡介 Hibernate 資源管理 在Spring容器中創(chuàng)建 SessionFactory The HibernateTemplate 不使用回調(diào)的基于Spring的DAO實(shí)現(xiàn) 基于Hibernate3的原生API實(shí)現(xiàn)DAO 編程式的事務(wù)劃分 聲明式的事務(wù)劃分 事務(wù)管理策略 容器資源 vs 本地資源 在應(yīng)用服務(wù)器中使用Hibernate的注意事項(xiàng) JDO 建立PersistenceManagerFactory JdoTemplate和JdoDaoSupport 基于原生的JDO API實(shí)現(xiàn)DAO 事務(wù)管理 JdoDialect Oracle TopLink SessionFactory 抽象層 TopLinkTemplate and TopLinkDaoSupport 基于原生的TopLink API的DAO實(shí)現(xiàn) 事務(wù)管理 iBATIS SQL Maps 創(chuàng)建SqlMapClient 使用 SqlMapClientTemplate 和 SqlMapClientDaoSupport 基于原生的iBATIS API的DAO實(shí)現(xiàn) JPA 在Spring環(huán)境中建立JPA LocalEntityManagerFactoryBean 從JNDI中獲取 EntityManagerFactory LocalContainerEntityManagerFactoryBean Tomcat(5.0以上)加載時的織入配置 使用VM代理的全局加載時織入 上下文范圍內(nèi)的加載時織入配置 處理多持久化單元 JpaTemplate 和 JpaDaoSupport 基于原生的JPA實(shí)現(xiàn)DAO 異常轉(zhuǎn)化 事務(wù)管理 JpaDialect The Web Web MVC framework Web框架 概述 與其他MVC實(shí)現(xiàn)框架的集成 Spring Web MVC框架的特點(diǎn) DispatcherServlet 控制器 AbstractController 和 WebContentGenerator 其它的簡單控制器 MultiActionController 命令控制器 處理器映射(handler mapping) BeanNameUrlHandlerMapping SimpleUrlHandlerMapping 攔截器(HandlerInterceptor) 視圖與視圖解析 視圖解析器(ViewResolver) 視圖解析鏈 重定向(Rediret)到另一個視圖 RedirectView redirect:前綴 forward:前綴 本地化解析器 AcceptHeaderLocaleResolver CookieLocaleResolver SessionLocaleResolver LocaleChangeInterceptor 使用主題 簡介 如何定義主題 主題解析器 Spring對分段文件上傳(multipart file upload)的支持 介紹 使用MultipartResolver 在表單中處理分段文件上傳 使用Spring的表單標(biāo)簽庫 配置 form標(biāo)簽 input標(biāo)簽 checkbox標(biāo)簽 checkboxes標(biāo)簽 radiobutton標(biāo)簽 radiobuttons標(biāo)簽 password標(biāo)簽 select標(biāo)簽 option標(biāo)簽 options標(biāo)簽 textarea標(biāo)簽 hidden標(biāo)簽 errors標(biāo)簽 處理異常 慣例優(yōu)先原則(convention over configuration) 對控制器的支持:ControllerClassNameHandlerMapping 對模型的支持:ModelMap(ModelAndView) 對視圖的支持:RequestToViewNameTranslator 基于注解的控制器配置 建立dispatcher實(shí)現(xiàn)注解支持 使用@Controller定義一個控制器 使用@RequestMapping映射請求 使用@RequestParam綁定請求參數(shù)到方法參數(shù) 使用@ModelAttribute提供一個從模型到數(shù)據(jù)的鏈接 使用@SessionAttributes指定存儲在會話中的屬性 自定義WebDataBinder初始化 使用@InitBinder自定義數(shù)據(jù)綁定 配置一個定制的WebBindingInitializer 更多資源 集成視圖技術(shù) 簡介 JSP和JSTL 視圖解析器 'Plain-old' JSPs versus JSTL 'Plain-old' JSP與JSTL 幫助簡化開發(fā)的額外的標(biāo)簽 Tiles 需要的資源 如何集成Tiles UrlBasedViewResolver類 ResourceBundleViewResolver類 SimpleSpringPreparerFactory 和 SpringBeanPreparerFactory Velocity和FreeMarker 需要的資源 Context 配置 創(chuàng)建模板 高級配置 velocity.properties FreeMarker 綁定支持和表單處理 用于綁定的宏 簡單綁定 表單輸入生成宏 輸入域 選擇輸入域 重載HTML轉(zhuǎn)碼行為并使你的標(biāo)簽符合XHTML XSLT 寫在段首 Bean 定義 標(biāo)準(zhǔn)MVC控制器代碼 把模型數(shù)據(jù)轉(zhuǎn)化為XML 定義視圖屬性 文檔轉(zhuǎn)換 小結(jié) 文檔視圖(PDF/Excel) 簡介 配置和安裝 文檔視圖定義 Controller 代碼 Excel視圖子類 PDF視圖子類 JasperReports 依賴的資源 配置 配置ViewResolver 配置View 關(guān)于報(bào)表文件 使用 JasperReportsMultiFormatView 構(gòu)造ModelAndView 使用子報(bào)表 配置子報(bào)表文件 配置子報(bào)表數(shù)據(jù)源 配置Exporter的參數(shù) 集成其它Web框架 簡介 通用配置 JavaServer Faces DelegatingVariableResolver FacesContextUtils Struts ContextLoaderPlugin DelegatingRequestProcessor DelegatingActionProxy ActionSupport Classes Tapestry 注入 Spring 托管的 beans 將 Spring Beans 注入到 Tapestry 頁面中 組件定義文件 添加抽象訪問方法 將 Spring Beans 注入到 Tapestry 頁面中 - Tapestry 4.0+ 風(fēng)格 WebWork 更多資源 Portlet MVC框架 介紹 控制器 - MVC中的C 視圖 - MVC中的V Web作用范圍的Bean DispatcherPortlet ViewRendererServlet 控制器 AbstractController 和 PortletContentGenerator 其它簡單的控制器 Command控制器 PortletWrappingController 處理器映射 PortletModeHandlerMapping ParameterHandlerMapping PortletModeParameterHandlerMapping 增加 HandlerInterceptors HandlerInterceptorAdapter ParameterMappingInterceptor 視圖和它們的解析 Multipart文件上傳支持 使用 PortletMultipartResolver 處理表單里的文件上傳 異常處理 Portlet應(yīng)用的部署 整合 使用Spring進(jìn)行遠(yuǎn)程訪問與Web服務(wù) 簡介 使用RMI暴露服務(wù) 使用RmiServiceExporter暴露服務(wù) 在客戶端鏈接服務(wù) 使用Hessian或者Burlap通過HTTP遠(yuǎn)程調(diào)用服務(wù) 為Hessian和co.配置DispatcherServlet 使用HessianServiceExporter暴露你的bean 在客戶端連接服務(wù) 使用Burlap 對通過Hessian或Burlap暴露的服務(wù)使用HTTP Basic認(rèn)證 使用HTTP調(diào)用器暴露服務(wù) Exposing the service object 在客戶端連接服務(wù) Web Services 使用JAX-RPC暴露基于servlet的web服務(wù) 使用JAX-RPC訪問web服務(wù) 注冊JAX-RPC Bean映射 注冊自己的JAX-RPC 處理器 使用JAX-WS暴露基于servlet的web服務(wù) 使用JAX-WS暴露單獨(dú)web服務(wù) 使用Spring支持的JAX-WS RI來暴露服務(wù) 使用JAX-WS訪問web服務(wù) 使用XFire來暴露Web服務(wù) JMS 服務(wù)端配置 客戶端配置 對遠(yuǎn)程接口不提供自動探測實(shí)現(xiàn) 在選擇這些技術(shù)時的一些考慮 Enterprise Java Beans (EJB) 集成 簡介 訪問EJB 概念 訪問本地的無狀態(tài)Session Bean(SLSB) 訪問遠(yuǎn)程SLSB Accessing EJB 2.x SLSBs versus EJB 3 SLSBs 使用Spring提供的輔助類實(shí)現(xiàn)EJB組件 EJB 2.x base classes EJB 3 注入攔截 JMS (Java Message Service) 簡介 使用Spring JMS JmsTemplate 連接工廠 目的地管理 消息偵聽容器 SimpleMessageListenerContainer DefaultMessageListenerContainer ServerSessionMessageListenerContainer 事務(wù)管理 發(fā)送消息 使用消息轉(zhuǎn)換器 SessionCallback 和 ProducerCallback 接收消息 同步接收 異步接收 - 消息驅(qū)動的POJO SessionAwareMessageListener接口 MessageListenerAdapter 事務(wù)中的消息處理 JCA消息端點(diǎn)的支持 JMS命名空間支持 JMX 介紹 將Bean暴露為JMX 創(chuàng)建MBeanServer 重用原有的MBeanServer 延遲初始化的MBean MBean的自動注冊 控制注冊行為 控制Bean的管理接口 MBeanInfoAssembler接口 使用源碼級元數(shù)據(jù) 使用JDK 5.0的注解 源代碼級的元數(shù)據(jù)類型 AutodetectCapableMBeanInfoAssembler接口 用Java接口定義管理接口 使用MethodNameBasedMBeanInfoAssembler 控制Bean的ObjectName 從Properties讀取Properties 使用MetadataNamingStrategy <context:mbean-export/>元素 JSR-160連接器 服務(wù)器端連接器 客戶端連接器 基于Burlap/Hessian/SOAP的JMX 通過代理訪問MBean 通知 為通知注冊監(jiān)聽器 發(fā)布通知 更多資源 JCA CCI 簡介 配置CCI 連接器配置 在Spring中配置ConnectionFactory 配置CCI連接 使用一個 CCI 單連接 使用Spring的 CCI訪問支持 記錄轉(zhuǎn)換 CciTemplate類 DAO支持 自動輸出記錄生成 總結(jié) 直接使用一個CCI Connection接口和Interaction接口 CciTemplate 使用示例 建模CCI訪問為操作對象 MappingRecordOperation MappingCommAreaOperation 自動生成輸出記錄 總結(jié) MappingRecordOperation 使用示例 MappingCommAreaOperation 使用示例 事務(wù) Spring郵件抽象層 簡介 使用Spring郵件抽象 MailSender 和 SimpleMailMessage 的基本用法 使用 JavaMailSender 和 MimeMessagePreparator 使用MimeMessageHelper 發(fā)送附件和嵌入式資源(inline resources) 附件 內(nèi)嵌資源 使用模板來創(chuàng)建郵件內(nèi)容 一個基于Velocity的示例 Spring中的定時調(diào)度(Scheduling)和線程池(Thread Pooling) 簡介 使用OpenSymphony Quartz 調(diào)度器 使用JobDetailBean 使用 MethodInvokingJobDetailFactoryBean 使用triggers和SchedulerFactoryBean來包裝任務(wù) 使用JDK Timer支持類 創(chuàng)建定制的timers 使用 MethodInvokingTimerTaskFactoryBean類 最后:使用TimerFactoryBean來設(shè)置任務(wù) SpringTaskExecutor抽象 TaskExecutor接口 TaskExecutor類型 使用TaskExecutor 動態(tài)語言支持 介紹 第一個示例 定義動態(tài)語言支持的bean 公共概念 <lang:language/> 元素 Refreshable bean 內(nèi)置動態(tài)語言源文件 理解dynamic-language-backed bean上下文中的構(gòu)造器注入 JRuby beans Groovy beans 通過回調(diào)定制Groovy對象 BeanShell beans 場景 Spring MVC控制器的腳本化 Validator的腳本化 Bits and bobs AOP - 通知腳本化bean 作用域 更多的資源 注解和源代碼級的元數(shù)據(jù)支持 簡介 Spring的元數(shù)據(jù)支持 注解 @Required Spring中的其它@Annotations Jakarta Commons Attributes集成 元數(shù)據(jù)和Spring AOP自動代理 基本原理 聲明式事務(wù)管理 示例程序 演示案例 介紹 使用動態(tài)語言實(shí)現(xiàn)的Spring MVC控制器 構(gòu)建與部署 使用SimpleJdbcTemplate和@Repository實(shí)現(xiàn)DAO 域?qū)ο?/a> Data Access Object 構(gòu)建 XML Schema-based configuration Introduction XML Schema-based configuration Referencing the schemas The util schema <util:constant/> Setting a bean property or constructor arg from a field value <util:property-path/> Using <util:property-path/> to set a bean property or constructor-argument <util:properties/> <util:list/> <util:map/> <util:set/> The jee schema <jee:jndi-lookup/> (simple) <jee:jndi-lookup/> (with single JNDI environment setting) <jee:jndi-lookup/> (with multiple JNDI environment settings) <jee:jndi-lookup/> (complex) <jee:local-slsb/> (simple) <jee:local-slsb/> (complex) <jee:remote-slsb/> The lang schema The jms schema The tx (transaction) schema The aop schema The context schema <property-placeholder/> <annotation-config/> <component-scan/> <load-time-weaver/> <spring-configured/> <mbean-export/> The tool schema The beans schema Setting up your IDE Setting up Eclipse Setting up IntelliJ IDEA Integration issues XML parsing errors in the Resin v.3 application server Extensible XML authoring Introduction Authoring the schema Coding a NamespaceHandler Coding a BeanDefinitionParser Registering the handler and the schema 'META-INF/spring.handlers' 'META-INF/spring.schemas' Using a custom extension in your Spring XML configuration Meatier examples Nesting custom tags within custom tags Custom attributes on 'normal' elements Further Resources spring-beans-2.0.dtd spring.tld Introduction The bind tag The escapeBody tag The hasBindErrors tag The htmlEscape tag The message tag The nestedPath tag The theme tag The transform tag spring-form.tld Introduction The checkbox tag The checkboxes tag The errors tag The form tag The hidden tag The input tag The label tag The option tag The options tag The password tag The radiobutton tag The radiobuttons tag The select tag The textarea tag Spring 2.5開發(fā)手冊中文化項(xiàng)目 聲明 致謝 參與人員 項(xiàng)目歷程
characters

17.5.?Web Services

Spring為標(biāo)準(zhǔn)Java web服務(wù)API提供了全面的支持:

  • 使用JAX-RPC暴露web服務(wù)

  • 使用JAX-RPC訪問web服務(wù)

  • 使用JAX-WS暴露web服務(wù)

  • 使用JAX-WS訪問web服務(wù)

注意

為什么有2個標(biāo)準(zhǔn)的Java web服務(wù)APIs?

JAX-RPC 1.1 在J2EE 1.4 中是標(biāo)準(zhǔn)的web服務(wù)API。正像其名稱所示,它關(guān)注于RPC綁定而且在最近幾年越來越不流行。最終被Java EE 5中的JAX-WS 2.0所取代,JAX-WS 2.0不但在綁定方面更靈活,而且也是完全基于annotation的。JAX-WS 2.1也被包含在Java 6中(更詳細(xì)的說是在Sun JDK 1.6.0_04和更高版本中,低版本的Sun JDK 1.6.0包含JAX-WS 2.0),它與JDK內(nèi)置的HTTP服務(wù)器集成。

Spring 同時支持兩個標(biāo)準(zhǔn)Java web服務(wù)API。選擇誰主要看運(yùn)行平臺:在JDK 1.4 / J2EE 1.4上,唯一的選擇是JAX-RPC。在Java EE 5 / Java 6上顯然應(yīng)該選JAX-WS。運(yùn)行Java 5的J2EE 1.4環(huán)境上,你可以選擇插入一個JAX-WS provider;請查看你的J2EE服務(wù)器文檔。

除了在Spring Core中支持JAX-RPC and JAX-WS,Spring portfolio也提供了一種特性Spring Web Services,一個為優(yōu)先授權(quán)和文檔驅(qū)動的web服務(wù)所提供的方案 - 非常建議用來創(chuàng)建高級并具有前瞻性的web服務(wù)。XFire是最后但不是唯一的Spring內(nèi)置支持可以讓你將Spring管理的bean暴露為web服務(wù)的方式。

17.5.1.?使用JAX-RPC暴露基于servlet的web服務(wù)

Spring為JAX-RPC servlet的端點(diǎn)實(shí)現(xiàn)提供了一個方便的基類 - ServletEndpointSupport. 未來暴露我們的 AccountService我們擴(kuò)展Spring的ServletEndpointSupport類并在這里實(shí)現(xiàn)了我們的業(yè)務(wù)邏輯,通常將調(diào)用交給業(yè)務(wù)層。

/**
 * JAX-RPC compliant RemoteAccountService implementation that simply delegates
 * to the AccountService implementation in the root web application context.
 *
 * This wrapper class is necessary because JAX-RPC requires working with dedicated
 * endpoint classes. If an existing service needs to be exported, a wrapper that
 * extends ServletEndpointSupport for simple application context access is
 * the simplest JAX-RPC compliant way.
 *
 * This is the class registered with the server-side JAX-RPC implementation.
 * In the case of Axis, this happens in "server-config.wsdd" respectively via
 * deployment calls. The web service engine manages the lifecycle of instances
 * of this class: A Spring application context can just be accessed here.
 */import org.springframework.remoting.jaxrpc.ServletEndpointSupport;

public class AccountServiceEndpoint extends ServletEndpointSupport implements RemoteAccountService {
    
    private AccountService biz;
	
    protected void onInit() {
        this.biz = (AccountService) getWebApplicationContext().getBean("accountService");
    }

    public void insertAccount(Account acc) throws RemoteException {
        biz.insertAccount(acc);
    }
  
    public Account[] getAccounts(String name) throws RemoteException {
        return biz.getAccounts(name);
    }
}

AccountServletEndpoint需要在Spring中同一個上下文的web應(yīng)用里運(yùn)行,以獲得對Spring的訪問能力。如果使用Axis,把AxisServlet定義復(fù)制到你的'web.xml'中,并且在'server-config.wsdd'中設(shè)置端點(diǎn)(或使用發(fā)布工具)。參看JPetStore這個例子中OrderService是如何用Axis發(fā)布成一個Web服務(wù)的。

17.5.2.?使用JAX-RPC訪問web服務(wù)

Spring提供了兩個工廠bean用來創(chuàng)建Web服務(wù)代理,LocalJaxRpcServiceFactoryBeanJaxRpcPortProxyFactoryBean。前者只返回一個JAX-RPC服務(wù)類供我們使用。后者是一個全功能的版本,可以返回一個實(shí)現(xiàn)我們業(yè)務(wù)服務(wù)接口的代理。本例中,我們使用后者來為前面段落中暴露的AccountService端點(diǎn)創(chuàng)建一個代理。你將看到Spring對Web服務(wù)提供了極好的支持,只需要很少的代碼 - 大多數(shù)都是通過類似下面的Spring配置文件:

<bean id="accountWebService" class="org.springframework.remoting.jaxrpc.JaxRpcPortProxyFactoryBean">
    <property name="serviceInterface" value="example.RemoteAccountService"/>
    <property name="wsdlDocumentUrl" value="http://localhost:8080/account/services/accountService?WSDL"/>
    <property name="namespaceUri" value="http://localhost:8080/account/services/accountService"/>
    <property name="serviceName" value="AccountService"/>
    <property name="portName" value="AccountPort"/>
</bean>

serviceInterface是我們客戶端將使用的遠(yuǎn)程業(yè)務(wù)接口。 wsdlDocumentUrl是WSDL文件的URL. Spring需要用它作為啟動點(diǎn)來創(chuàng)建JAX-RPC服務(wù)。 namespaceUri對應(yīng).wsdl文件中的targetNamespace。 serviceName 對應(yīng).wsdl文件中的服務(wù)名。 portName 對應(yīng).wsdl文件中的端口號。

現(xiàn)在我們可以很方便的訪問web服務(wù),因?yàn)槲覀冇幸粋€可以將它暴露為RemoteAccountService接口的bean工廠。我們可以在Spring中這樣使用:

<bean id="client" class="example.AccountClientImpl">
    ...
    <property name="service" ref="accountWebService"/>
</bean>

從客戶端代碼上看,除了它拋出RemoteException,我們可以把這個web服務(wù)當(dāng)成一個普通的類進(jìn)行訪,。

public class AccountClientImpl {

    private RemoteAccountService service;
    
    public void setService(RemoteAccountService service) {
        this.service = service;
    }
    
    public void foo() {
        try {
            service.insertAccount(...);
        }
        catch (RemoteException ex) {
            // ouch
        }
    }
}

我們可以不檢查受控異常RemoteException,因?yàn)镾pring將它自動轉(zhuǎn)換成相應(yīng)的非受控異常RemoteException。這也需要我們提供一個非RMI的接口。現(xiàn)在配置文件如下:

<bean id="accountWebService" class="org.springframework.remoting.jaxrpc.JaxRpcPortProxyFactoryBean">
    <property name="serviceInterface" value="example.AccountService"/>
    <property name="portInterface" value="example.RemoteAccountService"/>
</bean>

我們的serviceInterface變成了非RMI接口。我們的RMI接口現(xiàn)在使用portInterface屬性來定義。我們的客戶端代碼可以避免處理異常java.rmi.RemoteException:

public class AccountClientImpl {

    private AccountService service;
    
    public void setService(AccountService service) {
        this.service = service;
    }
    
    public void foo() {
        service.insertAccount(...);
    }
}

請注意你也可以去掉"portInterface"部分并指定一個普通業(yè)務(wù)接口作為"serviceInterface"。這樣JaxRpcPortProxyFactoryBean將自動切換到JAX-RPC "動態(tài)調(diào)用接口", 不使用固定端口存根來進(jìn)行動態(tài)調(diào)用。這樣做的好處是你甚至不需要使用一個RMI相關(guān)的Java接口(比如在非Java的目標(biāo)web服務(wù)中);你只需要一個匹配的業(yè)務(wù)接口。查看JaxRpcPortProxyFactoryBean的javadoc來了解運(yùn)行時實(shí)行的細(xì)節(jié)。

17.5.3.?注冊JAX-RPC Bean映射

T為了傳遞類似Account等復(fù)雜對象,我們必須在客戶端注冊bean映射。

注意

在服務(wù)器端通常在'server-config.wsdd'中使用Axis進(jìn)行bean映射注冊。

我們將使用Axis在客戶端注冊bean映射。為此,我們需要通過程序注冊這個bean映射:

public class AxisPortProxyFactoryBean extends JaxRpcPortProxyFactoryBean {

    protected void postProcessJaxRpcService(Service service) {
        TypeMappingRegistry registry = service.getTypeMappingRegistry();
        TypeMapping mapping = registry.createTypeMapping();
        registerBeanMapping(mapping, Account.class, "Account");
        registry.register("http://schemas.xmlsoap.org/soap/encoding/", mapping);
    }

    protected void registerBeanMapping(TypeMapping mapping, Class type, String name) {
        QName qName = new QName("http://localhost:8080/account/services/accountService", name);
        mapping.register(type, qName,
                new BeanSerializerFactory(type, qName),
                new BeanDeserializerFactory(type, qName));
    }
}

17.5.4.?注冊自己的JAX-RPC 處理器

本節(jié)中,我們將注冊自己的javax.rpc.xml.handler.Handler 到Web服務(wù)代理,這樣我們可以在SOAP消息被發(fā)送前執(zhí)行定制的代碼。Handler是一個回調(diào)接口。jaxrpc.jar中有個方便的基類javax.rpc.xml.handler.GenericHandler供我們繼承使用:

public class AccountHandler extends GenericHandler {

    public QName[] getHeaders() {
        return null;
    }

    public boolean handleRequest(MessageContext context) {
        SOAPMessageContext smc = (SOAPMessageContext) context;
        SOAPMessage msg = smc.getMessage();
        try {
            SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
            SOAPHeader header = envelope.getHeader();
            ...
        }
        catch (SOAPException ex) {
            throw new JAXRPCException(ex);
        }
        return true;
    }
}

我們現(xiàn)在要做的就是把AccountHandler注冊到JAX-RPC服務(wù),這樣它可以在消息被發(fā)送前調(diào)用 handleRequest(..)。Spring目前對注冊處理方法還不提供聲明式支持,所以我們必須使用編程方式。但是Spring中這很容易實(shí)現(xiàn),我們只需覆寫專門為此設(shè)計(jì)的 postProcessJaxRpcService(..) 方法:

public class AccountHandlerJaxRpcPortProxyFactoryBean extends JaxRpcPortProxyFactoryBean {

    protected void postProcessJaxRpcService(Service service) {
        QName port = new QName(this.getNamespaceUri(), this.getPortName());
        List list = service.getHandlerRegistry().getHandlerChain(port);
        list.add(new HandlerInfo(AccountHandler.class, null, null));
        logger.info("Registered JAX-RPC AccountHandler on port " + port);
    }
}

最后,我們要記得更改Spring配置文件來使用我們的工廠bean:

<bean id="accountWebService" class="example.AccountHandlerJaxRpcPortProxyFactoryBean">
    ...
</bean>

17.5.5.?使用JAX-WS暴露基于servlet的web服務(wù)

Spring為JAX-WS servlet端點(diǎn)實(shí)現(xiàn)提供了一個方便的基類 - SpringBeanAutowiringSupport。要暴露我們的AccountService接口,我們可以擴(kuò)展Spring的SpringBeanAutowiringSupport類并實(shí)現(xiàn)我們的業(yè)務(wù)邏輯,通常把調(diào)用交給業(yè)務(wù)層。我們將簡單的使用Spring 2.5的@Autowired注解來聲明依賴于Spring管理的bean。

/**
 * JAX-WS compliant AccountService implementation that simply delegates
 * to the AccountService implementation in the root web application context.
 *
 * This wrapper class is necessary because JAX-WS requires working with dedicated
 * endpoint classes. If an existing service needs to be exported, a wrapper that
 * extends SpringBeanAutowiringSupport for simple Spring bean autowiring (through
 * the @Autowired annotation) is the simplest JAX-WS compliant way.
 *
 * This is the class registered with the server-side JAX-WS implementation.
 * In the case of a Java EE 5 server, this would simply be defined as a servlet
 * in web.xml, with the server detecting that this is a JAX-WS endpoint and reacting
 * accordingly. The servlet name usually needs to match the specified WS service name.
 *
 * The web service engine manages the lifecycle of instances of this class.
 * Spring bean references will just be wired in here.
 */import org.springframework.web.context.support.SpringBeanAutowiringSupport;

@WebService(serviceName="AccountService")
public class AccountServiceEndpoint extends SpringBeanAutowiringSupport {

    @Autowired
    private AccountService biz;

    @WebMethod
    public void insertAccount(Account acc) {
       biz.insertAccount(acc);
    }

    @WebMethod
    public Account[] getAccounts(String name) {
       return biz.getAccounts(name);
    }
}

為了能夠讓Spring上下文使用Spring設(shè)施,我們的AccountServletEndpoint類需要運(yùn)行在同一個web應(yīng)用中。在Java EE 5環(huán)境中這是默認(rèn)的情況,它使用JAX-WS servlet端點(diǎn)安裝標(biāo)準(zhǔn)契約。詳情請參閱Java EE 5 web服務(wù)教程。

17.5.6.?使用JAX-WS暴露單獨(dú)web服務(wù)

Sun JDK 1.6提供的內(nèi)置JAX-WS provider 使用內(nèi)置的HTTP服務(wù)器來暴露web服務(wù)。Spring的SimpleJaxWsServiceExporter類檢測所有在Spring應(yīng)用上下文中配置的l@WebService 注解bean,然后通過默認(rèn)的JAX-WS服務(wù)器(JDK 1.6 HTTP服務(wù)器)來暴露它們。

在這種場景下,端點(diǎn)實(shí)例將被作為Spring bean來定義和管理。它們將使用JAX-WS來注冊,但其生命周期將一直跟隨Spring應(yīng)用上下文。這意味著Spring的顯示依賴注入可用于端點(diǎn)實(shí)例。當(dāng)然通過@Autowired來進(jìn)行注解驅(qū)動的注入也可以正常工作。

<bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter">
    <property name="baseAddress" value="http://localhost:9999/"/>
</bean>

<bean id="accountServiceEndpoint" class="example.AccountServiceEndpoint">
    ...
</bean>

...

AccountServiceEndpoint類可能源自Spring的 SpringBeanAutowiringSupport類,也可能不是。因?yàn)檫@里的端點(diǎn)是由Spring完全管理的bean。這意味著端點(diǎn)實(shí)現(xiàn)可能像下面這樣沒有任何父類定義 - 而且Spring的@Autowired配置注解仍然能夠使用:

@WebService(serviceName="AccountService")
public class AccountServiceEndpoint {

    @Autowired
    private AccountService biz;

    @WebMethod
    public void insertAccount(Account acc) {
       biz.insertAccount(acc);
    }

    @WebMethod
    public Account[] getAccounts(String name) {
       return biz.getAccounts(name);
    }
}

17.5.7.?使用Spring支持的JAX-WS RI來暴露服務(wù)

Sun的JAX-WS RI被作為GlassFish項(xiàng)目的一部分來開發(fā),它使用了Spring支持來作為JAX-WS Commons項(xiàng)目的一部分。這允許把JAX-WS端點(diǎn)作為Spring管理的bean來定義。這與前面章節(jié)討論的單獨(dú)模式類似 - 但這次是在Servlet環(huán)境中。注意這在Java EE 5環(huán)境中是不可遷移的,建議在沒有EE的web應(yīng)用環(huán)境如Tomcat中嵌入JAX-WS RI。

與標(biāo)準(zhǔn)的暴露基于servlet的端點(diǎn)方式不同之處在于端點(diǎn)實(shí)例的生命周期將被Spring管理。這里在web.xml將只有一個JAX-WS servlet定義。在標(biāo)準(zhǔn)的Java EE 5風(fēng)格中(如上所示),你將對每個服務(wù)端點(diǎn)定義一個servlet,每個服務(wù)端點(diǎn)都代理到Spring bean (通過使用@Autowired,如上所示)。

關(guān)于安裝和使用詳情請查閱https://jax-ws-commons.dev.java.net/spring/。

17.5.8.?使用JAX-WS訪問web服務(wù)

類似JAX-RPC支持,Spring提供了2個工廠bean來創(chuàng)建JAX-WS web服務(wù)代理,它們是LocalJaxWsServiceFactoryBeanJaxWsPortProxyFactoryBean。前一個只能返回一個JAX-WS服務(wù)對象來讓我們使用。后面的是可以返回我們業(yè)務(wù)服務(wù)接口的代理實(shí)現(xiàn)的完整版本。這個例子中我們使用后者來為AccountService端點(diǎn)再創(chuàng)建一個代理:

<bean id="accountWebService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
    <property name="serviceInterface" value="example.AccountService"/>
    <property name="wsdlDocumentUrl" value="http://localhost:8080/account/services/accountService?WSDL"/>
    <property name="namespaceUri" value="http://localhost:8080/account/services/accountService"/>
    <property name="serviceName" value="AccountService"/>
    <property name="portName" value="AccountPort"/>
</bean>

serviceInterface是我們客戶端將使用的遠(yuǎn)程業(yè)務(wù)接口。 wsdlDocumentUrl是WSDL文件的URL. Spring需要用它作為啟動點(diǎn)來創(chuàng)建JAX-RPC服務(wù)。 namespaceUri對應(yīng).wsdl文件中的targetNamespace。 serviceName 對應(yīng).wsdl文件中的服務(wù)名。 portName 對應(yīng).wsdl文件中的端口號。

現(xiàn)在我們可以很方便的訪問web服務(wù),因?yàn)槲覀冇幸粋€可以將它暴露為AccountService接口的bean工廠。我們可以在Spring中這樣使用:

<bean id="client" class="example.AccountClientImpl">
    ...
    <property name="service" ref="accountWebService"/>
</bean>

從客戶端代碼上我們可以把這個web服務(wù)當(dāng)成一個普通的類進(jìn)行訪問:

public class AccountClientImpl {

    private AccountService service;

    public void setService(AccountService service) {
        this.service = service;
    }

    public void foo() {
        service.insertAccount(...);
    }
}

注意: 上面被稍微簡化了,因?yàn)镴AX-WS需要端點(diǎn)接口及實(shí)現(xiàn)類來使用@WebService, @SOAPBinding等注解。 這意味著你不能簡單的使用普通的Java接口和實(shí)現(xiàn)來作為JAX-WS端點(diǎn),你需要首先對它們進(jìn)行相應(yīng)的注解。這些需求詳情請查閱JAX-WS文檔。

17.5.9.?使用XFire來暴露Web服務(wù)

XFire是一個Codehaus提供的輕量級SOAP庫。暴露XFire是通過XFire自帶的context,這個context將和RemoteExporter風(fēng)格的bean相結(jié)合,后者需要被加入到在你的WebApplicationContext中。對于所有讓你來暴露服務(wù)的方法,你需要創(chuàng)建一個DispatcherServlet類并有相應(yīng)的WebApplicationContext來封裝你將要暴露的服務(wù):

<servlet>
    <servlet-name>xfire</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

你還必須鏈接XFire配置。這是通過增加一個context文件到由ContextLoaderListener(或者ContextLoaderServlet)加載的 contextConfigLocations 參數(shù)中。

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:org/codehaus/xfire/spring/xfire.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

在你加入一個Servlet映射后(映射/*到上面定義的XFire Servlet),你只需要增加一個額外的bean來使用XFire暴露服務(wù)。例如,在 'xfire-servlet.xml' 中增加如下配置:

<beans>

    <bean name="/Echo" class="org.codehaus.xfire.spring.remoting.XFireExporter">
        <property name="serviceInterface" value="org.codehaus.xfire.spring.Echo"/>
        <property name="serviceBean">
    	       <bean class="org.codehaus.xfire.spring.EchoImpl"/>
        </property>
        <!-- the XFire bean is defined in the xfire.xml file -->
        <property name="xfire" ref="xfire"/>
  </bean>

</beans>

XFire處理了其他的事情。它檢查你的服務(wù)接口并產(chǎn)生一個WSDL文件。這里的部分文檔來自XFire網(wǎng)站,要了解更多有關(guān)XFire Spring的集成請?jiān)L問 docs.codehaus.org/display/XFIRE/Spring。

Previous article: Next article: