Spring Boot 快速入门
2023-09-11 14:18:25 时间
Spring Boot makes it easy to create Spring-powered, production-grade applications and services with absolute minimum fuss. It takes an opinionated view of the Spring platform so that new and existing users can quickly get to the bits they need.
You can use Spring Boot to create stand-alone Java applications that can be started using java -jar or more traditional WAR deployments. We also provide a command line tool that runs spring scripts.
点击Generate Project下载项目压缩包 解压项目包,并用IDE以Maven项目导入
项目结构
pom.xml
欢迎支持
Spring boot 使用 ON DUPLICATE KEY UPDATE属性控制版本 更新数据不成功 如果更新不成功会报下面的错误(此错误是自定义的): The data you want to update has been updated by another user. Please reopen and try again! 一、主要按下面的流程检查: 1、检查数据库的段alastupdatetime定义 2、检查.xml的alastupdatetime 3、要更新数据的主键是否在同一个updateByBatch中的List中重复出现
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载
Spring Boot主要优点:
创建独立的Spring应用程序 嵌入的Tomcat,无需部署WAR文件 简化Maven配置 自动配置Spring 提供生产就绪型功能,如指标,健康检查和外部配置 无需编写繁琐的XML配置快速创建Spring Boot项目
访问:http://start.spring.io/ 选择构建工具Maven Project、Spring Boot版本1.5.4以及一些工程基本信息点击Generate Project下载项目压缩包 解压项目包,并用IDE以Maven项目导入
项目结构
pom.xml
![CDATA[ ?xml version="1.0" encoding="UTF-8"? 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 com.example /groupId artifactId spring-boot-sample /artifactId version 0.0.1-SNAPSHOT /version packaging jar /packaging name spring-boot-sample /name description Demo project for Spring Boot /description parent groupId org.springframework.boot /groupId artifactId spring-boot-starter-parent /artifactId version 1.5.4.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 !--核心模块,包括自动配置支持、日志和YAML-- dependency groupId org.springframework.boot /groupId artifactId spring-boot-starter-web /artifactId /dependency !--热启动-- dependency groupId org.springframework.boot /groupId artifactId spring-boot-devtools /artifactId scope runtime /scope /dependency !--测试模块,包括JUnit、Hamcrest、Mockito-- 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 !-- 设定Maven仓库 -- repositories repository id maven-aliyun /id name maven-aliyun /name url http://maven.aliyun.com/nexus/content/groups/public /url /repository /repositories !-- 设定plugin仓库 -- pluginRepositories pluginRepository id maven-aliyun /id name maven-aliyun /name url http://maven.aliyun.com/nexus/content/groups/public /url /pluginRepository /pluginRepositories /project ]]SpringBootSampleApplication.java
@SpringBootApplication public class SpringBootSampleApplication { public static void main(String[] args) { SpringApplication.run(SpringBootSampleApplication.class, args); }
SampleController.java
class SampleController {
@RequestMapping(value = "/hello") String hello() {
return "hello world!";
}
}
SpringBootSampleApplicationTests@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @AutoConfigureMockMvc public class SpringBootSampleApplicationTests { @Autowired private MockMvc mvc; @Test public void contextLoads() { try{ URI uri = new URI("/hello"); MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(uri).accept(MediaType.APPLICATION_JSON)) .andReturn(); String context = mvcResult.getResponse().getContentAsString(); System.out.println(context); }catch (Exception e){ e.printStackTrace(); }application.properties
server.port=8000 #指定程序运行端口
大功告成!!!运行SpringBootSampleApplication的main方法SpringBoot即可启动起来~
浏览器访问http://localhost:8000/hello
运行测试类
欢迎支持
Spring boot 使用 ON DUPLICATE KEY UPDATE属性控制版本 更新数据不成功 如果更新不成功会报下面的错误(此错误是自定义的): The data you want to update has been updated by another user. Please reopen and try again! 一、主要按下面的流程检查: 1、检查数据库的段alastupdatetime定义 2、检查.xml的alastupdatetime 3、要更新数据的主键是否在同一个updateByBatch中的List中重复出现
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载
相关文章
- activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建
- Spring Boot优雅地处理404异常
- Spring之IOC容器
- SpringBoot之整合Redis分析和实现-基于Spring Boot2.0.2版本
- spring boot:创建一个简单的web(maven web project)
- Spring Boot 之 HelloWorld详解
- Spring Boot WebFlux 快速入门实践
- 前台项目基础框架之spring boot后端(spring boot v2.5.4)
- spring boot:在项目中引入第三方外部jar包集成为本地jar包(spring boot 2.3.2)
- spring boot 手动value和自动注入配置的区别[五]
- spring boot单元测试之十三:用mockmvc测试文件下载(spring boot 2.4.4)
- 基于Springboot2.0的Dubbo入门项目(dubbo-spring-boot-starter)
- 让你的Spring Boot工程支持HTTP和HTTPS
- Atitit spring cache key的生成 与ken生成规范 1. Good key name meth.params1 1.1. Use epl 的mode but only clss
- 为什么Spring Boot推荐使用logback-spring.xml来替代logback.xml来配置logback日志的问题分析
- 已解决:解决 Spring Boot 多线程环境下,多个定时器冲突问题
- 关于Spring注解开发教程,打包全送你
- Spring Boot 分库分表入门
- 学习Spring Boot:(六) 集成Swagger2
- Spring Boot 项目打包问题集锦: jar依赖多出boot-inf 文件夹问题/多环境动态打包/缺少BOOT-INF目录问题等...
- 毕业设计 Spring Boot的网课在线点播管理系统(含源码+论文)
- 005-Spring Boot配置分析-配置文件application、Environment、PropertySource、@Value、EnvironmentPostProcessor、Profiles
- [手写spring](1)构建框架,实现包扫描