SpringBoot编写自定义配置信息

⒈编写自定义配置类

  1.浏览器配置

复制代码
 1 package cn.coreqi.security.properties;
 2 
 3 public class BrowserProperties {
 4 
 5     private String loginPage = "coreqi-signIn.html";   //登录页面
 6 
 7     private LoginType loginType = LoginType.JSON;
 8 
 9 
10     public LoginType getLoginType() {
11         return loginType;
12     }
13 
14     public void setLoginType(LoginType loginType) {
15         this.loginType = loginType;
16     }
17 
18     public String getLoginPage() {
19         return loginPage;
20     }
21 
22     public void setLoginPage(String loginPage) {
23         this.loginPage = loginPage;
24     }
25 }
复制代码

  2.安全配置中包含了浏览器配置

复制代码
 1 package cn.coreqi.security.properties;
 2 
 3 import org.springframework.boot.context.properties.ConfigurationProperties;
 4 
 5 @ConfigurationProperties(prefix = "coreqi.security")
 6 public class SecurityProperties {
 7     private BrowserProperties browser = new BrowserProperties();
 8 
 9     public BrowserProperties getBrowser() {
10         return browser;
11     }
12 
13     public void setBrowser(BrowserProperties browser) {
14         this.browser = browser;
15     }
16 }
复制代码

⒉在配置文件中配置

1 coreqi.security.browser.loginPage=/coreqi-signIn.html

⒊开启自定义配置,并在代码中引用

复制代码
 1 package cn.coreqi.security.config;
 2 
 3 import cn.coreqi.security.properties.SecurityProperties;
 4 import org.springframework.beans.factory.annotation.Autowired;
 5 import org.springframework.boot.context.properties.ConfigurationProperties;
 6 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 7 import org.springframework.context.annotation.Configuration;
 8 
 9 @Configuration
10 @EnableConfigurationProperties(value = {SecurityProperties.class})
11 public class SecurityPropertiesConfig {
12     @Autowired
13     private SecurityProperties securityProperties;
14     public void test(){
15         System.out.println(securityProperties.getBrowser().getLoginPage());
16     }
17 }
复制代码

 

作者:奇

出处:https://www.cnblogs.com/fanqisoft/p/10692226.html

版权:本作品采用「本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。」许可协议进行许可。

posted @   SpringCore  阅读(381)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
more_horiz
keyboard_arrow_up light_mode palette
选择主题
点击右上角即可分享
微信分享提示