/* * << * Davinci * == * Copyright (C) 2016 - 2019 EDP * == * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * >> * */ package edp; import com.alibaba.nacos.api.annotation.NacosInjected; import com.alibaba.nacos.api.config.annotation.NacosValue; import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.client.naming.utils.CollectionUtils; import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.scheduling.annotation.EnableScheduling; import javax.annotation.PostConstruct; @SpringBootApplication(exclude = { org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration.class, org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class }) @NacosPropertySource(dataId = "taihu-analysis", autoRefreshed = true) @EnableScheduling public class DavinciServerApplication { @NacosInjected private NamingService namingService; @Value("${server.port}") private int serverPort; @NacosValue(value = "${person.name}", autoRefreshed = true) private String name; @Value("${nacos.discovery.server-addr}") private String serverAddr; @Value("${spring.application.name}") private String applicationName; //curl -X PUT 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=xxx&ip=127.0.0.1&port=8080' @PostConstruct public void registerInstance() throws NacosException { System.out.println(name); if(CollectionUtils.isEmpty(namingService.getAllInstances(applicationName))){ namingService.registerInstance(applicationName,serverAddr,serverPort); } } public static void main(String[] args) { System.setProperty("mail.mime.splitlongparameters", "false"); SpringApplication.run(DavinciServerApplication.class, args); } @Value("${jwtToken.secret:Pa@ss@Word}") private String tokenSecret; @Bean public String TOKEN_SECRET() { return tokenSecret; } }