springboot test

来源:互联网 发布:监控系统网络拓扑图 编辑:程序博客网 时间:2024/06/05 06:16

前期搭建适合自己的eclipse,下载eclipse_v4.7.0.exe,是一个eclipse的下载工具,安装好后运行,可以下载开发java的,我下载的是javaee的,因为包含的web开发。也可以下载开发c++, js的。

安装插件:jad,startexplorer,git,svn,maven,还有自己喜欢的activiti插件。当然最快最省事情的就是在线安装。当然我都是每一个百度出来的安装方法,自己记不住这么多安装方法,一般都差不多,因为地址版本不一样,所以每次安装可能找的地方也不一样。

1 首先创建一个maven项目,定义groupName(包名的开头),artifact id 项目名,package 包名,与前面的可以一致。

2 如果要做一个springboot的测试,那么我们需要在pom.xml加入spring boot的jar。见下面:

只要保存pom文件,那么系统会自动通过maven的仓库地址去通过网络下载对应的jar,并且形成依赖。 

<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>GroupName</groupId>
  <artifactId>project_1</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>


  <name>project_1</name>
  <url>http://maven.apache.org</url>


  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>


  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
    </parent>


  <dependencies>
  
  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
  
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    
  </dependencies>
</project>


3 然后写一个测试类:

package com.springboot.main;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@SpringBootApplication
@RestController
public class Application {


@RequestMapping("/test")
public String greeting() {
return "Hello World!";
}


public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}


4 运行main后,访问http://localhost:8080/test

在页面上出现对应的字符串信息Hello World!

原创粉丝点击