怎么做火短视频网站,群晖可以做网站服务器,网络广告方案怎么写,网站页面上的下载功能怎么做目录一、新建Springboot项目第一步#xff1a;新建一个Springboot项目第二步#xff1a;选择项目模板第三步#xff1a;设置项目配置第四步#xff1a;设置项目依赖第五步#xff1a;设置项目名称及路径第六步#xff1a;创建完成二、测试及运行1、测试代码2、设置默认端…
目录一、新建Springboot项目第一步新建一个Springboot项目第二步选择项目模板第三步设置项目配置第四步设置项目依赖第五步设置项目名称及路径第六步创建完成二、测试及运行1、测试代码2、设置默认端口3、运行三、加载本地配置1、引入Lombok2、创建本地配置1application.properties添加配置2创建配置对象3、加载本地配置SpringBoot项目打包IDEA 将 SpringBoot 项目打包成jar
一、新建Springboot项目 第一步新建一个Springboot项目 第二步选择项目模板 第三步设置项目配置 第四步设置项目依赖 第五步设置项目名称及路径 第六步创建完成
等待依赖下载完项目就创建完成。
二、测试及运行 1、测试代码 2、设置默认端口 3、运行 出现如上界面说明运行成功。 三、加载本地配置
1、引入Lombok
首先在IDEA的plugins中引入Lombok插件添加方式如下 在项目中引入 lombok 包。
dependenciesdependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdscopecompile/scope/dependency
/dependencies2、创建本地配置
1application.properties添加配置
在 application.properties 配置文件中添加如下配置
data.domainhttp://10.0.10.202:18080
log.levelINFO2创建配置对象
package com.example.springbootdemo.config;import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;Data
Component
Configuration
public class GlobalConfig {Value(${data.domain:http://10.0.0.1:18080})private String dataDomain;Value(${log.level:DEBUG})private String logLevel;
}3、加载本地配置
在应用初始化时获取本地配置对象
package com.example.springbootdemo;import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;Component
public class ApplicationManager implements ApplicationContextAware {Autowiredprivate static ApplicationContext applicationContext;Overridepublic void setApplicationContext(ApplicationContext context) throws BeansException {applicationContext context;}public static T T getBean(ClassT clazz) {if (applicationContext null) {return null;}return applicationContext.getBean(clazz);}public static T T getBean(String name, ClassT clazz) {if (applicationContext null) {return null;}return applicationContext.getBean(name, clazz);}
}应用初始化时加载配置对象 接口中返回所有配置信息 访问接口后返回如下界面说明加载本地配置成功。