1.springboot启动类加载yml配置项

主要是如下方法,读取了yml的配置项,赋值为类成员属性

  1. @Autowired
  2. public void setEnvironment(Environment environment) {
  3. host = environment.getProperty("server.port");
  4. }
  1. package com.shy;
  2.  
  3. import com.shy.iot.facerecognition2.tcp.Server;
  4. import com.shy.iot.netty.server.NettyServer;
  5. import org.apache.catalina.Context;
  6. import org.apache.catalina.connector.Connector;
  7. import org.apache.tomcat.util.descriptor.web.SecurityCollection;
  8. import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
  9. import org.mybatis.spring.annotation.MapperScan;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.boot.SpringApplication;
  12. import org.springframework.boot.autoconfigure.SpringBootApplication;
  13. import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
  14. import org.springframework.cache.annotation.EnableCaching;
  15. import org.springframework.context.ConfigurableApplicationContext;
  16. import org.springframework.context.annotation.Bean;
  17. import org.springframework.core.env.Environment;
  18. import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  19. import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  20.  
  21. @SpringBootApplication
  22. @EnableCaching
  23. @EnableWebMvc
  24. @MapperScan("com.shy.iot.*.dao")
  25. public class CentralPlatformApp extends WebMvcConfigurerAdapter {
  26.  
  27. String host;
  28.  
  29. public static void main(String[] args) throws InterruptedException {
  30. ConfigurableApplicationContext ctx = SpringApplication.run(CentralPlatformApp.class, args);
  31. String flag = ctx.getEnvironment().getProperty("netty.isStart");
  32. if ("start".equals(flag)) {//判断当前项目启动是否要启动智能家居模块
  33. NettyServer nettyServer = (NettyServer) ctx.getBean("nettyServer");
  34. nettyServer.start();
  35. }
  36. Server bean = ctx.getBean(Server.class);
  37. bean.run();
  38. }
  39.  
  40. @Autowired
  41. public void setEnvironment(Environment environment) {
  42. host = environment.getProperty("server.port");
  43. }
  44.  
  45. /**
  46. * it's for set http url auto change to https
  47. */
  48. @Bean
  49. public TomcatEmbeddedServletContainerFactory servletContainer() {
  50. TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
  51. @Override
  52. protected void postProcessContext(Context context) {
  53. SecurityConstraint securityConstraint = new SecurityConstraint();
  54. securityConstraint.setUserConstraint("CONFIDENTIAL");//confidential
  55. SecurityCollection collection = new SecurityCollection();
  56. collection.addPattern("/*");
  57. securityConstraint.addCollection(collection);
  58. context.addConstraint(securityConstraint);
  59. }
  60. };
  61. tomcat.addAdditionalTomcatConnectors(httpConnector());
  62. return tomcat;
  63. }
  64.  
  65. @Bean
  66. public Connector httpConnector() {
  67. Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
  68. connector.setScheme("http");
  69. connector.setPort(9000);
  70. connector.setSecure(true);
  71. connector.setRedirectPort(Integer.parseInt(host));
  72. return connector;
  73. }
  74. }

springboot之零碎小知识的更多相关文章

  1. thinkphp零碎小知识

    在使用thinkphp搭建后台的时候,有很多的参数需要去配置,有的记不住还要去查找,这里把一些基本的参数整理一下,还有些零碎的知识点,与大家共勉,希望能方便大家. 友情提示:这些配置是 thinkph ...

  2. JS零碎小知识

    filter()方法对数组进行过滤,生成新数组 var aqiNewData = aqiData.filter(function(data){ return data[1]>60; }); // ...

  3. HTML+css零碎小知识

    1.设置了float浮动的元素和绝对定位position:absolute的元素会脱离正常的文档流.但是设置absolute的元素不会占据空间,相当于隐形了.   2.相对定位position:rel ...

  4. 关于JSON的零碎小知识

    1.ali的fastjson在将实体类转成jsonString的时候,一些首字母大写的字段会自动修改为小字母,这种字段加 @JsonProperty(value = "DL_id" ...

  5. 关于JAVA的一些零碎小知识

    1.经常遇到集合之间需要互相转化的 Array和List转化:Arrays.asList(数组):list.toArray(); List和Set转化:Set<String> set = ...

  6. 极简SpringBoot指南-Chapter00-学习SpringBoot前的基本知识

    仓库地址 w4ngzhen/springboot-simple-guide: This is a project that guides SpringBoot users to get started ...

  7. 蓝牙Bluetooth技术小知识

    蓝牙Bluetooth技术以及广泛的应用于各种设备,并将继续在物联网IoT领域担任重要角色.下面搜集整理了一些关于蓝牙技术的小知识,以备参考. 蓝牙Bluetooth技术始创于1994年,其名字来源于 ...

  8. HTML+CSS中的一些小知识

    今天分享一些HTML.CSS的小知识,希望能够对大家有所帮助! 1.解决网页乱码的问题:最重要的是要保证各个环节的字符编码一致! (1)编辑器的编辑环境的字符集(默认字符集):Crtl+U 常见的编码 ...

  9. iOS APP开发的小知识(分享)

          亿合科技小编发现从2007年第一款智能手机横空出世,由此开启了人们的移动智能时代.我们从一开始对APP的陌生,到现在的爱不释手,可见APP开发的出现对我们的生活改变有多巨大.而iOS AP ...

随机推荐

  1. 面试官最爱的 volatile 关键字,这些问题你都搞懂了没?

    前言 volatile相关的知识点,在面试过程中,属于基础问题,是必须要掌握的知识点,如果回答不上来会严重扣分的哦. volatile关键字基本介绍 volatile可以看成是synchronized ...

  2. 数据结构与算法笔记(java)目录

    数据结构: 一个动态可视化数据结构的网站 线性结构 数组 动态数组 链表 单向链表 双向链表 单向循环链表 双向循环链表 栈 栈 队列 队列 双端队列 哈希表 树形结构 二叉树 二叉树 二叉搜索树 A ...

  3. vue-cli的安装及版本查看/更新

    vue-cli的安装及版本查看更新 vue-cli安装 npm install vue-cli -g vue-cli的版本查看 vue -V vue-cli的3.0+以后使用的不是vue-cli了,如 ...

  4. python基础 Day6

    python Day6 id 可以获得python的内存地址 id的举例子 a=100 print(id(a)) #140712544153072 这里就是该对象的内存地址 is 判断的是比较内存地址 ...

  5. WARNING: The host 'db01' could not be looked up with /data/mysql/bin/resolveip. This probably means that your libc libraries are not 100 % compatible with this binary MySQL version......

    Linux系统安装MySQL,环境参数: 硬件配置:CPU: Xeon(R) CPU E5-2650 v4 @ 2.20GHz 8核内存:16G硬盘:系统盘200GB 数据盘1TB 操作系统CentO ...

  6. git提交限制后提交出错的暴力解决 (使用小乌龟)

    1.右键-> TortoiseGit-> 显示日志 2.右键->重置到哪个版本 3. 重新修改提交信息提交

  7. 什么是RPC,RPC好处,常用的RPC框架

    RPC简介 RPC(Remote Procedure Call Protocol)远程过程调用协议.一个通俗的描述是:客户端在不知道调用细节的情况下,调用存在于远程计算机上的某个对象,就像调用本地应用 ...

  8. neighbor和neigh_modify(转载)

    (转载:http://blog.sina.com.cn/s/blog_b48a7ac30102w4mg.html###) 以下取自:http://simulation.haotui.com/viewt ...

  9. vmware虚拟机Bridged(桥接模式)、NAT(网络地址转换模式)、Host-Only(仅主机模式)详解

    原文来自http://note.youdao.com/share/web/file.html?id=236896997b6ffbaa8e0d92eacd13abbf&type=note 我怕链 ...

  10. oracle坑。

    char(2)的,后面的有一个空格.删不掉.在plsql里可以正常查.写死的sql在程序也可以正常查. 程序用占位符的形式,不能查出来.只能转成to_number select t.*,t.rowid ...