栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springBoot2---基础入门

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springBoot2---基础入门

一、配置 1、maven

conf/setting.xml:选择阿里云快一点


      
        nexus-aliyun
        central
        Nexus aliyun
        http://maven.aliyun.com/nexus/content/groups/public
      
  

  
         
              jdk-1.8
              
                true
                1.8
              
              
                1.8
                1.8
                1.8
              
         
  
2、系统要求

二、helloWorld

官方文档:https://spring.io/projects/spring-boot#learn

1、创建maven项目 1.1、引入依赖

    org.springframework.boot
    spring-boot-starter-parent
    2.5.4


    
        org.springframework.boot
        spring-boot-starter-web
    

2、创建主程序
package com.boot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;


//@SpringBootConfiguration
//@EnableAutoConfiguration
//@ComponentScan("com.boot")
@SpringBootApplication
public class MyApplication {
    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class,args);
    }
}
3、编写业务
package com.boot.controller;

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

@RestController
public class helloController {

    @RequestMapping("/hello")
    public String hello(){
        return "hello,world.";
    }
}
4、测试

直接运行main方法,

然后在浏览器中输入:http://localhost:8080/hello

5、题外话

在springboot中咱们再也不用配置海量的配置文件,仅仅只需要创建一个application.properties文件就够了

需要改什么都可以在里面改

例如如果要修改端口号的话:

server.port=8888
三、创建可执行的jar 1、添加插件

要创建可执行jar,我们需要将SpringBootMaven插件添加到pom.xml中。要执行此操作,请在dependencies部分下方插入以下行:


    
        
            org.springframework.boot
            spring-boot-maven-plugin
        
    

2、打包

也可以在输入命令:mvn package

成功结果:

打包的文件会放在target目录下

然后再cmd中运行,必须在同级目录下

3、注意点

取消掉cmd的快速编辑模式:因为程序没运行好时,你点击窗口,程序可能会终止

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/424832.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号