xyz327

hakuna matata

_

refresh方法概览

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
public void refresh() throws BeansException, IllegalStateException {
synchronized (this.startupShutdownMonitor) {
StartupStep contextRefresh = this.applicationStartup.start("spring.context.refresh");
// Prepare this context for refreshing.
prepareRefresh();
// Tell the subclass to refresh the internal bean factory.
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();
// Prepare the bean factory for use in this context.
prepareBeanFactory(beanFactory);
try {
// Allows post-processing of the bean factory in context subclasses.
postProcessBeanFactory(beanFactory);
StartupStep beanPostProcess = this.applicationStartup.start("spring.context.beans.post-process");
// Invoke factory processors registered as beans in the context.
invokeBeanFactoryPostProcessors(beanFactory);
// Register bean processors that intercept bean creation.
registerBeanPostProcessors(beanFactory);
beanPostProcess.end();
// Initialize message source for this context.
initMessageSource();
// Initialize event multicaster for this context.
initApplicationEventMulticaster();
// Initialize other special beans in specific context subclasses.
onRefresh();
// Check for listener beans and register them.
registerListeners();
// Instantiate all remaining (non-lazy-init) singletons.
finishBeanFactoryInitialization(beanFactory);
// Last step: publish corresponding event.
finishRefresh();
} catch (BeansException ex) {
// Destroy already created singletons to avoid dangling resources.
destroyBeans();
// Reset 'active' flag.
cancelRefresh(ex);
// Propagate exception to caller.
throw ex;
} finally {
// Reset common introspection caches in Spring's core, since we
// might not ever need metadata for singleton beans anymore...
resetCommonCaches();
contextRefresh.end();
}
}
}
阅读全文 »

最原始的spring配置都是使用xml文件来作为配置(像下面这样),但是xml 写起来还是比较繁琐的

1
2
3
4
5
6
7
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="testBean" class="cn.xz.spring.TestBean"/>
</beans>

所以在spring 3的时候引入了基于java注解的配置方式,让我们可以使用java类来配置spring的Bean

@Configuration @Bean @Lazy @DependsOn 等一系列注解

所以上面的xml翻译成java配置的话就像下面这样

1
2
3
4
5
6
7
8
@Configuration
public static class BeanConfig {

@Bean
public TestBean testBean(){
return new TestBean();
}
}
阅读全文 »

最原始的spring配置都是使用xml文件来作为配置(像下面这样),但是xml 写起来还是比较繁琐的

1
2
3
4
5
6
7
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="testBean" class="cn.xz.spring.TestBean"/>
</beans>

所以在spring 3的时候引入了基于java注解的配置方式,让我们可以使用java类来配置spring的Bean

@Configuration @Bean @Lazy @DependsOn 等一系列注解

所以上面的xml翻译成java配置的话就像下面这样

1
2
3
4
5
6
7
8
@Configuration
public static class BeanConfig {

@Bean
public TestBean testBean(){
return new TestBean();
}
}
阅读全文 »

其实这个是由spring-context实现的

我们知道在spring中可以使用@Configuration注解标记的类来代替传统的xml配置,然后用@Bean注解标记方法代替<bean>标签

在@Configuration注解标记的类中如果bean有依赖我们可以这样写

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* @author xizhou
* @date 2021/6/3 22:53
*/
@Configuration
public class TestConfiguration {

@Bean
public BeanA beanA(){
return new BeanA();
}


@Bean
public BeanB beanB(){
return new BeanB(beanA());
}
}

BeanB 依赖BeanA,然后在上面的beanB()方法里面直接写调用 beanA()方法就行了.

直观来看是不是觉得会调用beanA()方法去生成一个BeanA对象。但是如果是这样的话,就和上面的beanA()方法注入到springIOC容器的对象不是同一个了,这明显是不正确的。

阅读全文 »

两个线程循环输出1-100,一个输出奇数,一个输出偶数

可以用Condition去实现这个功能。开启两个线程去获取同一个可重入锁.获取到锁之后打印当前的值,再使用condition.signal()唤醒另一个线程,然后自己condition.await()。最后释放锁。两个线程使用同样的代码。每次只有一个线程运行进行来实现交替输出

直接上代码

阅读全文 »

7. 整数反转 - 力扣(LeetCode) (leetcode-cn.com)

用以10取模的方式依次把x的最小位的数字取出,然后以*10的方式累加

1.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
func reverse(x int) int {
res := 0
for x != 0 {
// 判断数据是否溢出
if x > 0 && res > (math.MaxInt32 - x % 10) / 10 {
return 0
}
if x < 0 && res < (math.MinInt32 - x % 10) / 10 {
return 0
}
// res * 10 + x 的最后一位数
res = res * 10 + x % 10
x = x / 10
}
return res
}

1. 两数之和 - 力扣(LeetCode) (leetcode-cn.com)

解题思路:
x+y=target;

解题1:

用双重循环的方式

1
2
3
4
5
6
7
8
9
10
11
12
13
func twoSum(nums []int, target int) []int {
for i, x := range nums {
for j, y := range nums {
if i == j {
continue
}
if x + y == target {
return []int{x, y};
}
}
}
return nil
}

解题2

阅读全文 »

问题起因

在公司接口使用了统一的数据返回格式

1
2
3
4
5
{
"code":0,
"msg": "",
"data": ...
}

但是在实现接口 sdk 时只需要 data 类型就够了。

1
2
3
4
5
public interface TestApi{

@GetMapping("status")
public Boolean getStatus();
}

所以在反序列化时使用了 fastjson 通过 ParameterizedTypeImpl 来实现.

阅读全文 »

Jira/Bitbucket/Confluence

项目代码托管,协作,问题追踪三件套。这三个软件同时使用时可以将用户统一托管给Jira管理.
但是一般公司会有自己的账户体系并且使用了 CAS 作为统一登录管理.
这个时候就可以将这三个系统的登录以及用户管理交由CAS来完成

CAS

由耶鲁大学开源的一套单点登录系统
基于SAML协议来做SSO认证. CAS 可以支持多种认证协议.只需要做下简单的配置就行

阅读全文 »

排序算法

选择排序

不断的选择剩余元素中的最小值

  1. 找到最小的元素并和集合第一个元素交换
  2. 在剩下的元素中找到最小的元素并和集合第二个元素交换
  3. 重复步骤直至将整个集合排序

直接插入排序

基本思想:每一步将一个待排序的数据插入到前面已经排好序的有序序列中,直到插完所有元素为止。

阅读全文 »