Spring

redis分布式锁-redisson

时间秒杀一切 提交于 2021-02-20 12:43:08
定义连接池 package cn.cao.config ; import org.redisson.Redisson ; import org.redisson.api.RedissonClient ; import org.redisson.config.Config ; import org.springframework.beans.factory.annotation. Value ; import org.springframework.context.annotation. Bean ; import org.springframework.context.annotation. Configuration ; /** * redisson 配置类 * Created on 2020/11/01 */ @Configuration public class RedissonConfig { @Value ( "${spring.redis.host}" ) private String host ; @Value ( "${spring.redis.port}" ) private String port ; @Value ( "${spring.redis.password}" ) private String password ; @Bean public

Zipkin整合rabbitmq和mysql

隐身守侯 提交于 2021-02-20 08:59:35
存储跟踪数据 Zipkin Server默认时间追踪数据信息保存到内存,这种方式不适合生产环境。因为一旦Service关闭重 启或者服务崩溃,就会导致历史数据消失。Zipkin支持将追踪数据持久化到mysql数据库或者存储到 elasticsearch中。这里已mysql为例。 准备数据库 可以从官网找到Zipkin Server持久mysql的数据库脚本。 CREATE TABLE IF NOT EXISTS zipkin_spans ( `trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT ' If non zero, this means the trace uses 128 bit traceIds instead of 64 bit ' , `trace_id` BIGINT NOT NULL , `id` BIGINT NOT NULL , `name` VARCHAR ( 255 ) NOT NULL , `remote_service_name` VARCHAR ( 255 ), `parent_id` BIGINT , `debug` BIT ( 1 ), `start_ts` BIGINT COMMENT ' Span.timestamp(): epoch micros used for endTs query

Spring bean的生命周期

非 Y 不嫁゛ 提交于 2021-02-20 08:53:34
一、bean的生命周期 1.简介 Spring Bean 的生命周期在整个 Spring 中占有很重要的位置,从BeanFactory或ApplicationContext取得的实例为Singleton,也就是预设为每一个Bean的别名只能维持一个实例,而不是每次都产生一个新的对象使用Singleton模式产生单一实例,在spring中,singleton属性默认是true,只有设定为false,则每次指定别名取得的Bean时都会产生一个新的实例,Spring只帮我们管理单例模式Bean的完整生命周期,对于prototype的bean,Spring在创建好交给使用者之后则不会再管理后续的生命周期。 2.生命周期图 3.代码示例 spring 容器中的bean的完整生命周期一共分为十一步完成: 1.bean对象的实例化 2.封装属性,也就是设置properties中的属性值 3.如果bean实现了BeanNameAware,则执行setBeanName方法,也就是bean中的id值 4.如果实现BeanFactoryAware或者ApplicationContextAware ,需要设置setBeanFactory或者上下文对象setApplicationContext 5.如果存在类实现BeanPostProcessor后处理bean

Spring bean的生命周期

杀马特。学长 韩版系。学妹 提交于 2021-02-20 08:53:22
学习spring源码主框架,从源码角度开发学习Spring bean的生命周期。 spring创建bean方法 org.springframework.beans.factory.support.AbstractBeanFactory#getBean(java.lang.String, java.lang.Class<T>) public <T> T getBean(String name, Class<T> requiredType) throws BeansException { //doGetBean是获取bean的真实方法 return doGetBean(name, requiredType, null, false); } 真正执行spring创建bean方法doGetBean org.springframework.beans.factory.support.AbstractBeanFactory#doGetBean protected <T> T doGetBean( final String name, final Class<T> requiredType, final Object[] args, boolean typeCheckOnly) throws BeansException { //获取的beanname可能是重命名后的

spring bean的生命周期与springmvc的生命周期

喜夏-厌秋 提交于 2021-02-20 08:53:08
配置在Spring中的Bean在Spring容器中从加载到销毁会经历那些过程呢?如果实现一些特定的Spring接口,这些特定接口的方法会在什么时候被调用呢?本文简单介绍一下这些过程. Bean在Spring容器中的生命周期如下图所示: 1,调用Bean的构造函数(或者工厂方法)实例化Bean. 2,对Bean的成员变量赋值. 3,如果Bean实现了BeanNameAware,调用Bean的setBeanName方法. 4,如果Bean实现了BeanFactoryAware,调用Bean的setBeanFactory方法. 5,如果Bean实现了ApplicationContextAware,调用Bean的setApplicationContext方法. 6,如果容器中配置了BeanPostProcessor,调用BeanPostProcessor的postProcessBeforeInitialization方法(如果有多个BeanPostProcessor,调用每一个BeanPostProcessor的postProcessBeforeInitialization方法). 6,如果Bean实现了InitializingBean,调用Bean的afterPropertiesSet方法. 7,如果Bean配置了init-method方法,调用init-method配置的Bean方法.

Spring | Bean 的生命周期

谁说胖子不能爱 提交于 2021-02-20 08:37:27
作者:sunshujie1990 www.jianshu.com/p/1dec08d290c1 S pring Bean的生命周期是Spring面试热点问题。 这个问题即考察对Spring的微观了解,又考察对Spring的宏观认识,想要答好并不容易! 本文希望能够从源码角度入手,帮助面试者彻底搞定Spring Bean的生命周期。 只有四个! 是的,Spring Bean的生命周期只有这四个阶段。把这四个阶段和每个阶段对应的扩展点糅合在一起虽然没有问题,但是这样非常凌乱,难以记忆。要彻底搞清楚Spring的生命周期,首先要把这四个阶段牢牢记住。实例化和属性赋值对应构造方法和setter方法的注入,初始化和销毁是用户能自定义扩展的两个阶段。在这四步之间穿插的各种扩展点,稍后会讲。 实例化 Instantiation 属性赋值 Populate 初始化 Initialization 销毁 Destruction 实例化 -> 属性赋值 -> 初始化 -> 销毁 主要逻辑都在doCreate()方法中,逻辑很清晰,就是顺序调用以下三个方法,这三个方法与三个生命周期阶段一一对应,非常重要,在后续扩展接口分析中也会涉及。 createBeanInstance() -> 实例化 populateBean() -> 属性赋值 initializeBean() -> 初始化 源码如下,能证明实例化

Using bootBuildImage with a private Docker repository on Windows 10

怎甘沉沦 提交于 2021-02-20 04:46:07
问题 I am trying to use bootBuildImage on Windows 10 (Docker is running in WSL2 mode) and when I set up in build.gradle group = "repo.trajano.net" bootBuildImage { builder = "${project.group}/${project.name}" } I found a couple of things that look incorrect d:\dh\template-ms>gradlew bootBuildImage > Task :bootBuildImage FAILED Building image 'docker.io/library/template-ms:latest' > Pulling builder image 'repo.trajano.net/template-ms:latest' ..................................................

How to perform my own authentication (checking username and password typed by the user)

别来无恙 提交于 2021-02-20 04:35:05
问题 I implemented the UserDetailsService interface and override the loadUserByUsername method. I thought that, inside loadUserByUsername , I could get username and password, to check if they match username and password on the DB. But I can't understand how to get the password typed by the user, provided that it is possibile. Probably, I'm implementing the wrong interface. Is UserDetailsService enough to do what I want to or I have to implement or extend something else? 回答1: The UserDetailsService

Spring Security custom RememberMeAuthenticationFilter not getting fired

ぃ、小莉子 提交于 2021-02-20 04:18:50
问题 I have implemented 'Remember Me' functionality in my Spring MVC application using Spring Security 3.1 My security-context.xml looks like this : <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:security="http://www.springframework.org/schema/security" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www

How to perform a basic Spring Boot application security [closed]

依然范特西╮ 提交于 2021-02-20 04:12:42
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 9 months ago . Improve this question I'm looking forward to deploying my Spring Application on a production environment and i'd like to include some basic and solid security measures. First things first, i extended WebSecurityConfigurerAdapter into my SecurityConfiguration.java