当前位置: 首页 > news >正文

网站变exe文件怎么做私人影吧服务器

网站变exe文件怎么做,私人影吧服务器,中国建设银行官网站e路护航下载,广州一起做网店官网文章目录一、前言二、加载方式2.1、 第一种:使用PostConstruct注解(properties/yaml文件)。2.2、 第二种:使用Order注解和CommandLineRunner接口。2.3、 第三种:使用Order注解和ApplicationRunner接口。三、代码示例3.…

文章目录

  • 一、前言
  • 二、加载方式
    • 2.1、 第一种:使用@PostConstruct注解(properties/yaml文件)。
    • 2.2、 第二种:使用@Order注解和CommandLineRunner接口。
    • 2.3、 第三种:使用@Order注解和ApplicationRunner接口。
  • 三、代码示例
    • 3.1、 使用@PostConstruct注解
    • 3.2、 CommandLineRunner接口
    • 3.3、 ApplicationRunner接口
  • 四、总结
    • 4.1、CommandLineRunner和ApplicationRunner调用的时机是在容器初始化完成之后,立即调用。
    • 4.2、CommandLineRunner和ApplicationRunner使用上没有区别,唯一区别是CommandLineRunner接受字符串数组参数,需要自行解析出健和值,ApplicationRunner的参数是ApplicationArguments,是对原始参数做了进一步的封装。
    • 4.3、两个接口都可以使用 @Order 参数,支持工程启动后根据order 声明的权重值来决定调用的顺序(数字越小,优先级越高)。

一、前言

一般来说,SpringBoot工程环境配置放在properties文件中,启动的时候将工程中的properties/yaml文件的配置项加载到内存中。但这种方式改配置项的时候,需要重新编译部署,考虑到这种因素,今天介绍将配置项存到数据库表中,在工程启动时把配置项加载到内存中。

SpringBoot提供了两个接口: CommandLineRunner 和 ApplicationRunner 。实现其中接口,就可以在工程启动时将数据库中的数据加载到内存。使用的场景有:加载配置项到内存中;启动时将字典或白名单数据加载到内存(或缓存到Redis中)。

二、加载方式

2.1、 第一种:使用@PostConstruct注解(properties/yaml文件)。

2.2、 第二种:使用@Order注解和CommandLineRunner接口。

2.3、 第三种:使用@Order注解和ApplicationRunner接口。

注意事项

第二种和第三种,二者的官方javadoc一样,区别在于接收的参数不一样。CommandLineRunner的参数是最原始的参数,没有做任何处理。ApplicationRunner的参数是ApplicationArguments,是对原始参数做了进一步的封装。

三、代码示例

3.1、 使用@PostConstruct注解

package com.example.demo.config;import com.example.demo.service.ICodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.HashMap;
import java.util.List;
import java.util.Map;@Component
public class InitData1 {public static Map<Integer, String> codeMap = new HashMap<Integer, String>();@Autowiredprivate ICodeService codeService;@PostConstructpublic void init() {System.out.println("示例1:加载codeMap中......");// 查询数据库数据List<String> codeList = codeService.listAll();for (int i = 0; i < codeList.size(); i++) {codeMap.put(i, codeList.get(i));}}@PreDestroypublic void destroy() {System.out.println("系统启动成功,codeMap加载完成!");}
}

3.2、 CommandLineRunner接口

package com.example.demo.config;import com.example.demo.service.ICodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;import java.util.HashMap;
import java.util.List;
import java.util.Map;@Component
@Order(1) // 初始化加载优先级,数字越小优先级越高
public class InitData2 implements CommandLineRunner {public static Map<Integer, String> codeMap = new HashMap<Integer, String>();@Autowiredprivate ICodeService codeService;@Overridepublic void run(String... args) throws Exception {System.out.println("示例2:加载codeMap中......");// 查询数据库数据List<String> codeList = codeService.listAll();for (int i = 0; i < codeList.size(); i++) {codeMap.put(i, codeList.get(i));}}
}

3.3、 ApplicationRunner接口

package com.example.demo.config;import com.example.demo.service.ICodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;import java.util.HashMap;
import java.util.List;
import java.util.Map;@Component
@Order(1) // 初始化加载优先级,数字越小优先级越高
public class InitData3 implements ApplicationRunner {public static Map<Integer, String> codeMap = new HashMap<Integer, String>();@Autowiredprivate ICodeService codeService;@Overridepublic void run(ApplicationArguments args) throws Exception {System.out.println("示例3:加载codeMap中......");// 查询数据库数据List<String> codeList = codeService.listAll();for (int i = 0; i < codeList.size(); i++) {codeMap.put(i, codeList.get(i));}}
}

四、总结

4.1、CommandLineRunner和ApplicationRunner调用的时机是在容器初始化完成之后,立即调用。

4.2、CommandLineRunner和ApplicationRunner使用上没有区别,唯一区别是CommandLineRunner接受字符串数组参数,需要自行解析出健和值,ApplicationRunner的参数是ApplicationArguments,是对原始参数做了进一步的封装。

4.3、两个接口都可以使用 @Order 参数,支持工程启动后根据order 声明的权重值来决定调用的顺序(数字越小,优先级越高)。

http://www.yayakq.cn/news/57131/

相关文章:

  • 网络口碑营销案例分析seo职位全称
  • 韶关哪里做网站最好白鹭引擎做网站
  • 网站建设带数据库模板wordpress微信h5支付
  • 建设网站 翻译wordpress 导入的模板
  • 站点建设方案百度账号免费注册
  • 公司网站维护内容网站建设死人接单
  • 做网站用dw还是vs织梦网站更改标题长度
  • wordpress多个single泉州seo关键词排名
  • 做网站广告软件wordpress最新版爆破
  • 怎么自己做网站版面设计个人备案挂企业网站
  • 代理公司网站备案wordpress搬家中文图片
  • 做教育的网站有哪些wordpress中文官网上
  • 做公众号时图片的网站舟山 做企业网站
  • php用什么做网站服务器活在永久免费服务器
  • wordpress 调用大全天津网站优化步骤
  • 做 爱 网站小视频下载找外包公司做个网站多少钱
  • 网站漏洞扫描服务全国大型教育集团网站建设
  • 三型布局的网站朝阳百姓网免费发布信息
  • 电商网站建设公司排名多用户商城源码开发
  • 工作室 网站备案发帖网站有哪些
  • 做区域链的网站客厅装修风格
  • 权威的扬中网站建设深圳品牌战略定位公司
  • 手机网页版网站开发怎样做自己的个人网站
  • 遵化建设招标网站wordpress 攻击
  • iapp网站做软件厦门seo网站优化
  • 建网站到底需要多少钱hyperapp wordpress
  • 营销型手机网站做网站的接口是意思
  • 个人博客网站设计的目的seo营销的概念
  • 电商网站建设情况汇报怎做不下网站刷枪
  • 哪些网站可以免费平湖网站设计