6 changed files with 167 additions and 0 deletions
@ -0,0 +1,43 @@
|
||||
/* |
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* |
||||
* Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* Neither the name of the dreamlu.net developer nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* Author: Chill 庄骞 (smallchill@163.com) |
||||
*/ |
||||
package org.springblade.demo.config; |
||||
|
||||
|
||||
import org.springblade.core.secure.registry.SecureRegistry; |
||||
import org.springblade.demo.props.DemoProperties; |
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
||||
|
||||
/** |
||||
* Demo配置 |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@Configuration |
||||
@EnableConfigurationProperties(DemoProperties.class) |
||||
public class DemoConfiguration implements WebMvcConfigurer { |
||||
|
||||
@Bean |
||||
public SecureRegistry secureRegistry() { |
||||
SecureRegistry secureRegistry = new SecureRegistry(); |
||||
secureRegistry.excludePathPatterns("/demo/**"); |
||||
return secureRegistry; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,56 @@
|
||||
/* |
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* |
||||
* Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* Neither the name of the dreamlu.net developer nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* Author: Chill 庄骞 (smallchill@163.com) |
||||
*/ |
||||
package org.springblade.demo.controller; |
||||
|
||||
import org.springblade.demo.props.DemoProperties; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.cloud.context.config.annotation.RefreshScope; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* Demo控制器 |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@RefreshScope |
||||
@RestController |
||||
@RequestMapping("demo") |
||||
public class DemoController { |
||||
|
||||
@Value("${demo.name}") |
||||
private String name; |
||||
|
||||
private final DemoProperties properties; |
||||
|
||||
public DemoController(DemoProperties properties) { |
||||
this.properties = properties; |
||||
} |
||||
|
||||
|
||||
@GetMapping("name") |
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
@GetMapping("name-by-props") |
||||
public String getNameByProps() { |
||||
return properties.getName(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,42 @@
|
||||
/* |
||||
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* |
||||
* Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* Neither the name of the dreamlu.net developer nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* Author: Chill 庄骞 (smallchill@163.com) |
||||
*/ |
||||
package org.springblade.demo.launcher; |
||||
|
||||
import org.springblade.core.auto.service.AutoService; |
||||
import org.springblade.core.launch.constant.NacosConstant; |
||||
import org.springblade.core.launch.service.LauncherService; |
||||
import org.springframework.boot.builder.SpringApplicationBuilder; |
||||
|
||||
import java.util.Properties; |
||||
|
||||
/** |
||||
* 启动参数拓展 |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@AutoService(LauncherService.class) |
||||
public class DemoLauncherServiceImpl implements LauncherService { |
||||
|
||||
@Override |
||||
public void launcher(SpringApplicationBuilder builder, String appName, String profile, boolean isLocalDev) { |
||||
Properties props = System.getProperties(); |
||||
props.setProperty("spring.cloud.nacos.config.ext-config[0].data-id", NacosConstant.dataId(appName, profile)); |
||||
props.setProperty("spring.cloud.nacos.config.ext-config[0].group", NacosConstant.NACOS_CONFIG_GROUP); |
||||
props.setProperty("spring.cloud.nacos.config.ext-config[0].refresh", NacosConstant.NACOS_CONFIG_REFRESH); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,18 @@
|
||||
package org.springblade.demo.props; |
||||
|
||||
import lombok.Data; |
||||
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
|
||||
/** |
||||
* DemoProperties |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@Data |
||||
@ConfigurationProperties(prefix = "demo") |
||||
public class DemoProperties { |
||||
/** |
||||
* 名称 |
||||
*/ |
||||
private String name; |
||||
} |
Loading…
Reference in new issue