第一个springboot程序

1、下载java1.8 ,安装并配置环境变量

环境变量
增加java 的安装目录到环境变量中
path中增加 %JAVA_HOME%/bin
增加变量 java_home C:\Program Files\Java\jdk1.8.0_181
CLASSPATH .;./bin

测试 cmd中 使用java -version 测试是否安装成功,设置成功

2、下载maven3.2以上,安装并配置环境变量

解压即安装,将Maven解压至对应的盘符下(目录中不要出现中文)
增加变量M2_HOME E:\apache-maven-3.5.4
path 增加 %M2_HOME%/bin
测试是否安装成功,设置成功
cmd中 使用mvn -version

3. Maven仓库配置
本地仓库
1. 创建本地仓库目录
 E:\repository
修改kaven下的本地仓库配置 在conf/settings.xml中配置本地仓库路径
  <localRepository>E:\repository</localRepository>
修改远程仓库配置
远程仓库

    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>

    
修改为
    
    <mirror>
      <id>nexus-aliyun</id>
      <mirrorOf>*</mirrorOf>
      <name>nexus aliyun</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
    
下载 spring ctl
    https://github.com/spring-projects/spring-boot    Clone with HTTPS  downloads ZIP
    http://spring.io/projects/spring-boot  (官方网站)
    
3、下载ecalipse,安装
创建工作目录
E:\spring_workspace

4、在ecalipse下安装spring boot 插件


创建工作目录
E:\spring_workspace
4) 基本配置

启动eclipse之后需要配置编码格式,避免乱码问题 UTF-8
设置字体大小
将maven集成到eclipse中,因为后期我们要使用eclipse进行编码,,输入maven installation-》 add extenal 选择maven所在目录 目录使用

选择user setting 选择 maven安装目录下的setting.xml

5、eclips创建project 选择maven project

在pom.xml中增加

</parent>

<groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
  

 

6新建一个pacakge,controller

新建一个类 SampleController

增加内容

 

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

 

@RestController

@EnableAutoConfiguration

public class SampleController {

 

@RequestMapping("/")

//@ResponseBody

String home() {

return "Hello World!";

}

 

public static void main(String[] args) throws Exception {

SpringApplication.run(SampleController.class, args);

}

}

 

保存后运行,run as application

使用http://localhost:8080/访问

猜你喜欢

转载自www.cnblogs.com/programer-xinmu78/p/9568309.html