配置

创建项目的时候选择

application.yml内容如下

spring:
redis:
host: 127.0.0.1
port: 6379
database: 0 datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/alertremotecontrol?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC&useSSL=true
username: root
password: 123456 jpa:
hibernate:
ddl-auto: update
show-sql: true
user:
redis_prefix: USERS_REDIS_PREFIX
token_name: LOGIN_TOKEN

Redis

    @Autowired
private StringRedisTemplate template;
....
template.opsForValue().set("hello", para);
template.expire("hello", 60, TimeUnit.SECONDS);

日志

每一个类添加成员

private final Logger logger = LoggerFactory.getLogger(getClass());

然后记录的时候,logger.info("xxx"),logger.error("xxx")即可。

如果还要记录到文件,YML配置添加

logging:
file: ./logback.txt

netty

Springboot中集成Netty

Springboot主类实现 接口

CommandLineRunner

在run方法中运行netty 。

Handler中注入Springboot对象,比如UserService

public class UserHandler extends ChannelInboundHandlerAdapter {
private static UserService userService;
static {
userService = SpringUtil.getBean(UserService.class);
}
import org.springframework.context.ApplicationContext;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component; @Component
public class SpringUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext; @Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
if (SpringUtil.applicationContext == null) {
SpringUtil.applicationContext=applicationContext;
}
} public static ApplicationContext getApplicationContext() {
return applicationContext;
} public static Object getBean(String name) {
return getApplicationContext().getBean(name);
} public static <T> T getBean(Class<T> clazz) {
return getApplicationContext().getBean(clazz);
} public static <T> T getBean(String name, Class<T> clazz) {
return getApplicationContext().getBean(name, clazz);
}
}

SpringUtil的代码

异步执行

@SpringBootApplication注解下面加上

@EnableAsync注解

需要异步的方法上加上@Async注解

该类前面加上@Component注解

打包和运行

在下面 terminal中输入

mvn package -DskipTests

或者在“Maven”窗口中先点击,表示不测试,然后然后双击package

在target目录中有jar包生成

运行

java -jar XYZ.jar

注意Win10控制台默认点击窗口会暂停程序,

此时需要右键窗口,点击“属性”,取消勾选“快速编辑模式”

springboot 极简使用例子: redis,MySql数据库,日志,netty,打包和运行的更多相关文章

  1. MySQL数据库日志文件(redo与undo)

    +++++++++++++++++++++++++++++++++++++++++++标题:MySQL数据库日志文件时间:2019年2月25日内容:MySQL数据库日志文件(redo日志和undo日志 ...

  2. Mysql数据库日志类型查询与配置详解

    在mysql中日志分为很多种,下面小编来给大家介绍Mysql数据库日志类型查询与使用,希望对各位同学会有所帮助 mysql常见的日志类型有五种:错误日志.二进制日志.查询日志.慢查日志和中继日志. 一 ...

  3. delphi+mysql做的图书管理系统,怎么把mysql数据库也一起打包进去?我用的是delphi的Express组件。

    sqlconnection,sqlquery1这些组件,我连接数据库的时候是用对象编辑器里的属性进行连接的,在sqlconnection中指定了字符集utf8,有些人做的方法是利用代码连接的数据库,如 ...

  4. 发布Rest风格的WebService的SpringBoot极简例子

    JDK:1.8.0_212 IDE:STS4(Spring Tool Suit4 Version: 4.3.2.RELEASE) 工程下载:https://files.cnblogs.com/file ...

  5. SpringBoot框架:使用mybatis连接mysql数据库完成数据访问(二)

    一.导入依赖包 1.在创建项目时勾选: 勾选SQL中的JDBC API.MyBatis Framework.MySQL Driver,创建项目后就会自动配置和引入这些包. 2.在pom.xml文件中添 ...

  6. Springboot+mybatis中整合过程访问Mysql数据库时报错

    报错原因如下:com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone.. 产生这个 ...

  7. SpringBoot 集成 Mybatis 使用 Druid数据源 MySQL数据库

    思路: 1.创建项目 项目结构如下: 2.导入相应包 POM.xml文件如下: <?xml version="1.0" encoding="UTF-8"? ...

  8. 《Springboot极简教程》问题解决:Springboot启动报错 Whitelabel Error Page: This application has no explicit mapping for(转)

    13.2 Spring Boot启动报错:Whitelabel Error Page 13.2 Spring Boot启动报错:Whitelabel Error Page 问题描述 Whitelabe ...

  9. Mysql 数据库日志与数据文件分开

    参考:https://blog.csdn.net/jiao_fuyou/article/details/78366621 myql默认配置情况下,二进制日志文件是保存在默认的数据目录 data 下,如 ...

随机推荐

  1. USACO14MAR The Lazy Cow(Gold)

    题目 题意:平面上有 \(n\) 块草地,第 \(i\) 块草地坐标为 \((x_i,y_i)\) ,上面有 \(g_i\) 个单位的草.Bessie 可以吃到距离起始点不超过 \(k\)(这里是曼哈 ...

  2. spark实现smote近邻采样

    一.smote相关理论 (1). SMOTE是一种对普通过采样(oversampling)的一个改良.普通的过采样会使得训练集中有很多重复的样本. SMOTE的全称是Synthetic Minorit ...

  3. [题解] [AtCoder2134] Zigzag MST

    题面 题解 考虑kruscal的过程 对于三个点\(x, y, x + 1\), 我们可以将\((x, y, z), (y, x + 1, z + 1)\)看做\((x, y, z), (x, x + ...

  4. 【Nginx】Linux 环境下 Nginx 配置SSL 证书

    一.解压三个包到相同目录编译nginx cd /usr/local/src/nginx-1.12.2 # 将下列的包版本号换成自己下载的版本号 ./configure --prefix=/usr/lo ...

  5. git commit 合并到指定分支

    1. 将指定的commit合并到当前分支 git cherry-pick  commit_id 2. 合并多个连续 commit 到指定分支 假设需要合并 devlop 上从 fb407a3f 到 9 ...

  6. linux中~和/,$和#的区别

    /是目录层的分隔.表示符.只有一个/表明是root,/etc/表明是根目录下面的etc目录(当然目录最后不需要/,但有/直接表明他是目录,没有末尾的/,那么/etc需要检测一下确定是目录还是文件,虽然 ...

  7. CSS标签详解

    CSS3标签 Css3概述 从2010年开始,HTML5与CSS3就一直是互联网技术中最受关注的两个话题.从前端技术的角度可以把互联网的发展分为三个阶段:第一阶段是web1.0以内容为主的网络,前端主 ...

  8. Vue常见的框架

    1. Element:一套为开发者,设计师和产品经理准备的基于Vue 2.0的桌面端组件库 地址:https://element.eleme.cn/#/zh-CN 2.iview:主要服务于PC界面的 ...

  9. LC 861. Score After Flipping Matrix

    We have a two dimensional matrix A where each value is 0 or 1. A move consists of choosing any row o ...

  10. JSON-Runoob-工具:Json 格式化工具

    ylbtech-JSON-Runoob-工具:Json 格式化工具 1.返回顶部 1. http://c.runoob.com/front-end/53 2. 2.返回顶部   3.返回顶部   4. ...