Spring boot(一) 搭建

    xiaoxiao2021-03-25  141

    依赖:maven或gradle 建议使用jre1.8或更高

    本人用maven比较习惯

    传送门:apache-maven笔记(一) windows环境下的安装

    步骤:

    一、创建项目结构

    二、在src同级目录下创建pom.xml文件

    三、去Spring Boot官网找到右侧文档处,选一个版本点Reference

    找到Installing Spring Boot 下Maven installation并打开,会看到以下pom.xml的文件内容

    <?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>myproject</artifactId> <version>0.0.1-SNAPSHOT</version> <!-- Inherit defaults from Spring Boot --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.2.RELEASE</version> </parent> <!-- Add typical dependencies for a web application --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <!-- Package as an executable jar --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>

    内容复制到pom.xml中

    四、打开eclipse,导入maven项目

    五、创建入口

    package com.xyr; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } 然后run 这样就初步搭建成功了 六、自定义spring boot配置 变量 spring boot允许你自定义一个application.properties或application.yml,然后放在以下的地方,来重写spring boot的配置变量或者定义你自己配置变量 classpath根目录的“/config”包下classpath的根目录下

    优先级1>2

    application.properties和application.yml优先级则是后者大于前者,根据个人喜好选择。

    本人比较喜欢使用application.yml文件,在eclipse中需装一个spring插件能更好地使用,help - Eclipse Marketplace 搜索安装 Spring Tool Suite

    转载请注明原文地址: https://ju.6miu.com/read-8369.html

    最新回复(0)