Java Spring FrameWork: Difference between revisions
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
| Line 74: | Line 74: | ||
     <display-name>Spring ExoTest</display-name>  |      <display-name>Spring ExoTest</display-name>  | ||
     <description>Spring ExoTest Demo</description>  |      <description>Spring ExoTest Demo</description>  | ||
<!-- A context listner to load other spring context xml file -->  | |||
    <listener>  | |||
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  | |||
    </listener>  | |||
<!-- Context Config File Location (where are located the configuration file) -->  | <!-- Context Config File Location (where are located the configuration file) -->  | ||
| Line 81: | Line 86: | ||
     </context-param>  |      </context-param>  | ||
<!--   | <!-- Handles Spring requests -->  | ||
     <  |      <servlet>  | ||
         <  |          <servlet-name>myapplication</servlet-name>  | ||
     </  |         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  | ||
        <init-param>  | |||
            <param-name>contextConfigLocation</param-name>  | |||
            <param-value>WEB-INF/spring/webmvc-config.xml</param-value>  | |||
        </init-param>  | |||
        <load-on-startup>1</load-on-startup>  | |||
     </servlet>  | |||
    <servlet-mapping>  | |||
        <servlet-name>myapplication</servlet-name>  | |||
        <url-pattern>/</url-pattern>  | |||
    </servlet-mapping>  | |||
<!-- timeout Setting -->  | <!-- timeout Setting -->  | ||
Revision as of 20:13, 5 December 2014
Notes
Rest Architecture
REST (REpresentational State Transfer) New naming : HATEOAS (Hypermedia as the Engine of Application State)
- Client-serveur: Data remain on serveur and client is a separated entity
 - No state: Each request provide to the server all the necessary information to provide the service
 - Cache: The information sent by the server must contain, creation date, expiration date.
 - Uniform Interface:
- Each resources has a unic Id;
 - Resources have representation defined;
 - Auto descriptive message: The content and how to read the message; (Like how the message is coded Utf8).
 - Hypermedia Each access to the next step of the application is describe in the current message.
 
 - Hyercharchie
 - Code-on-Demande(facultative): Script excecution on the client retreived from the server.
 
| Stackoverflow what exactly is restful programming
Maven Setup
<!-- General repository to get package -->  
<repositories>
    <repository>
        <id>io.spring.repo.maven.release</id>
        <url>http://repo.spring.io/release/</url>
        <snapshots><enabled>false</enabled></snapshots>
    </repository>
</repositories>
<!-- Maven bom to manage dependencies between jar -->  
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-framework-bom</artifactId>
            <version>4.1.2.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<!-- Dependencies without version because they are managed by Maven Bom --> 
<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>
</dependencies>
Setup
web.xml
1 In the web.xml specify the location of the Spring Configuration File
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         id="WebApp_ID" version="2.5">
<!-- Application Name (for Information only) -->
    <display-name>Spring ExoTest</display-name>
    <description>Spring ExoTest Demo</description>
<!-- A context listner to load other spring context xml file -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
<!-- Context Config File Location (where are located the configuration file) -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
    </context-param>
<!-- Handles Spring requests -->
    <servlet>
        <servlet-name>myapplication</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>WEB-INF/spring/webmvc-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>myapplication</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
<!-- timeout Setting -->
    <session-config>
        <session-timeout>10</session-timeout>
    </session-config>
<!-- Error page Management java error and page no found 404  -->
    <error-page>
        <exception-type>java.lang.Exception</exception-type>
        <location>/uncaughtException</location>
    </error-page>
    
    <error-page>
        <error-code>404</error-code>
        <location>/resourceNotFound</location>
    </error-page>