From 6af6a9e6e7bc3a9baa70d07bf07b6b7d6db9a3b2 Mon Sep 17 00:00:00 2001 From: smallchill Date: Wed, 22 May 2019 17:41:33 +0800 Subject: [PATCH] =?UTF-8?q?:tada:=20=E5=A2=9E=E5=8A=A0nacos=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=8C=87=E5=AE=9A=E8=8E=B7=E5=8F=96=E3=80=81=E5=88=B7?= =?UTF-8?q?=E6=96=B0demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blade-service/blade-demo/pom.xml | 6 ++ .../demo/config/DemoConfiguration.java | 43 ++++++++++++++ .../demo/controller/DemoController.java | 56 +++++++++++++++++++ .../launcher/DemoLauncherServiceImpl.java | 42 ++++++++++++++ .../demo/props/DemoProperties.java | 18 ++++++ doc/nacos/blade-demo-dev.yaml | 2 + 6 files changed, 167 insertions(+) create mode 100644 blade-service/blade-demo/src/main/java/org/springblade/demo/config/DemoConfiguration.java create mode 100644 blade-service/blade-demo/src/main/java/org/springblade/demo/controller/DemoController.java create mode 100644 blade-service/blade-demo/src/main/java/org/springblade/demo/launcher/DemoLauncherServiceImpl.java create mode 100644 blade-service/blade-demo/src/main/java/org/springblade/demo/props/DemoProperties.java create mode 100644 doc/nacos/blade-demo-dev.yaml diff --git a/blade-service/blade-demo/pom.xml b/blade-service/blade-demo/pom.xml index e8e17ac84..bac353a6a 100644 --- a/blade-service/blade-demo/pom.xml +++ b/blade-service/blade-demo/pom.xml @@ -32,6 +32,12 @@ blade-demo-api ${bladex.project.version} + + org.springblade + blade-core-auto + ${bladex.tool.version} + provided + diff --git a/blade-service/blade-demo/src/main/java/org/springblade/demo/config/DemoConfiguration.java b/blade-service/blade-demo/src/main/java/org/springblade/demo/config/DemoConfiguration.java new file mode 100644 index 000000000..95d68532f --- /dev/null +++ b/blade-service/blade-demo/src/main/java/org/springblade/demo/config/DemoConfiguration.java @@ -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; + } + +} diff --git a/blade-service/blade-demo/src/main/java/org/springblade/demo/controller/DemoController.java b/blade-service/blade-demo/src/main/java/org/springblade/demo/controller/DemoController.java new file mode 100644 index 000000000..5db3a3a3f --- /dev/null +++ b/blade-service/blade-demo/src/main/java/org/springblade/demo/controller/DemoController.java @@ -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(); + } + +} diff --git a/blade-service/blade-demo/src/main/java/org/springblade/demo/launcher/DemoLauncherServiceImpl.java b/blade-service/blade-demo/src/main/java/org/springblade/demo/launcher/DemoLauncherServiceImpl.java new file mode 100644 index 000000000..ea205e17a --- /dev/null +++ b/blade-service/blade-demo/src/main/java/org/springblade/demo/launcher/DemoLauncherServiceImpl.java @@ -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); + } + +} diff --git a/blade-service/blade-demo/src/main/java/org/springblade/demo/props/DemoProperties.java b/blade-service/blade-demo/src/main/java/org/springblade/demo/props/DemoProperties.java new file mode 100644 index 000000000..0306f7dbd --- /dev/null +++ b/blade-service/blade-demo/src/main/java/org/springblade/demo/props/DemoProperties.java @@ -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; +} diff --git a/doc/nacos/blade-demo-dev.yaml b/doc/nacos/blade-demo-dev.yaml new file mode 100644 index 000000000..33e464ffb --- /dev/null +++ b/doc/nacos/blade-demo-dev.yaml @@ -0,0 +1,2 @@ +demo: + name: demo-name