BeanPostProcessor妙用(转载)

BeanPostProcessor妙用(转载)

BeanPostProcessor简介

BeanPostProcessor是Spring IOC容器给我们提供的一个扩展接口。接口声明如下:


 
 
  1. public interface BeanPostProcessor {
  2. //bean初始化方法调用前被调用
  3. Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException;
  4. //bean初始化方法调用后被调用
  5. Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException;
  6. }

如上接口声明所示,BeanPostProcessor接口有两个回调方法。当一个BeanPostProcessor的实现类注册到Spring IOC容器后,对于该Spring IOC容器所创建的每个bean实例在初始化方法(如afterPropertiesSet和任意已声明的init方法)调用前,将会调用BeanPostProcessor中的postProcessBeforeInitialization方法,而在bean实例初始化方法调用完成后,则会调用BeanPostProcessor中的postProcessAfterInitialization方法,整个调用顺序可以简单示意如下:

--> Spring IOC容器实例化Bean
--> 调用BeanPostProcessor的postProcessBeforeInitialization方法
--> 调用bean实例的初始化方法
--> 调用BeanPostProcessor的postProcessAfterInitialization方法

可以看到,Spring容器通过BeanPostProcessor给了我们一个机会对Spring管理的bean进行再加工。比如:我们可以修改bean的属性,可以给bean生成一个动态代理实例等等。一些Spring AOP的底层处理也是通过实现BeanPostProcessor来执行代理包装逻辑的。

BeanPostProcessor实战

了解了BeanPostProcessor的相关知识后,下面我们来通过项目中的一个具体例子来体验一下它的神奇功效吧。

先介绍一下我们的项目背景吧:我们项目中经常会涉及AB 测试,这就会遇到同一套接口会存在两种不同实现。实验版本与对照版本需要在运行时同时存在。下面用一些简单的类来做一个示意:


 
 
  1. public class HelloService{
  2. void sayHello();
  3. void sayHi();
  4. }

HelloService有以下两个版本的实现:


 
 
  1. @Service
  2. public class HelloServiceImplV1 implements HelloService{
  3. public void sayHello(){
  4. System.out.println( "Hello from V1");
  5. }
  6. public void sayHi(){
  7. System.out.println( "Hi from V1");
  8. }
  9. }

 
 
  1. @Service
  2. public class HelloServiceImplV2 implements HelloService{
  3. public void sayHello(){
  4. System.out.println( "Hello from V2");
  5. }
  6. public void sayHi(){
  7. System.out.println( "Hi from V2");
  8. }
  9. }

做AB测试的话,在使用BeanPostProcessor封装前,我们的调用代码大概是像下面这样子的:


 
 
  1. @Controller
  2. public class HelloController{
  3. @Autowird
  4. private HelloServiceImplV1 helloServiceImplV1;
  5. @Autowird
  6. private HelloServiceImplV2 helloServiceImplV2;
  7. public void sayHello(){
  8. if(getHelloVersion()== "A"){
  9. helloServiceImplV1.sayHello();
  10. } else{
  11. helloServiceImplV2.sayHello();
  12. }
  13. }
  14. public void sayHi(){
  15. if(getHiVersion()== "A"){
  16. helloServiceImplV1.sayHi();
  17. } else{
  18. helloServiceImplV2.sayHi();
  19. }
  20. }
  21. }

可以看到,这样的代码看起来十分不优雅,并且如果AB测试的功能点很多的话,那项目中就会充斥着大量的这种重复性分支判断,看到代码就想死有木有!!!维护代码也将会是个噩梦。比如某个功能点AB测试完毕,需要把全部功能切换到V2版本,V1版本不再需要维护,那么处理方式有两种:

  • 把A版本代码留着不管:这将会导致到处都是垃圾代码从而造成代码臃肿难以维护
  • 找到所有V1版本被调用的地方然后把相关分支删掉:这很容易在处理代码的时候删错代码从而造成生产事故。

怎么解决这个问题呢,我们先看代码,后文再给出解释:


 
 
  1. @Target({ElementType.FIELD})
  2. @Retention(RetentionPolicy.RUNTIME)
  3. @Documented
  4. @Component
  5. public @interface RoutingInjected{
  6. }

 
 
  1. @Target({ElementType.FIELD,ElementType.METHOD})
  2. @Retention(RetentionPolicy.RUNTIME)
  3. @Documented
  4. @Component
  5. public @interface RoutingSwitch{
  6. /**
  7. * 在配置系统中开关的属性名称,应用系统将会实时读取配置系统中对应开关的值来决定是调用哪个版本
  8. * @return
  9. */
  10. String value() default "";
  11. }

 
 
  1. @RoutingSwitch( "hello.switch")
  2. public class HelloService{
  3. @RoutingSwitch( "A")
  4. void sayHello();
  5. void sayHi();
  6. }

 
 
  1. @Controller
  2. public class HelloController{
  3. @RoutingInjected
  4. private HelloService helloService;
  5. public void sayHello(){
  6. this.helloService.sayHello();
  7. }
  8. public void sayHi(){
  9. this.helloService.sayHi();
  10. }
  11. }

现在我们可以停下来对比一下封装前后调用代码了,是不是感觉改造后的代码优雅很多呢?那么这是怎么实现的呢,我们一起来揭开它的神秘面纱吧,请看代码:


 
 
  1. @Component
  2. public class RoutingBeanPostProcessor implements BeanPostProcessor {
  3. @Autowired
  4. private ApplicationContext applicationContext;
  5. @Override
  6. public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
  7. return bean;
  8. }
  9. @Override
  10. public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
  11. Class clazz = bean.getClass();
  12. Field[] fields = clazz.getDeclaredFields();
  13. for (Field f : fields) {
  14. if (f.isAnnotationPresent(RoutingInjected.class)) {
  15. if (!f.getType().isInterface()) {
  16. throw new BeanCreationException( "RoutingInjected field must be declared as an interface:" + f.getName()
  17. + " @Class " + clazz.getName());
  18. }
  19. try {
  20. this.handleRoutingInjected(f, bean, f.getType());
  21. } catch (IllegalAccessException e) {
  22. throw new BeanCreationException( "Exception thrown when handleAutowiredRouting", e);
  23. }
  24. }
  25. }
  26. return bean;
  27. }
  28. private void handleRoutingInjected(Field field, Object bean, Class type) throws IllegalAccessException {
  29. Map<String, Object> candidates = this.applicationContext.getBeansOfType(type);
  30. field.setAccessible( true);
  31. if (candidates.size() == 1) {
  32. field.set(bean, candidates.values().iterator().next());
  33. } else if (candidates.size() == 2) {
  34. Object proxy = RoutingBeanProxyFactory.createProxy(type, candidates);
  35. field.set(bean, proxy);
  36. } else {
  37. throw new IllegalArgumentException( "Find more than 2 beans for type: " + type);
  38. }
  39. }
  40. }

 
 
  1. public class RoutingBeanProxyFactory {
  2. public static Object createProxy(Class targetClass, Map<String, Object> beans) {
  3. ProxyFactory proxyFactory = new ProxyFactory();
  4. proxyFactory.setInterfaces(targetClass);
  5. proxyFactory.addAdvice(new VersionRoutingMethodInterceptor(targetClass, beans));
  6. return proxyFactory.getProxy();
  7. }
  8. static class VersionRoutingMethodInterceptor implements MethodInterceptor {
  9. private String classSwitch;
  10. private Object beanOfSwitchOn;
  11. private Object beanOfSwitchOff;
  12. public VersionRoutingMethodInterceptor(Class targetClass, Map<String, Object> beans) {
  13. String interfaceName = StringUtils.uncapitalize(targetClass.getSimpleName());
  14. if(targetClass.isAnnotationPresent(RoutingSwitch. class)){
  15. this.classSwitch =((RoutingSwitch)targetClass.getAnnotation(RoutingSwitch. class)).value();
  16. }
  17. this.beanOfSwitchOn = beans. get( this.buildBeanName(interfaceName, true));
  18. this.beanOfSwitchOff = beans. get( this.buildBeanName(interfaceName, false));
  19. }
  20. private String buildBeanName(String interfaceName, boolean isSwitchOn) {
  21. return interfaceName + "Impl" + (isSwitchOn ? "V2" : "V1");
  22. }
  23. @Override
  24. public Object invoke(MethodInvocation invocation) throws Throwable {
  25. Method method = invocation.getMethod();
  26. String switchName = this.classSwitch;
  27. if (method.isAnnotationPresent(RoutingSwitch. class)) {
  28. switchName = method.getAnnotation(RoutingSwitch. class).value();
  29. }
  30. if (StringUtils.isBlank(switchName)) {
  31. throw new IllegalStateException( "RoutingSwitch's value is blank, method:" + method.getName());
  32. }
  33. return invocation.getMethod().invoke(getTargetBean(switchName), invocation.getArguments());
  34. }
  35. public Object getTargetBean(String switchName) {
  36. boolean switchOn;
  37. if (RoutingVersion.A.equals(switchName)) {
  38. switchOn = false;
  39. } else if (RoutingVersion.B.equals(switchName)) {
  40. switchOn = true;
  41. } else {
  42. switchOn = FunctionSwitch.isSwitchOpened(switchName);
  43. }
  44. return switchOn ? beanOfSwitchOn : beanOfSwitchOff;
  45. }
  46. }
  47. }

我简要解释一下思路:

  • 首先自定义了两个注解:RoutingInjected、RoutingSwitch,前者的作用类似于我们常用的Autowired,声明了该注解的属性将会被注入一个路由代理类实例;后者的作用则是一个配置开关,声明了控制路由的开关属性
  • 在RoutingBeanPostProcessor类中,我们在postProcessAfterInitialization方法中通过检查bean中是否存在声明了RoutingInjected注解的属性,如果发现存在该注解则给该属性注入一个动态代理类实例
  • RoutingBeanProxyFactory类功能就是生成一个代理类实例,代理类的逻辑也比较简单。版本路由支持到方法级别,即优先检查方法是否存在路由配置RoutingSwitch,方法不存在配置时才默认使用类路由配置

好了,BeanPostProcessor的介绍就到这里了。不知道看过后大家有没有得到一些启发呢?欢迎大家留言交流反馈。今天就到这里,我们下期再见吧 哈哈哈

  •                     <li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#csdnc-thumbsup"></use>
                        </svg><span class="name">点赞</span>
                        <span class="count">2</span>
                        </a></li>
                        <li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;popu_824&quot;}"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-Collection-G"></use>
                        </svg><span class="name">收藏</span></a></li>
                        <li class="tool-item tool-active is-share"><a href="javascript:;"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-fenxiang"></use>
                        </svg>分享</a></li>
                        <!--打赏开始-->
                                                <!--打赏结束-->
                                                <li class="tool-item tool-more">
                            <a>
                            <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
                            </a>
                            <ul class="more-box">
                                <li class="item"><a class="article-report">文章举报</a></li>
                            </ul>
                        </li>
                                            </ul>
                </div>
                            </div>
            <div class="person-messagebox">
                <div class="left-message"><a href="https://blog.csdn.net/u011121287">
                    <img src="https://profile.csdnimg.cn/4/5/D/3_u011121287" class="avatar_pic" username="u011121287">
                                            <img src="https://g.csdnimg.cn/static/user-reg-year/2x/7.png" class="user-years">
                                    </a></div>
                <div class="middle-message">
                                        <div class="title"><span class="tit"><a href="https://blog.csdn.net/u011121287" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}" target="_blank">gold_zwj</a></span>
                                            </div>
                    <div class="text"><span>发布了82 篇原创文章</span> · <span>获赞 14</span> · <span>访问量 7万+</span></div>
                </div>
                                <div class="right-message">
                                            <a href="https://im.csdn.net/im/main.html?userName=u011121287" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
                        </a>
                                                            <a class="btn btn-sm  bt-button personal-watch" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}">关注</a>
                                    </div>
                            </div>
                    </div>
    </article>
    
<script>
$("#blog_detail_zk_collection").click(function(){
    window.csdn.articleCollection()
})
        <div class="recommend-box"><div class="recommend-item-box type_blog clearfix" data-report-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/qq_18297675/article/details/87957540&quot;,&quot;strategy&quot;:&quot;BlogCommendFromMachineLearnPai2&quot;,&quot;index&quot;:&quot;0&quot;}">
<div class="content" style="width: 712px;">
	<a href="https://blog.csdn.net/qq_18297675/article/details/87957540" target="_blank" rel="noopener" title="springboot之BeanPostProcessor功能及例子(一)">
	<h4 class="text-truncate oneline" style="width: 552px;">
			springboot之<em>BeanPostProcessor</em>功能及例子(一)		</h4>
	<div class="info-box d-flex align-content-center">
		<p class="date-and-readNum oneline">
			<span class="date hover-show">02-26</span>
			<span class="read-num hover-hide">
				阅读数 
				2831</span>
			</p>
		</div>
	</a>
	<p class="content" style="width: 712px;">
		<a href="https://blog.csdn.net/qq_18297675/article/details/87957540" target="_blank" rel="noopener" title="springboot之BeanPostProcessor功能及例子(一)">
			<span class="desc oneline">一、BeanPostProcessor字面上的意思是bean的后置处理器,什么意思呢?其实就是说,在bean的生命周期中,可以对它干什么。再简单点就是,bean初始化之前干点什么,之后又干点什么。pu...</span>
		</a>
		<span class="blog_title_box oneline ">
								<span class="type-show type-show-blog type-show-after">博文</span>
										<a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_18297675">来自:	<span class="blog_title"> _ACME_的博客</span></a>
											</span>
	</p>
</div>
</div>
还能输入1000个字符
<div class="comment-list-container">
	<a id="comments"></a>
	<div class="comment-list-box">
	</div>
	<div id="commentPage" class="pagination-box d-none"></div>
	<div class="opt-box text-center">
		<div class="btn btn-sm btn-link-blue" id="btnMoreComment"></div>
	</div>
</div>
<div class="recommend-item-box recommend-recommend-box"><div id="kp_box_59" data-pid="59"><script type="text/javascript">
(function() {
    var s = "_" + Math.random().toString(36).slice(2);
    document.write('<div style="" id="' + s + '"></div>');
    (window.slotbydup = window.slotbydup || []).push({
        id: "u3491668",
        container:  s
    });
})();

14位享誉全球的程序员

09-04 阅读数 3万+

本文转载至:http://www.cricode.com/2922.html 博文 来自: 闲云孤鹤

Spring实战系列(三)-BeanPostProcessor妙用 - jokeHe..._CSDN博客

12-1

Spring中BeanPostProcessor - 每天进步一点点 - CSDN博客

12-6

<div class="recommend-item-box recommend-recommend-box"><div id="kp_box_60" data-pid="60"><script type="text/javascript">
    (function() {
        var s = "_" + Math.random().toString(36).slice(2);
        document.write('<div style="" id="' + s + '"></div>');
        (window.slotbydup = window.slotbydup || []).push({
            id: "u3502456",
            container: s
        });
    })();

BeanPostProcessor妙用(转载)_每天进步一点点的专栏-CSDN博客

1-6

springboot之BeanPostProcessor功能及例子(一) - _ACME..._CSDN博客

12-2

		<div class="recommend-item-box blog-expert-recommend-box" style="display: block;">
		<div class="d-flex">
			<div class="blog-expert-recommend">
				<div class="blog-expert">
					<div class="blog-expert-flexbox"><div class="blog-expert-item"><div class="blog-expert-info-box"><div class="blog-expert-img-box" data-report-click="{&quot;mod&quot;:&quot;popu_709&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zwjyyy1203/article/details/89576084&quot;}"><a href="https://blog.csdn.net/qq_18297675" target="_blank"><img src="https://profile.csdnimg.cn/2/5/1/3_qq_18297675" username="qq_18297675" alt="_acme_" title="_acme_"><svg class="icon" aria-hidden="true"><use xlink:href="#csdnc-blogexpert"></use></svg></a><span data-report-click="{&quot;mod&quot;:&quot;popu_710&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zwjyyy1203/article/details/89576084&quot;}"><span class="blog-expert-button-follow btn-red-follow" data-name="qq_18297675" data-nick="_acme_">关注</span></span></div><div class="info"><span data-report-click="{&quot;mod&quot;:&quot;popu_709&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zwjyyy1203/article/details/89576084&quot;}"><a href="https://blog.csdn.net/qq_18297675" target="_blank"><h5 class="oneline" title="_acme_">_acme_</h5></a></span>  <p></p><p class="article-num" title="258篇文章"> 258篇文章</p><p class="article-num" title="排名:4000+"> 排名:4000+</p><p></p></div></div></div><div class="blog-expert-item"><div class="blog-expert-info-box"><div class="blog-expert-img-box" data-report-click="{&quot;mod&quot;:&quot;popu_709&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zwjyyy1203/article/details/89576084&quot;}"><a href="https://blog.csdn.net/jokeHello" target="_blank"><img src="https://profile.csdnimg.cn/9/D/3/3_jokehello" username="jokeHello" alt="轻鸿飘羽" title="轻鸿飘羽"></a><span data-report-click="{&quot;mod&quot;:&quot;popu_710&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zwjyyy1203/article/details/89576084&quot;}"><span class="blog-expert-button-follow btn-red-follow" data-name="jokeHello" data-nick="轻鸿飘羽">关注</span></span></div><div class="info"><span data-report-click="{&quot;mod&quot;:&quot;popu_709&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zwjyyy1203/article/details/89576084&quot;}"><a href="https://blog.csdn.net/jokeHello" target="_blank"><h5 class="oneline" title="轻鸿飘羽">轻鸿飘羽</h5></a></span>  <p></p><p class="article-num" title="314篇文章"> 314篇文章</p><p class="article-num" title="排名:千里之外"> 排名:千里之外</p><p></p></div></div></div><div class="blog-expert-item"><div class="blog-expert-info-box"><div class="blog-expert-img-box" data-report-click="{&quot;mod&quot;:&quot;popu_709&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zwjyyy1203/article/details/89576084&quot;}"><a href="https://blog.csdn.net/fzghjx" target="_blank"><img src="https://profile.csdnimg.cn/A/2/5/3_fzghjx" username="fzghjx" alt="fzghjx" title="fzghjx"></a><span data-report-click="{&quot;mod&quot;:&quot;popu_710&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zwjyyy1203/article/details/89576084&quot;}"><span class="blog-expert-button-follow btn-red-follow" data-name="fzghjx" data-nick="fzghjx">关注</span></span></div><div class="info"><span data-report-click="{&quot;mod&quot;:&quot;popu_709&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zwjyyy1203/article/details/89576084&quot;}"><a href="https://blog.csdn.net/fzghjx" target="_blank"><h5 class="oneline" title="fzghjx">fzghjx</h5></a></span>  <p></p><p class="article-num" title="19篇文章"> 19篇文章</p><p class="article-num" title="排名:千里之外"> 排名:千里之外</p><p></p></div></div></div><div class="blog-expert-item"><div class="blog-expert-info-box"><div class="blog-expert-img-box" data-report-click="{&quot;mod&quot;:&quot;popu_709&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zwjyyy1203/article/details/89576084&quot;}"><a href="https://blog.csdn.net/m0_37962779" target="_blank"><img src="https://profile.csdnimg.cn/A/F/C/3_m0_37962779" username="m0_37962779" alt="不动明王1984" title="不动明王1984"></a><span data-report-click="{&quot;mod&quot;:&quot;popu_710&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zwjyyy1203/article/details/89576084&quot;}"><span class="blog-expert-button-follow btn-red-follow" data-name="m0_37962779" data-nick="不动明王1984">关注</span></span></div><div class="info"><span data-report-click="{&quot;mod&quot;:&quot;popu_709&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zwjyyy1203/article/details/89576084&quot;}"><a href="https://blog.csdn.net/m0_37962779" target="_blank"><h5 class="oneline" title="不动明王1984">不动明王1984</h5></a></span>  <p></p><p class="article-num" title="30篇文章"> 30篇文章</p><p class="article-num" title="排名:千里之外"> 排名:千里之外</p><p></p></div></div></div></div>
				</div>
			</div>
		</div>
	</div><div class="recommend-item-box baiduSearch" data-report-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/omgkill/article/details/81666754&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:&quot;5&quot;}" data-track-view="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/omgkill/article/details/81666754&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:4,&quot;extend1&quot;:&quot;_&quot;}" data-track-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/omgkill/article/details/81666754&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:4,&quot;extend1&quot;:&quot;_&quot;}" data-flg="true">                <a href="https://blog.csdn.net/omgkill/article/details/81666754" target="_blank">              		<h4 class="text-truncate oneline" style="width: 626px;"><em>BeanPostProcessor</em>示例和理解 - 行简 - CSDN博客</h4>                  <div class="info-box d-flex align-content-center">                    <p>                      <span class="date">11-22</span>                    </p>                  </div>                </a>            	</div><div class="recommend-item-box baiduSearch" data-report-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/Qgwperfect/article/details/83508772&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:&quot;6&quot;}" data-track-view="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/Qgwperfect/article/details/83508772&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:5,&quot;extend1&quot;:&quot;_&quot;}" data-track-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/Qgwperfect/article/details/83508772&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:5,&quot;extend1&quot;:&quot;_&quot;}" data-flg="true">                <a href="https://blog.csdn.net/Qgwperfect/article/details/83508772" target="_blank">              		<h4 class="text-truncate oneline" style="width: 633px;"><em>BeanPostProcessor</em>的使用 - 早起的鸟儿有虫吃的博客 - CSDN博客</h4>                  <div class="info-box d-flex align-content-center">                    <p>                      <span class="date">12-2</span>                    </p>                  </div>                </a>            	</div>
BeanPostProcessor使用心得 - weixin_34224941的博客 - CSDN博客

6-29

深入理解spring生命周期与BeanPostProcessor的实现原理..._CSDN博客

11-20

<div class="recommend-item-box recommend-recommend-box"><div id="kp_box_61" data-pid="61"><script type="text/javascript">
    (function() {
        var s = "_" + Math.random().toString(36).slice(2);
        document.write('<div style="" id="' + s + '"></div>');
        (window.slotbydup = window.slotbydup || []).push({
            id: "u3565309",
            container: s
        });
    })();

Spring的BeanPostProcessor - 路人而已的专栏 - CSDN博客

5-19

<div class="recommend-item-box recommend-recommend-box"><div id="kp_box_62" data-pid="62"><script type="text/javascript">
    (function() {
        var s = "_" + Math.random().toString(36).slice(2);
        document.write('<div style="" id="' + s + '"></div>');
        (window.slotbydup = window.slotbydup || []).push({
            id: "u3565311",
            container: s
        });
    })();

<div class="recommend-item-box recommend-recommend-box"><div id="kp_box_63" data-pid="63"><script async="async" charset="utf-8" src="https://shared.ydstatic.com/js/yatdk/3.0.1/stream.js" data-id="8935aa488dd58452b9e5ee3b44f1212f" data-div-style="width:100%;" data-tit-style="margin-bottom: 6px; font-size: 18px; line-height: 24px; color: #3d3d3d;display: inline-block;font-weight:bold;" data-des-style="font-size: 13px; line-height: 22px; white-space: normal; color: #999;" data-img-style="float:left;margin-right:15px;width:90px;height:60px;" data-is-handling="1">

nginx学习,看这一篇就够了:下载、安装。使用:正向代理、反向代理、负载均衡。常用命令和配置文件

10-25 阅读数 4万+

文章目录前言一、nginx简介1. 什么是 nginx 和可以做什么事情2.Nginx 作为 web 服务器3. 正向代理4. 反向代理5. 动静分离6.动静分离二、Nginx 的安装三、 Ngin... 博文 来自: 冯安晨

<div class="recommend-item-box recommend-recommend-box"><div id="kp_box_64" data-pid="64"><script async="async" charset="utf-8" src="https://shared.ydstatic.com/js/yatdk/3.0.1/stream.js" data-id="8935aa488dd58452b9e5ee3b44f1212f" data-div-style="width:100%;" data-tit-style="margin-bottom: 6px; font-size: 18px; line-height: 24px; color: #3d3d3d;display: inline-block;font-weight:bold;" data-des-style="font-size: 13px; line-height: 22px; white-space: normal; color: #999;" data-img-style="float:left;margin-right:15px;width:90px;height:60px;" data-is-handling="1">

<div class="recommend-item-box recommend-recommend-box"><div id="kp_box_65" data-pid="65"><script async="async" charset="utf-8" src="https://shared.ydstatic.com/js/yatdk/3.0.1/stream.js" data-id="8935aa488dd58452b9e5ee3b44f1212f" data-div-style="width:100%;" data-tit-style="margin-bottom: 6px; font-size: 18px; line-height: 24px; color: #3d3d3d;display: inline-block;font-weight:bold;" data-des-style="font-size: 13px; line-height: 22px; white-space: normal; color: #999;" data-img-style="float:left;margin-right:15px;width:90px;height:60px;" data-is-handling="1">

<div class="recommend-item-box recommend-recommend-box"><div id="kp_box_66" data-pid="66"><script type="text/javascript">
    (function() {
        var s = "_" + Math.random().toString(36).slice(2);
        document.write('<div style="" id="' + s + '"></div>');
        (window.slotbydup = window.slotbydup || []).push({
            id: "u4623747",
            container: s
        });
    })();

130 个相见恨晚的超实用网站,一次性分享出来

01-06 阅读数 11万+

文末没有公众号,只求 点赞 + 关注

搞学习

知乎:www.zhihu.com
大学资源网:http://www.dxzy163.com/
简答题:http://www.jiandati.com…


博文



这篇文章很长,但绝对是精华,相信我,读完以后,你会知道学历不好的解决方案…


博文



<div class="recommend-item-box recommend-recommend-box"><div><iframe width="962" frameborder="0" height="52" scrolling="no" src="//pos.baidu.com/s?hei=52&amp;wid=962&amp;di=u3491668&amp;ltu=https%3A%2F%2Fblog.csdn.net%2Fzwjyyy1203%2Farticle%2Fdetails%2F89576084&amp;psi=2e6a1c7223c2ef589ede851279a4bbb2&amp;dis=0&amp;dc=3&amp;cpl=3&amp;cfv=0&amp;ant=0&amp;pcs=1215x564&amp;ti=BeanPostProcessor%E5%A6%99%E7%94%A8%EF%BC%88%E8%BD%AC%E8%BD%BD%EF%BC%89&amp;dtm=HTML_POST&amp;tcn=1580884794&amp;pss=1230x9007&amp;cec=UTF-8&amp;psr=1536x864&amp;dai=6&amp;cdo=-1&amp;ccd=24&amp;tpr=1580884793781&amp;col=zh-CN&amp;drs=3&amp;par=1536x824&amp;ari=2&amp;cce=true&amp;prot=2&amp;cja=false&amp;ps=6023x383&amp;dri=1&amp;cmi=4&amp;pis=-1x-1&amp;exps=111000,110011&amp;tlm=1580884793&amp;chi=2"></iframe></div><script type="text/javascript" src="//rabc1.iteye.com/production/res/rxjg.js?pkcgstj=jm"></script></div>
《奇巧淫技》系列-python!!每天早上八点自动发送天气预报邮件到QQ邮箱

01-19 阅读数 4万+

此博客仅为我业余记录文章所用,发布到此,仅供网友阅读参考,如有侵权,请通知我,我会删掉。

补充
有不少读者留言说本文章没有用,因为天气预报直接打开手机就可以收到了,为何要多此一举发送到邮箱呢!!!…


博文



区块链技术被认为…


博文



<div class="recommend-item-box recommend-recommend-box"><div><iframe width="962" frameborder="0" height="52" scrolling="no" src="https://pos.baidu.com/s?hei=52&amp;wid=962&amp;di=u3491668&amp;ltu=https%3A%2F%2Fblog.csdn.net%2Fzwjyyy1203%2Farticle%2Fdetails%2F89576084&amp;psi=2e6a1c7223c2ef589ede851279a4bbb2&amp;tpr=1580884793781&amp;tlm=1580884793&amp;dtm=HTML_POST&amp;prot=2&amp;cce=true&amp;tcn=1580884794&amp;pcs=1215x564&amp;cpl=3&amp;cdo=-1&amp;ccd=24&amp;exps=111000,110011&amp;chi=2&amp;dri=2&amp;par=1536x824&amp;psr=1536x864&amp;dis=0&amp;cja=false&amp;dai=7&amp;dc=3&amp;col=zh-CN&amp;cmi=4&amp;ps=6487x383&amp;pss=1230x9065&amp;cec=UTF-8&amp;drs=3&amp;ant=0&amp;cfv=0&amp;ti=BeanPostProcessor%E5%A6%99%E7%94%A8%EF%BC%88%E8%BD%AC%E8%BD%BD%EF%BC%89&amp;ari=2&amp;pis=-1x-1"></iframe></div><script type="text/javascript" src="//rabc1.iteye.com/production/res/rxjg.js?pkcgstj=jm"></script></div>
8年经验面试官详解 Java 面试秘诀

11-19 阅读数 11万+

 

 

作者 | 胡书敏

责编 | 刘静

出品 | CSDN(ID:CSDNnews)

本人目前在一家知名外企担任架构师,而且最近八年来,在多家外企和互联网公司担任Java技术面试官…


博文



致 Python 初学者们!

11-21 阅读数 1万+

作者 | 许向武

责编 | 屠敏

出品 | CSDN 博客

前言

在 Python 进阶的过程中,相信很多同学应该大致上学习了很多 Python 的基础知识,也正在努力成长。在此…


博文



一、什么是中台?

这其实是一个老生常谈的概念了,中台,顾名思义,就是在起中间作…


博文



上面是一个读者“烦不烦”问我的一个问题。其实不止是“烦不烦”,还有很多读者问过我类似这样的问题。
我接的私活不算多,挣到…


博文



(一)初进校园

刚进入大学的时候自己完全…


博文



工具和中间件——redis,从底层原理到开发实践

02-02 阅读数 1681

目录

一、前言

二、redis基础知识

2.1 从“处理器-缓存-内存”到“后台-redis-数据库”

2.2 不使用缓存与使用缓存(读操作+写操作)

2.3 redis典型问题:缓存穿透…


博文



大学两年,写了这篇几十万字的干货总结

12-08 阅读数 9万+

本文十天后设置为粉丝可见,喜欢的提前关注

不要白嫖请点赞

不要白嫖请点赞

不要白嫖请点赞

文中提到的书我都有电子版,可以评论邮箱发给你。

文中提到的书我都有电子版,可以评论邮箱发给你。

文…


博文



《C++ Primer》学习笔记(八):标准 IO 库

02-03 阅读数 1214

第8章 IO库 部分IO库设施:

istream:输入流类型,提供输入操作。
ostream:输出流类型,提供输出操作。
cin:istream对象,从标准输入读取数据。
cout:ostream对…


博文



拿下微软、Google、Adobe,印度为何盛产科技圈 CEO?

01-09 阅读数 1万+

作者 | 胡巍巍

出品 | CSDN(ID:CSDNnews)

世界500强中,30%的掌舵人,都是印度人。

是的,你没看错。这是近日《哈佛商业评论》的研究结果。

其中又以微软CEO萨提亚·纳…


博文



[数据结构与算法] 邂逅栈

02-03 阅读数 1108

在邂逅了完线性结构的数组和队列后, 我们便偶遇了栈这个东东, 他到底是个啥?
就让我们慢慢揭开它的神秘面纱吧~~~

需求介绍

栈的介绍
栈的英文为(stack)

栈是一个先入后出(FILO…


博文



基本情况:

专业技能:
1、 熟悉Sping了解SpringMVC、S…


博文



GitHub 上有哪些适合新手跟进的优质项目?

01-17 阅读数 1万+

专栏 | 九章算法 网址 | www.jiuzhang.com/?utm_source=sc-csdn-fks

HelloGitHub
star:19k
Python,Java,PHP,C++,go…


博文



提高开发效率一些工具,你知道都有那些吗?

01-21 阅读数 5662

目录

前言:

  1. 禅道

  2. Jenkins

  3. sonarqube

4.showdoc

5.swgger

6.分布式配置中心apollo

  1. appscan

8.项目开发…


博文



有些…


博文



全国新型肺炎疫情最新数据接口api 含每日历史数据及各省市具体人数数据

01-30 阅读数 1万+

返回json示例 { "errcode":0,//0标识接口正常 "data":{ "date":"2020-01-30 07:47:23",//实时更新时间 ... 博文

利用Python爬取新冠肺炎疫情实时数据,Pyecharts画2019-nCoV疫情地图

01-30 阅读数 6029

地图绘制 数据源 腾讯疫情实时追踪 网站结构比较简单,可以直接获取json格式的数据

抓取每个城市的当前感染数据

导入相关模块

import time
import json
import re…


博文



                <div class="recommend-item-box type_hot_word">
                <div class="content clearfix" style="width: 712px;">
                    <div class="float-left">
                                                                            <span>
                            <a href="https://blog.csdn.net/yilovexing/article/details/80577510" target="_blank">
                            python</a>
                        </span>
                                                    <span>
                            <a href="https://blog.csdn.net/slwbcsdn/article/details/53458352" target="_blank">
                            json</a>
                        </span>
                                                    <span>
                            <a href="https://blog.csdn.net/csdnnews/article/details/83753246" target="_blank">
                            java</a>
                        </span>
                                                    <span>
                            <a href="https://blog.csdn.net/qq_35077512/article/details/88952519" target="_blank">
                            mysql</a>
                        </span>
                                                    <span>
                            <a href="https://blog.csdn.net/pdcfighting/article/details/80297499" target="_blank">
                            pycharm</a>
                        </span>
                                                    <span>
                            <a href="https://blog.csdn.net/sinyu890807/article/details/97142065" target="_blank">
                            android</a>
                        </span>
                                                    <span>
                            <a href="https://blog.csdn.net/gexiaoyizhimei/article/details/100122368" target="_blank">
                            linux</a>
                        </span>
                                                    <span>
                            <a href="https://download.csdn.net/download/xhg_gszs/10978826" target="_blank">
                            json格式</a>
                        </span>
                                                
                                                                            <span>
                            <a href="https://www.csdn.net/gather_16/NtzaUgzsLWRvd25sb2Fk.html" target="_blank">
                            c# ef通用数据层封装</a>
                        </span>
                                                    <span>
                            <a href="https://www.csdn.net/gather_18/NtzaUg0sLWRvd25sb2Fk.html" target="_blank">
                            c# queu task</a>
                        </span>
                                                    <span>
                            <a href="https://www.csdn.net/gather_1c/NtzaUg1sLWRvd25sb2Fk.html" target="_blank">
                            c# timeout单位</a>
                        </span>
                                                    <span>
                            <a href="https://www.csdn.net/gather_12/NtzaUg2sLWRvd25sb2Fk.html" target="_blank">
                            c#中indexof(c</a>
                        </span>
                                                    <span>
                            <a href="https://www.csdn.net/gather_14/NtzaUg3sLWRvd25sb2Fk.html" target="_blank">
                            c#常量定义规则</a>
                        </span>
                                                    <span>
                            <a href="https://www.csdn.net/gather_1b/NtzaUg4sLWRvd25sb2Fk.html" target="_blank">
                            c#发送按键</a>
                        </span>
                                                    <span>
                            <a href="https://www.csdn.net/gather_2f/NtzaUg5sLWJsb2cO0O0O.html" target="_blank">
                            c#记住帐号密码</a>
                        </span>
                                                    <span>
                            <a href="https://www.csdn.net/gather_12/NtzaYgwsLWRvd25sb2Fk.html" target="_blank">
                            c#mvc框架搭建</a>
                        </span>
                                                    <span>
                            <a href="https://www.csdn.net/gather_10/NtzaYgysLWRvd25sb2Fk.html" target="_blank">
                            c#改变td值</a>
                        </span>
                                                    <span>
                            <a href="https://www.csdn.net/gather_1e/NtzaYgzsLWRvd25sb2Fk.html" target="_blank">
                            c#怎么读取html文件</a>
                        </span>
                                                                        </div>
                </div>
                </div>
                                <div class="recommend-loading-box">
                <img src="https://csdnimg.cn/release/phoenix/images/feedLoading.gif">
            </div>
            <div class="recommend-end-box" style="display: block;">
                <p class="text-center">没有更多推荐了,<a href="https://blog.csdn.net/" class="c-blue c-blue-hover c-blue-focus">返回首页</a></p>
            </div>
        </div>
                        <div class="template-box">
                <span>©️2019 CSDN</span><span class="point"></span>
            <span>皮肤主题: 大白</span>
            <span> 设计师:
                                        CSDN官方博客                                    </span>
            </div>
                </main>@[TOC](这里写自定义目录标题)

欢迎使用Markdown编辑器

你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。

新的改变

我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown编辑器功能,我们增加了如下几点新功能,帮助你用它写博客:

  1. 全新的界面设计 ,将会带来全新的写作体验;
  2. 在创作中心设置你喜爱的代码高亮样式,Markdown 将代码片显示选择的高亮样式 进行展示;
  3. 增加了 图片拖拽 功能,你可以将本地的图片直接拖拽到编辑区域直接展示;
  4. 全新的 KaTeX数学公式 语法;
  5. 增加了支持甘特图的mermaid语法1 功能;
  6. 增加了 多屏幕编辑 Markdown文章功能;
  7. 增加了 焦点写作模式、预览模式、简洁写作模式、左右区域同步滚轮设置 等功能,功能按钮位于编辑区域与预览区域中间;
  8. 增加了 检查列表 功能。

功能快捷键

撤销:Ctrl/Command + Z
重做:Ctrl/Command + Y
加粗:Ctrl/Command + B
斜体:Ctrl/Command + I
标题:Ctrl/Command + Shift + H
无序列表:Ctrl/Command + Shift + U
有序列表:Ctrl/Command + Shift + O
检查列表:Ctrl/Command + Shift + C
插入代码:Ctrl/Command + Shift + K
插入链接:Ctrl/Command + Shift + L
插入图片:Ctrl/Command + Shift + G
查找:Ctrl/Command + F
替换:Ctrl/Command + G

合理的创建标题,有助于目录的生成

直接输入1次#,并按下space后,将生成1级标题。
输入2次#,并按下space后,将生成2级标题。
以此类推,我们支持6级标题。有助于使用TOC语法后生成一个完美的目录。

如何改变文本的样式

强调文本 强调文本

加粗文本 加粗文本

标记文本

删除文本

引用文本

H2O is是液体。

210 运算结果是 1024.

插入链接与图片

链接: link.

图片: Alt

带尺寸的图片: Alt

居中的图片: Alt

居中并且带尺寸的图片: Alt

当然,我们为了让用户更加便捷,我们增加了图片拖拽功能。

如何插入一段漂亮的代码片

博客设置页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 代码片.

// An highlighted block
var foo = 'bar';

生成一个适合你的列表

  • 项目
    • 项目
      • 项目
  1. 项目1
  2. 项目2
  3. 项目3
  • 计划任务
  • 完成任务

创建一个表格

一个简单的表格是这么创建的:

项目Value
电脑$1600
手机$12
导管$1

设定内容居中、居左、居右

使用:---------:居中
使用:----------居左
使用----------:居右

第一列第二列第三列
第一列文本居中第二列文本居右第三列文本居左

SmartyPants

SmartyPants将ASCII标点字符转换为“智能”印刷标点HTML实体。例如:

TYPEASCIIHTML
Single backticks'Isn't this fun?'‘Isn’t this fun?’
Quotes"Isn't this fun?"“Isn’t this fun?”
Dashes-- is en-dash, --- is em-dash– is en-dash, — is em-dash

创建一个自定义列表

Markdown
Text-to- HTML conversion tool
Authors
John
Luke

如何创建一个注脚

一个具有注脚的文本。2

注释也是必不可少的

Markdown将文本转换为 HTML

KaTeX数学公式

您可以使用渲染LaTeX数学表达式 KaTeX:

Gamma公式展示 Γ ( n ) = ( n − 1 ) ! ∀ n ∈ N \Gamma(n) = (n-1)!\quad\forall n\in\mathbb N Γ(n)=(n1)!nN 是通过欧拉积分

Γ ( z ) = ∫ 0 ∞ t z − 1 e − t d t   . \Gamma(z) = \int_0^\infty t^{z-1}e^{-t}dt\,. Γ(z)=0tz1etdt.

你可以找到更多关于的信息 LaTeX 数学表达式here.

新的甘特图功能,丰富你的文章

Mon 06 Mon 13 Mon 20 已完成 进行中 计划一 计划二 现有任务 Adding GANTT diagram functionality to mermaid
  • 关于 甘特图 语法,参考 这儿,

UML 图表

可以使用UML图表进行渲染。 Mermaid. 例如下面产生的一个序列图:

张三 李四 王五 你好!李四, 最近怎么样? 你最近怎么样,王五? 我很好,谢谢! 我很好,谢谢! 李四想了很长时间, 文字太长了 不适合放在一行. 打量着王五... 很好... 王五, 你怎么样? 张三 李四 王五

这将产生一个流程图。:

链接
长方形
圆角长方形
菱形
  • 关于 Mermaid 语法,参考 这儿,

FLowchart流程图

我们依旧会支持flowchart的流程图:

Created with Raphaël 2.2.0 开始 我的操作 确认? 结束 yes no
  • 关于 Flowchart流程图 语法,参考 这儿.

导出与导入

导出

如果你想尝试使用此编辑器, 你可以在此篇文章任意编辑。当你完成了一篇文章的写作, 在上方工具栏找到 文章导出 ,生成一个.md文件或者.html文件进行本地保存。

导入

如果你想加载一篇你写过的.md文件,在上方工具栏可以选择导入功能进行对应扩展名的文件导入,
继续你的创作。


  1. mermaid语法说明 ↩︎

  2. 注脚的解释 ↩︎

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值