Spring Starter Demo

Source: Internet
Author: User

List of required software:

1.eclipse Luna 64bit, make sure it comes with Maven, or you'll need to install it through Eclipse's install new software

2.JDK 1.7 64bit

Let's start with the first demo

1. First manually create the following directories and files

Catalog: Workspace->myfirstproject->src->main->java->com->example->myfirstproject

Files: Workspace\myfirstproject\pom.xml file contents are as follows:

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"3 xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">4     <modelversion>4.0.0</modelversion>5 6     <groupId>Com.example</groupId>7     <Artifactid>Myfirstproject</Artifactid>8     <version>0.0.1-snapshot</version>9 Ten     <!--Inherit defaults from Spring Boot - One     <Parent> A         <groupId>Org.springframework.boot</groupId> -         <Artifactid>Spring-boot-starter-parent</Artifactid> -         <version>1.4.0.build-snapshot</version> the     </Parent> -  -     <!--Add Typical dependencies for a Web application - -     <Dependencies> +         <Dependency> -             <groupId>Org.springframework.boot</groupId> +             <Artifactid>Spring-boot-starter-web</Artifactid> A         </Dependency> at     </Dependencies> -  -     <!--Package as an executable jar - -     <Build> -         <Plugins> -             <plugin> in                 <groupId>Org.springframework.boot</groupId> -                 <Artifactid>Spring-boot-maven-plugin</Artifactid> to             </plugin> +         </Plugins> -     </Build> the  *     <!--Add Spring repositories - $     <!--(you don ' t need the If you are using a. RELEASE version) -Panax Notoginseng     <repositories> -         <Repository> the             <ID>Spring-snapshots</ID> +             <URL>Http://repo.spring.io/snapshot</URL> A             <Snapshots><enabled>True</enabled></Snapshots> the         </Repository> +         <Repository> -             <ID>Spring-milestones</ID> $             <URL>Http://repo.spring.io/milestone</URL> $         </Repository> -     </repositories> -     <pluginrepositories> the         <pluginrepository> -             <ID>Spring-snapshots</ID>Wuyi             <URL>Http://repo.spring.io/snapshot</URL> the         </pluginrepository> -         <pluginrepository> Wu             <ID>Spring-milestones</ID> -             <URL>Http://repo.spring.io/milestone</URL> About         </pluginrepository> $     </pluginrepositories> - </Project>
View Code

In addition, two new Java files are created,

Workspace\myfirstproject\src\main\java\com\example\myfirstproject\application.java, the code is as follows,

1  PackageMain.java.com.example.myFirstProject;2 3 Importorg.springframework.boot.SpringApplication;4 Importorg.springframework.boot.autoconfigure.SpringBootApplication;5 6 @SpringBootApplication7  Public classApplication {8 9      Public Static voidMain (string[] args) {TenSpringapplication.run (Application.class, args); One     } A  -}
View Code

Workspace\myfirstproject\src\main\java\com\example\myfirstproject\example.java, the code is as follows,

1  PackageMain.java.com.example.myFirstProject;2 3 4 Importorg.springframework.boot.autoconfigure.EnableAutoConfiguration;5 Importorg.springframework.web.bind.annotation.PathVariable;6 Importorg.springframework.web.bind.annotation.RequestMapping;7 ImportOrg.springframework.web.bind.annotation.RestController;8 9 @RestControllerTen @EnableAutoConfiguration One  Public classExample { A      -@RequestMapping ("/") - String Home () { the         return"Hello world!"; -     } -      -@RequestMapping ("/hello/{myname}") + String Index (@PathVariable string myName) { -         return"Hello" +myname+ "!!!"; +     } A}
View Code

2.Eclipse Configuration

File->import->existing maven Projects, located to Workspace\myfirstproject\, can automatically read pom.xml files as Maven project files,

The build path needs to be configured after the project is imported

2.1 In libraries of Build path, add Library->jre System library->workspace default JRE (1.7) to ensure that JDK1.7 is imported into the project

2.2 Add Library->maven Managed Dependencies, then configure "Maven Project settings" to enter Managed Dependencies

The final configuration results are as follows

3. Execute the Application.java and run the results as follows

4. Enter http://localhost:8080 in the browser, the result is as follows,

5. Enter Http://localhost:8080/hello/world in the browser, the result is as follows,

Spring Starter Demo

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.