springboot与分布式
Dubbo/ZookeeperZookeeperZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。
Docker安装参考文档https://hub.docker.com/_/zookeeper
1docker pull zookeeper
默认有3个端口。客户端2181,follow2888,election 3888
1docker run --name ZK01 -p 2181:2181 -
...
springboot与安全
SpringSecurity使用
引入依赖
1234<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
编写SpringSecurity配置类
@EnableWebSecurity 并且extends WebSecurityConfigurerAdapter
1234
...
springboot与任务
异步任务
@Async标记在方法上,指定改方法为一个异步任务
@EnableAsync启动异步任务
定时任务
@EnableScheduling 开启定时任务
@Scheduled 必填属性cron
12second as well as minute, hour, day of month, month and day of week.eg:{@code、 "0 * * * * MON-FRI"}
12345@Scheduled(cron = "0 * * * * MON-FRI")//周一至周五整秒的时候执行 public void Sch
...
springboot与检索
ElasticSearch安装docker pull elasticsearch
启动ElasticSearch默认需要使用2G的内存使用JAVA命令指定为256M
123456vim /etc/sysctl.confvm.max_map_count = 262144sysctl -p #使修改立即生效systemctl restart docker 重新启动镜像
服务端口为9200,集群通信接口为9300
如果报如下错误在启动命令上再加上 -e “discovery.type=single-node”
123ERROR: [1] bootstrap checks failed[1]: ma
...
springboot与消息
概述
大多数应用中,可以通过消息服务中间件来提升系统异步通信、扩展解耦能力
消息服务中两个重要概念
消息代理(message broker)
目的地(destination)
当消息发送者发送消息后,由消息代理接管,消息代理保证消息传递到目的地
消息队列主要有两种形式的目的地
队列:点对点消息通信(point-to-point)
主题:发布(publish)订阅(subscribe)消息通信
消息代理规范
JMS JAVA消息服务 eg: ActiveMQ HornetMQ
AMQP 高级消息队列协议规范 eg:RabbitMQ
Spring支持
spring-jms
...
springboot缓存
Spring缓存缓存注解和概念
缓存SPEL
使用在Springboot主配置类上打开注解Cache使用@EnableCaching,然后就可以在方法上使用上图中的各种缓存注解。
@Cacheable
cacheNames/values:指定缓存的名字,将方法的返回值放在哪个缓存中,可以使用数组
key:缓存数据使用的key,可以使用SPEL表达式来,如果不指定,默认使用方法参数的值
keyGenerator:key的生成器,指定key生成器的组件id,key/keyGenerator 二选一
cacheManager:指定缓存管理器或者使用 cacheResolver:指定获取解析器
...
springboot自定义starter
如何编写自动配置1234567@Configuration //指定这个类是一个自动配置类@ConditionalOnXXXX //指定在特定条件下才能生效@AutoConfigureAfter //自定自动配置的顺序@Bean给容器加组件@ConfigurationProperties //绑定XXXXProperties@EnableConfigurationProperties
需要将自动配置类放在类路径下的META-INF/spring.factories下才能生效
编写模式启动器只用来做依赖导入
springboot启动配置原理
重点的事件回调机制 配置在META-INF/spring.factories
ApplicationContextListener
SpringApplicationRunListener
在IOC容器中的
ApplicationRunner
CommandLineRunner
创建SpringApplication对象调用SpringApplication的构造方法
12345678910111213public SpringApplication(ResourceLoader resourceLoader, Class<?>... primaryS
...
springboot整合jpa问题
问题Springboot整合JPA后项目启动报错
1234567891011121314151617Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.2019-09-24 16:10:02.139 ERROR 15952 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : ***************************APPLICATI
...