springboot启动项目时执行任务,从数据库或者redis获取系统参数

在springboot启动类方法实现org.springframework.boot.CommandLineRunner接口

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;

@RestController
@SpringBootApplication //Spring Boot核心注解,用于开启自动配置
public class StartApplication implements CommandLineRunner{
//程序可以直接在此启动
    @RequestMapping("/")
    String index(){
      return "ok";
    }

    public static void main(String[] args) {
        SpringApplication.run(StartApplication.class, args);
    }

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //配置静态资源处理
        registry.addResourceHandler("/**")
        .addResourceLocations("classpath:/META-INF/")
        .addResourceLocations("classpath:/hospitalpay");
    }

    @Override
    public void run(String... args) throws Exception {
        //项目启动时会执行这里的任务
        //通常加载用于系统参数加载
    }
}

原文地址:https://www.cnblogs.com/zyf-yxm/p/11423260.html

时间: 2024-08-30 11:48:13

springboot启动项目时执行任务,从数据库或者redis获取系统参数的相关文章

Spring:启动项目时加载数据库数据(总结)

在项目中需要启动程序时,要将数据库的用户信息表加载到内存中,找到一下几种方式. 1.实现ApplicationListener接口,重写onApplicationEvent方法,可以在项目启动的时候执行该方法. @Component("userInit") public class UserInit implements ApplicationListener { public static Map<String,User> map=new HashMap<Strin

使用servers 启动项目时 ,一直处于启动中, 最后出现无法的问题。

使用eclipse 中的servers 配置了一个server 来启动项目, 发现无法启动 排除法: 去掉项目配置,单独启动该server ,发现可以启动, 说明是项目出现问题 但是项目并没有报错, 没有报错可能是eclipse 平台的校验出现问题,这时候对项目手动执行 validate 即可看到问题 我的问题是mybatis 配置的一个xml 文件有问题,但是我写的时候eclipse 并没有提示错误.,使用validate 校验发现了写法错误.

ElementUI项目请求SpringBoot后台项目时提示:Access to XMLHttpRequest at **from origin ** has been blocked by CORS policy

场景 搭建ElementUI前端项目后提示: Access to XMLHttpRequest at **from origin ** has been blocked by CORS policy 这是因为在请求后台SpringBoot接口时出现了跨域请求问题. 本来打算是搭建好前端项目后再js中进行ajaxq请求数据,但是会因为跨域被拒绝. 注: 博客: https://blog.csdn.net/badao_liumang_qizhi关注公众号 霸道的程序猿 获取编程相关电子书.教程推送与

SpringBoot启动项目之后,访问页面出现Whitelabel Error Page

话说万事具备,只欠东风- 蹭闲暇时来跑个SpringBoot项目玩玩,把一切配置依赖准备就绪之后打算运行项目. Staring...... 接着,在浏览器输入地址 localhost:8080/hello 很惊讶的看见 Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Sat Jan 18 22:33:51 CST 202

Activiti+oracle 启动项目时不能自动建表或更新表的问题分析及解决办法

现象描述:按照正常配置,第一次启动时不能自动建表 关键配置片段如下: <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration"> <property name="dataSource" ref="dataSource" /> <property name=&q

Eclipse启动项目时,删除workspaces无用的工作区间

选择菜单栏的window-->Preferences-->General-->Startup and Shutdown-->workspaces, Recent workspaces下面的列表里就是已经设置过的工作区间.如果要删除已不用的,选中,点remove就好了. 如果之前选择不再提示,默认使用本工作区,在启动时想重新选择, 把右面的第一个复选框“Prompt for workspace on startup选上就可以了. Number of recent workspaces

启动项目时出现Error: Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (72)

前几天趁假期重新装了一次系统,重新安装各种配置之后再启动项目的时候就报这个错误 第一反应就是去搜这个错误怎么解决,搜来搜去基本上都是让我重新安装node-sass,但我重装node-sass的时候又出现了新的错误,整了半天还是没整好 然后静下心来仔细看了一下错误提示,查看了下面那个github网址https://github.com/sass/node-sass/releases/tag/v4.9.3看到了这个 然后就知道是node版本的问题了,我的是v12.x,换了一个10.5的版本就好了 原

MyEclipse下启动项目时JBoss内存溢出问题的解决

配置1:-Xms64m -Xmx512m 配置2:-c default -b 0.0.0.0-Xmx1024M -Xms512M -XX:MaxPermSize=256m

启动项目时出现Not a JAR.......Find JAR........一指循环就是起不来

出现问题原因就是mapper的映射文件有问题,里面的返回类型如是实体找不到或者找重复的就会这样 解决办法就是:确保在用的实体(路径)能找到,切记不能有重名的实体 原文地址:https://www.cnblogs.com/austinspark-jessylu/p/9086271.html