简述
本文主要介绍Springboot以及用Eclipse搭建一个简单的Springboot项目。
Springboot简介
Springboot是由Pivotal团队提供的全新框架,其设计目的是用来简化Spring应用初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。Spring Boot其实就是一个整合很多可插拔的组件(框架),内嵌了使用工具(比如内嵌了Tomcat、Jetty等),方便开发人员快速搭建和开发的一个框架。
简单来说就是:简化开发、整合框架、减少配置、快速搭建。
SpringBoot特点
快速搭建:搭建项目快,几秒钟就可以搭建完成;
方便测试:内置了JUnit、Spring Boot Test等多种测试框架;
内嵌容器:内嵌了Tomcat、Jetty等,省去了配置Tomcat的繁琐;
方便监控:Spring Boot Actuator组件提供了应用的系统监控,可以查看应用配置详细信息;
减少配置:基于注解的零配置思想;
整合框架:各种流行框架,springmvc,mybatis,spring cloud无缝整合;
环境配置
Eclipse IDE Version: 2019-03 (4.11.0)
Java version: 1.8.0_151
创建项目
修改Maven仓库
Window->Preferences->Maven->User Settings,找到你本地设置的setting文件。
settings-springboot.xm文件
<?xml version="1.0" encoding="UTF-8"?>F://.m2/repo_springmaven-releasesadminadmin123maven-snapshotsadminadmin123maven-centraladminadmin123alimavencentralaliyun mavenhttp://maven.aliyun.com/nexus/content/repositories/central/nexusmaven-releaseshttp://maven-releasestruetruemaven-snapshotshttp://maven-snapshotstruetruemaven-releaseshttp://maven-releasestruetruemaven-snapshotshttp://maven-snapshotstruetruenexus
修改pom.xml文件
添加项目依赖和编译插件
pom.xml文件
4.0.0com.springspringbootDemo0.0.1-SNAPSHOTjarspringbootDemohttp://maven.apache.orgorg.springframework.bootspring-boot-starter-parent2.0.2.RELEASEUTF-8junitjunittestorg.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-maven-plugin
文件配置
application.properties文件
#服务端口server.port=80
Application.java文件
package com.spring.springboot;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;/****
Title: Application
**
Description: 应用启动类
** @author** @date 2020年5月18日**/@SpringBootApplicationpublic class Application{public static void main( String[] args ){SpringApplication.run(Application.class, args);}}
UserController.java文件
package com.spring.springboot.controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.bind.annotation.RestController;/****
Title: UserController
**
Description: 用户管理类
** @author** @date 2020年5月18日**/@RestController@RequestMapping("/user")public class UserController {/****
Title: login
**
Description: 登录方法
** @return**/@RequestMapping("/login")@ResponseBodypublic String login() {return "This is my first springboot demo!";}}
启动应用
访问应用
项目目录
ok,以上就是Springboot介绍以及用Eclipse搭建一个简单的Springboot项目教程,看完记得转发、点赞和收藏。如果有错误,欢迎批评指正,感谢。
(云渺书斋)