springboot之零碎小知识
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之零碎小知识的更多相关文章
- thinkphp零碎小知识
在使用thinkphp搭建后台的时候,有很多的参数需要去配置,有的记不住还要去查找,这里把一些基本的参数整理一下,还有些零碎的知识点,与大家共勉,希望能方便大家. 友情提示:这些配置是 thinkph ...
- JS零碎小知识
filter()方法对数组进行过滤,生成新数组 var aqiNewData = aqiData.filter(function(data){ return data[1]>60; }); // ...
- HTML+css零碎小知识
1.设置了float浮动的元素和绝对定位position:absolute的元素会脱离正常的文档流.但是设置absolute的元素不会占据空间,相当于隐形了. 2.相对定位position:rel ...
- 关于JSON的零碎小知识
1.ali的fastjson在将实体类转成jsonString的时候,一些首字母大写的字段会自动修改为小字母,这种字段加 @JsonProperty(value = "DL_id" ...
- 关于JAVA的一些零碎小知识
1.经常遇到集合之间需要互相转化的 Array和List转化:Arrays.asList(数组):list.toArray(); List和Set转化:Set<String> set = ...
- 极简SpringBoot指南-Chapter00-学习SpringBoot前的基本知识
仓库地址 w4ngzhen/springboot-simple-guide: This is a project that guides SpringBoot users to get started ...
- 蓝牙Bluetooth技术小知识
蓝牙Bluetooth技术以及广泛的应用于各种设备,并将继续在物联网IoT领域担任重要角色.下面搜集整理了一些关于蓝牙技术的小知识,以备参考. 蓝牙Bluetooth技术始创于1994年,其名字来源于 ...
- HTML+CSS中的一些小知识
今天分享一些HTML.CSS的小知识,希望能够对大家有所帮助! 1.解决网页乱码的问题:最重要的是要保证各个环节的字符编码一致! (1)编辑器的编辑环境的字符集(默认字符集):Crtl+U 常见的编码 ...
- iOS APP开发的小知识(分享)
亿合科技小编发现从2007年第一款智能手机横空出世,由此开启了人们的移动智能时代.我们从一开始对APP的陌生,到现在的爱不释手,可见APP开发的出现对我们的生活改变有多巨大.而iOS AP ...
随机推荐
- 笔记:Windows Server2008R2服务安装
Windows Server2008R2 服务安装 服务一:IIS,internet information services,互联网信息服务,微软开发的运行在Windows系统中互联网服务,提供了w ...
- java基础-01:dos命令
进入cmd方式 win + r 输入 cmd 随便进入一个文件夹 在导航栏输入cmd,回车即进入命令行 命令 盘符切换:直接输入 E: ,回车即可 查看文件夹下所有目录:dir 切换目录: cd 跨盘 ...
- 第2章 Hive安装
第2章 Hive安装 2.1 Hive安装地址 1.Hive官网地址 http://hive.apache.org/ 2.文档查看地址 https://cwiki.apache.org/conflue ...
- rcp
rcp的命令 rcp,远程文件复制.rcp既可以在本地主机和远程主机之间进行文件复制,也可以用于在两个远程主机之间进行文件复制.除了复制文件外,rcp也可以用于目录复制,只需要加参数-r. rcp的命 ...
- 区块链入门到实战(17)之以太坊(Ethereum) – 是什么
以太坊的作用:构建基于区块链的分布式应用. 以太坊是什么:可编程的虚拟币. 以太坊(Ethereum)是一个可编程的虚拟币,它是一个基于公共区块链的分布式计算平台,可用于构建基于区块链的分布式应用. ...
- RabbitMQ配置文件(rabbitmq.conf)
rabbitmq.conf配置文件示例: #====================================== #RabbitMQ经纪人部分 #======================= ...
- Python爬虫实战点触验证码, 模拟登陆bilibili
爬虫思路如下: 利用自动化爬虫工具 Selenium 模拟点击输入等操作来进行登录 分析页面,获取点触验证码的点触图片,通过将图片发送给超级鹰打码平台识别后获取坐标信息 根据超级鹰返回的数据,模拟坐标 ...
- Spine学习六 - 碰撞检测
相信在使用Spine做游戏的时候,肯定会遇到这样的需求: 一个人物有一把大刀,要使用这把大刀去砍怪,伤害检测以这把大刀砍刀怪物为准,那么要怎么在一个看上去就是一体的Spine Object上绑定一个碰 ...
- HDU-Tick and Tick
The three hands of the clock are rotating every second and meeting each other many times everyday. F ...
- Codeforces 1324F Maximum White Subtree DFS
题意 给你无根一颗树,每个节点是黑色或白色.对于每一个节点,问包含该节点的权值最大的子树. 子树的权值等于子树中白点的个数减去黑点的个数. 注意,这里的子树指的是树的联通子图. 解题思路 这场就这题卡 ...