spring中 Bean的生命周期, 一个对象的创建,并不单单是 new 了之后就可以了. 因为99%情况下,这个对象中是还有一些别的属性的, 还需要对这些属性赋值, new操作仅仅是创建了该对象,属性未赋值, Bean的生命周期就是, 从容器new 对象开始, 容器为这个对象各种赋值 和 AOP切 ...
分类:
编程语言 时间:
2020-07-24 21:31:09
阅读次数:
76
package com.summer.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org ...
分类:
编程语言 时间:
2020-07-24 21:14:33
阅读次数:
58
Spring1.1.1.1创建一个beanpackagecom.zt.spring;publicclassMyBean{privateStringuserName;privateIntegeruserAge;}1.1.1.2配置Config配置beanpackagecom.zt.spring;importorg.springframework.context.annotation.Bean;imp
分类:
编程语言 时间:
2020-07-24 13:30:44
阅读次数:
72
1. 配置类有3次机会可以去覆盖配置,这对于框架封装是很有好处的 1 // 2. 在 bean 生成后,populateBean() 时,在 application.yml 配置文件里面进行覆盖 2 @ConfigurationProperties(prefix = "cas") 3 public ...
分类:
编程语言 时间:
2020-07-24 13:24:29
阅读次数:
85
方法一 配置类 //redis配置类 @Configuration public class RedisConf extends CachingConfigurerSupport { /* 配置自定义RedisTemplate */ @Bean public RedisTemplate<String ...
分类:
编程语言 时间:
2020-07-22 20:59:54
阅读次数:
138
springboot集成redis序列化的问题 在springboot中RedisTemplate默认使用的是Java本地的序列化(JdkSerializationRedisSerializer)方式 public void afterPropertiesSet() { super.afterPro ...
分类:
编程语言 时间:
2020-07-22 20:56:29
阅读次数:
85
springboot 使用restTemplate发送post请求,传json数据,结果报错401 Unauthorized: [no body] 添加相应的数据格式就解决了 @Bean public RestTemplate registerTemplate() { RestTemplate re ...
分类:
其他好文 时间:
2020-07-22 20:32:37
阅读次数:
286
今天在项目中,遇见需要在websocket中注入redis工具类,最后发现通过@Autowired无法注入,最后网上搜寻了下答案,大致原因为spring管理的都是单例(singleton),和 websocket (多对象)相冲突。因为websocket是多实例单线程的,而websocket中的对象 ...
分类:
Web程序 时间:
2020-07-22 11:33:33
阅读次数:
97
测试类中的问题和解决思路 问题 在测试类中,每个测试方法都有以下两行代码: ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml"); IAccountService as = ac.getBean("account ...
分类:
编程语言 时间:
2020-07-22 11:28:09
阅读次数:
60
引用的jar包(maven) <properties> <java.version>1.8</java.version> <ch.qos.logback.version>1.2.3</ch.qos.logback.version> <sharding-sphere.version>4.1.1</sh ...
分类:
编程语言 时间:
2020-07-21 21:58:23
阅读次数:
74