DavinciServerApplication.java 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2019 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. * >>
  17. *
  18. */
  19. package edp;
  20. import com.alibaba.nacos.api.annotation.NacosInjected;
  21. import com.alibaba.nacos.api.config.annotation.NacosValue;
  22. import com.alibaba.nacos.api.exception.NacosException;
  23. import com.alibaba.nacos.api.naming.NamingService;
  24. import com.alibaba.nacos.client.naming.utils.CollectionUtils;
  25. import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
  26. import org.springframework.beans.factory.annotation.Value;
  27. import org.springframework.boot.SpringApplication;
  28. import org.springframework.boot.autoconfigure.SpringBootApplication;
  29. import org.springframework.context.annotation.Bean;
  30. import org.springframework.scheduling.annotation.EnableScheduling;
  31. import javax.annotation.PostConstruct;
  32. @SpringBootApplication(exclude = {
  33. org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration.class,
  34. org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
  35. })
  36. @NacosPropertySource(dataId = "taihu-analysis", autoRefreshed = true)
  37. @EnableScheduling
  38. public class DavinciServerApplication {
  39. @NacosInjected
  40. private NamingService namingService;
  41. @Value("${server.port}")
  42. private int serverPort;
  43. @NacosValue(value = "${person.name}", autoRefreshed = true)
  44. private String name;
  45. @Value("${nacos.discovery.server-addr}")
  46. private String serverAddr;
  47. @Value("${spring.application.name}")
  48. private String applicationName;
  49. //curl -X PUT 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=xxx&ip=127.0.0.1&port=8080'
  50. @PostConstruct
  51. public void registerInstance() throws NacosException
  52. {
  53. System.out.println(name);
  54. if(CollectionUtils.isEmpty(namingService.getAllInstances(applicationName))){
  55. namingService.registerInstance(applicationName,serverAddr,serverPort);
  56. }
  57. }
  58. public static void main(String[] args) {
  59. System.setProperty("mail.mime.splitlongparameters", "false");
  60. SpringApplication.run(DavinciServerApplication.class, args);
  61. }
  62. @Value("${jwtToken.secret:Pa@ss@Word}")
  63. private String tokenSecret;
  64. @Bean
  65. public String TOKEN_SECRET() {
  66. return tokenSecret;
  67. }
  68. }