Spring 4 Official Document Learning (13) integrating other web frameworks

Source: Internet
Author: User
Tags java web

The focus is on Universal configuration , very recommended to look at! Helps to understand the relationship between Spring's applicationcontext and servlet container!

1. Introduction

Spring Web Flow

The SWF goal is the best solution for flow Management of web App pages.

SWF integrates existing frameworks, such as spring MVC and JSF, in servlet and portlet environments. If you have one (or more) business processes and benefit from a session model rather than a purely request model, SWF might be the solution.

SWF allows you to capture a logical page flows and use it as a self-contained module that can be reused in different environments, so use it to build a Web application module (that's the user through controlled navigations that drive BU Siness processes) is ideal.

For more information, see Spring Web Flow website.

This chapter describes in detail the integration of spring with third-party web frameworks, such as JSF.

One of the core values of the spring framework is enable choice (selectable, extensible). In the general sense, spring does not enforce the use or purchase of any particular architecture, technology, or method (although it is certainly recommended). The choice is left to the developer!

Now that you've combed the fur (which is the previous chapter, it's really obscure), this chapter will focus on the Meat play section, which is how to integrate your Web framework! One thing developers who go to Java from other languages often say is that Java has a super-rich web framework. So many frameworks are definitely not covered, so this chapter selects only 4 of the most popular web frameworks, starting with a generic spring configuration and then fine-grained into specific integration options.

Please note that this chapter does not explain how to use specific Web frameworks. For example, if you want to use JSF, we'll assume you're already familiar with JSF. If you need more information about a specific web framework, you can refer to the end of this chapter.

2. Common configuration--General configurations

The so-called universal configuration is the configuration that is required regardless of the integration of the web framework, in other words, a configuration unrelated to the specific web framework.

It should be pointed out that in a classic layered architecture, the web layer is just one layer in a number of layers, and this layer assumes the entry point (entry points) that enters the server side, which also delegates service objects (facades) to the service layer. To complete a specific business usage scenario. In spring, these service objects, any other business-specific objects, DAO, and so on, all exist in a busisness context--note that this does not include the web or the imagery Layer Object!!! The imagery layer objects, such as spring MVC controllers, are usually configured in presentation context.

This chapter describes in detail how to configure a spring container (which is a webapplicationcontext) that contains all business beans. --Include all????

Specifically, all spring Web projects need to declare a contextloaderlistener in XML, and then add a contextconfiglocation <context-param>- Used to specify where the spring XML configuration file resides.

As follows:

< Listener >    < Listener-class >org.springframework.web.context.ContextLoaderListener</listener-class  ></listener>
 <  context-param  >  <  param-name  >  contextconfiglocation</    Span style= "COLOR: #800000" >param-name  >  <  param-value  > /web-inf/applicationcontext*.xml</  param-value  >  </ context-param  > 

If you do not specify Contextconfiglocation,contextloaderlistener, it will be found and loaded by default /WEB-INF/applicationContext.xml . Once the context file is loaded, Spring creates a Webapplicationcontext object--based on the bean definitions, And put the Webapplicationcontext object into the ServletContext of the Web App !!! ---finally understood, laughed.

All Java Web Frameworks are built on the servlet API, so you can use the following code to get the ' business context ' ApplicationContext created by Contextloaderlistener:

Webapplicationcontext CTX = Webapplicationcontextutils.getwebapplicationcontext (ServletContext);

This WebApplicationContextUtils class is for convenience, so there is no need to remember the name of ServletContext attribute. The Getwebapplicationcontext () method of the class finds the key by default WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE , and returns null if it is not found. Rather than risking the risk of a null pointer exception, use the Getrequiredwebapplicationcontext () method, which throws an exception if there is no applicationcontext.

Once you have a webapplicationcontext reference, you can get beans by name or type. Most developers are obtained by name, and then the type is strongly turned.

Fortunately, most frameworks in this section have a simpler way to find beans. Not only is getting beans simpler, but also running you using dependency injection. See each of the Web frameworks.

3, JavaServer Faces 1.2

Slightly

Other, slightly.

6. Other Resources

    • The JSF homepage
    • The Struts homepage
    • The Tapestry homepage

Official Documentation Links:

Http://docs.spring.io/spring/docs/current/spring-framework-reference/html/web-integration.html

Spring 4 Official Document Learning (13) integrating other web frameworks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.