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

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

@Autowired
public void setEnvironment(Environment environment) {
host = environment.getProperty("server.port");
}
package com.shy;

import com.shy.iot.facerecognition2.tcp.Server;
import com.shy.iot.netty.server.NettyServer;
import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; @SpringBootApplication
@EnableCaching
@EnableWebMvc
@MapperScan("com.shy.iot.*.dao")
public class CentralPlatformApp extends WebMvcConfigurerAdapter { String host; public static void main(String[] args) throws InterruptedException {
ConfigurableApplicationContext ctx = SpringApplication.run(CentralPlatformApp.class, args);
String flag = ctx.getEnvironment().getProperty("netty.isStart");
if ("start".equals(flag)) {//判断当前项目启动是否要启动智能家居模块
NettyServer nettyServer = (NettyServer) ctx.getBean("nettyServer");
nettyServer.start();
}
Server bean = ctx.getBean(Server.class);
bean.run();
} @Autowired
public void setEnvironment(Environment environment) {
host = environment.getProperty("server.port");
} /**
* it's for set http url auto change to https
*/
@Bean
public TomcatEmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");//confidential
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(httpConnector());
return tomcat;
} @Bean
public Connector httpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(9000);
connector.setSecure(true);
connector.setRedirectPort(Integer.parseInt(host));
return connector;
}
}

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. java程序CPU 100%调试

    前置 PID为进程id,NID为线程ID 步骤一.找到最耗CPU的进程 top 然后键入P,按CPU占用率排序(M是按内存排序) 步骤二.找到进程中最耗CPU的线程 top -Hp PID 步骤三.将 ...

  2. circos pipeline

    # /usr/bin/env python# coding=utf-8#################################### Author : yunkeli# Version : ...

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

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

  4. 简明python教程--读后感--推荐给python新手

    原书名: A Byte of Python作者:  Swaroop, C. H.译者: 沈洁元出版社: 未知  优点     1. 讲解很详细,很基础,适合入门,对编译器也做了简单的介绍     2. ...

  5. 科普,想成为厉害的 Java 后端程序员,你需要懂这 13 个知识点

    老读者就请肆无忌惮地点赞吧,微信搜索[沉默王二]关注这个在九朝古都洛阳苟且偷生的程序员.本文 GitHub github.com/itwanger 已收录,里面还有我精心为你准备的一线大厂面试题. 站 ...

  6. 焦大:做seo需要的三心二意

    http://www.wocaoseo.com/thread-92-1-1.html        读过一些外国人写的教程之后,愈发觉得国外人写的教程甚是有趣,比起国内学习的课本来,真是不可同日而语. ...

  7. 架构设计 | 基于电商交易流程,图解TCC事务分段提交

    本文源码:GitHub·点这里 || GitEE·点这里 一.场景案例简介 1.场景描述 分布式事务在业务系统中是十分常见的,最经典的场景就是电商架构中的交易业务,如图: 客户端通过请求订单服务,执行 ...

  8. python笔记-标准库unittest

    unittest核心工作原理 unittest中最核心的四个概念是:test case, test suite, test runner, test fixture. 一个TestCase的实例就是一 ...

  9. es6使用箭头函数需要注意的问题

    this问题 箭头函数没有它自己的this值,箭头函数内的this值继承自外围作用域,谁定义的函数,this指向谁 箭头函数要实现类似纯函数的效果,必须剔除外部状态.所以箭头函数不具备普通函数里常见的 ...

  10. 跟着尚硅谷系统学习Docker-【day01】

    day01-20200710   p1.基础知识   鲸鱼背上有一些集装箱   学习docker得基础知识   1.强制:熟悉Linux命令和相关背景知识 2.建议有maven和git的相关知识   ...