Spring Framework. Simple REST Service

From AsIsWiki
(Difference between revisions)
Jump to: navigation, search
Line 49: Line 49:
 
</beans>
 
</beans>
 
</source>
 
</source>
 
  
 
4. В файле '''pom.xml''' указываем, что web-приложение будет запаковано в Web Application Archive ('''war'''), и добавляем зависимость на '''spring-webmvc''':
 
4. В файле '''pom.xml''' указываем, что web-приложение будет запаковано в Web Application Archive ('''war'''), и добавляем зависимость на '''spring-webmvc''':

Revision as of 15:11, 26 March 2016

Spring Framework


Simple REST Service

1. Создаем Maven-проект в IntelliJ IDEA:

File / New / Project... 

Maven
Project SDK: 1.8 

[Next]

GroupId: org.asistech.web.srs
ArtifactId: SimpleRestService
Version: 1.0

[Next]

Project name: SimpleRestService
Project location: ~/projects/web/SimpleRestService

[Finish]

Структура нового проекта:

SimpleRestService.png


2. Добавляем папки webapp, WEB-INF и конфигурационный файл контекста приложения app-servlet.xml:

SimpleRestService1.png


3. Содержимое файла app-servlet.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.xsd">

</beans>

4. В файле pom.xml указываем, что web-приложение будет запаковано в Web Application Archive (war), и добавляем зависимость на spring-webmvc:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="
            http://maven.apache.org/POM/4.0.0
            http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>org.asistech.web.srs</groupId>
    <artifactId>SimpleRestService</artifactId>
    <version>1.0</version>

    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>
    </dependencies>

</project>



Spring Framework

Personal tools
Namespaces

Variants
Actions
Navigation
Tools