springboot设置默认值_详解springboot设置默认参数Springboot.setDefaultProperties(map)不生效解决...

本文介绍了在SpringBoot中遇到通过Springboot.setDefaultProperties(map)设置默认参数无效的问题。问题在于启动类使用了新的SpringApplication实例导致设置失效。解决办法是避免使用`application.run(startClass, args)`,而是采用`application.run(args)`来启动应用。" 133724019,5629451,LVGL库中的对象对齐:lv_obj_align_to函数解析,"['LVGL', 'GUI开发', '嵌入式UI']
摘要由CSDN通过智能技术生成

我们都知道springboot 由于内置tomcat(中间件)直接用启动类就可以启动了。

而且我们有时想代码给程序设置一些默认参数,所以使用方法Springboot.setDefaultProperties(map)

SpringApplication application = new SpringApplication(startClass);

//

Map params = new HashMap<>();

params.put("lai.ws.test","test");

application.setDefaultProperties(params);

ApplicationContext context = application.run(startClass,args);

于是启动后发现 lai.ws.test 居然是null,也就是参数设置不成功,百思不得其解。为此还断点进入SpringApplication 的源码里。最后发现以下源码

/**

* Static helper that can be used to run a {@link SpringApplication} from the

* specified sources using default settings and user supplied arguments.

* @param primarySources the primary sources to load

* @param args the application arguments (usually passed from a Java main method)

* @return the running {@link ApplicationConte

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值