`
zengshaotao
  • 浏览: 778057 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

spring启动过程解密

 
阅读更多

原文地址:http://blog.163.com/axuandebin@126/blog/static/118777042009410248557/

 

Spring容器像一台构造精妙的机器,我们通过配置文件向机器传达控制信息,机器就能够按照设定的模式进行工作。如果我们将Spring容器比喻为一辆汽车,可以将BeanFactory看成汽车的发动机,而ApplicationContext则是 整辆汽车,它不但包括发动机,还包括离合器、变速器以及底盘、车身、电气设备等其他组件。在ApplicationContext内,各个组件按部就班、有条不紊地完成汽车的各项功能。

ApplicationContext内部封装了一个BeanFactory对象,来实现对容器的操作,初始化完成之后,BeanFactory封装了bean的信息,而ApplicationContext通过访问这个对象获取bean的对象信息(BeanDefinition/Bean对象,都是由BeanFactory实际创建并管理的),为了实现接口的统一,ApplicationContext也实现了一系列的BeanFactory接口(可以说ApplicationContext对BeanFactory对象实现一种代理)。ApplicationContext建立在BeanFactory的基础之上,对配置对象的管理最终还是交于一个DefaultListableBeanFactory来完成(装配地址/访问等),而ApplicationContext在应用这个DefaultListableBeanFactory对象的基础上,不仅实现了BeanFactory接口提供的功能方法,并且黏合了一些面向应用的功能,如资源/国际化支持/框架事件支持等,并且将一些原先需要手动设置到BeanFactory的属性通过配置文件中配置的形式代替(如工厂后处理器BeanPostProcessor/InstantiationAwareBeanPostProcessor)

同样,因为对于BeanDefinition和bean对象的管理是由上下文持有的beanfactory对象完成的,用户不需要拥有这样的接口,因此,ApplicationContext的接口体系中并没有BeanDefinitionRegistry,SingletonBeanRegistry以及AutowireCapableBeanFactory接口(ApplicationContext可以访问一些接口方法在上述接口中也定义,但这些方法提供者为BeanFactory体系中的其他接口,BeanFactory接口体系中的接口之间有重复定义方法的)。

 

内部工作机制(Spring容器ApplicationContext的初始化                                                                                    

(一) 首先来看创建ApplicationContext ,以ClassPathXmlApplicationContext为例:

ApplicationContext = new ClassPathXmlApplicationContext(xmlPath);  

源码如下:

public class ClassPathXmlApplicationContext extends AbstractXmlApplicationContext {

public ClassPathXmlApplicationContext(String configLocation) throws BeansException {
                  this(new String[] {configLocation});
       }

public ClassPathXmlApplicationContext(String[] configLocations) throws BeansException {
                  this(configLocations, (ApplicationContext) null);
       }

//。。。。。。省略几个重载的构造函数

public ClassPathXmlApplicationContext(String[] configLocations, ApplicationContext parent)
                                                                                                                         throws BeansException {

          super(parent);
                 this.configLocations = configLocations;

          //IoC容器的初始化过程,其初始化过程的大致步骤由AbstractApplicationContext来定义   
                 refresh();
       }

关键之处在于refresh方法,此方法继承于ClassPathXmlApplicationContext的间接父类:

public abstract class AbstractApplicationContext extends DefaultResourceLoader
                                                        implements ConfigurableApplicationContext, DisposableBean
 {

Spring的AbstractApplicationContext是ApplicationContext抽象实现类,该抽象类的refresh()方法定义了Spring容器在加载配置文件后的各项处理过程,这些处理过程清晰刻画了Spring容器启动时所执行的各项操作(创建Spring容器如ClassPathXmlApplicationContext)。下面,我们来看一下refresh()内部定义了哪些执行逻辑:

public void refresh() throws BeansException, IllegalStateException {
              synchronized (this.startupShutdownMonitor) {
                    // Prepare this context for refreshing.
                    prepareRefresh();

             // Tell the subclass to refresh the internal bean factory       

            ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();--------(1)

             // Prepare the bean factory for use in this context.
                    prepareBeanFactory(beanFactory);

             try {
                          // Allows post-processing of the bean factory in context subclasses.
                          postProcessBeanFactory(beanFactory);

                   // Invoke factory processors registered as beans in the context.
                          invokeBeanFactoryPostProcessors(beanFactory);-------------------------------------(2)

                   // Register bean processors that intercept bean creation
                          registerBeanPostProcessors(beanFactory);---------------------------------------------(3)

                   // Initialize message source for this context.
                          initMessageSource();-------------------------------------------------------------------------(4)

                   // Initialize event multicaster for this context.
                          initApplicationEventMulticaster();-----------------------------------------------------------(5)

                   // Initialize other special beans in specific context subclasses.
                          onRefresh();------------------------------------------------------------------------------------(6)

                   // Check for listener beans and register them.
                          registerListeners();----------------------------------------------------------------------------(7)

                   // Instantiate singletons this late to allow them to access the message source.
                          beanFactory.preInstantiateSingletons();--------------------------------------------------(8)

                   // Last step: publish corresponding event.
                          publishEvent(new ContextRefreshedEvent(this));---------------------------------------(9)
                    } catch (BeansException ex) {
                          // Destroy already created singletons to avoid dangling resources.
                          beanFactory.destroySingletons();
                          throw ex;
                   }
             }
       }

protected ConfigurableListableBeanFactory obtainFreshBeanFactory() {
             refreshBeanFactory();
             ConfigurableListableBeanFactory beanFactory = getBeanFactory();

      return beanFactory;
       } 

protected abstract void refreshBeanFactory() throws BeansException, IllegalStateException;

public abstract ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException;

 

1.初始化BeanFactory:根据配置文件实例化BeanFactory,getBeanFactory()方法由具体子类实现。在这一步里,Spring将配置文件的信息解析成为一个个的BeanDefinition对象并装入到容器的Bean定义注册表(BeanDefinitionRegistry)中,但此时Bean还未初始化;obtainFreshBeanFactory()会调用自身的refreshBeanFactory(),而refreshBeanFactory()方法由子类AbstractRefreshableApplicationContext实现,该方法返回了一个创建的DefaultListableBeanFactory对象,这个对象就是由ApplicationContext管理的BeanFactory容器对象

这一步的操作相当于,如果我们在自己的应用代码中不用ApplicationContext而直接用BeanFactory时创建BeanFactory对象的操作

核心代码如下:

public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext { }

 /** 该ApplicationContext管理的BeanFactory容器对象*/
       private DefaultListableBeanFactory beanFactory;

protected final void refreshBeanFactory() throws BeansException {
              // Shut down previous bean factory, if any.
              ConfigurableListableBeanFactory oldBeanFactory = null;
              synchronized (this.beanFactoryMonitor) {
                      oldBeanFactory = this.beanFactory;
              }
              if (oldBeanFactory != null) {
                      oldBeanFactory.destroySingletons();
                      synchronized (this.beanFactoryMonitor) {
                             this.beanFactory = null;
                      }
              }

       // Initialize fresh bean factory.
              try {

               // 创建容器对象
                      DefaultListableBeanFactory beanFactory = createBeanFactory();

               // Customize the internal bean factory used by this context
                      customizeBeanFactory(beanFactory);

               // 装载配置文件,并传入相关联的BeanFactory对象,作为BeanDefinition的容器
                      loadBeanDefinitions(beanFactory);
                      synchronized (this.beanFactoryMonitor) {
                            this.beanFactory = beanFactory;
                      }
              }  catch (IOException ex) {
                      throw new ApplicationContextException(
                                  "I/O error parsing XML document for application context [" + getDisplayName() + "]", ex);
              }
       }

// 创建Spring默认的容器对象

protected DefaultListableBeanFactory createBeanFactory() {
              return new DefaultListableBeanFactory(getInternalParentBeanFactory());
       }

// 该方法为一个钩子方法,子类可以覆盖它对当前上下文管理的BeanFactory提供客户化操作,也可以忽略

protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) {
       }

// 装载配置文件的方法,需要子类实现

protected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory)
                                                                                                     throws IOException, BeansException;

 

对于上面装载配置文件的方法,由其子类扩展实现:

public abstract class AbstractXmlApplicationContext extends AbstractRefreshableApplicationContext  {}

protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws IOException {
             // 使用XMLBeanDefinitionReader来载入bean定义信息的XML文件,传入关联的BeanFactory

      XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);

      // 这里配置reader的环境,其中ResourceLoader是我们用来定位bean定义信息资源位置的
             // 因为上下文本身实现了ResourceLoader接口,所以可以直接把上下文作为ResourceLoader传递入

      beanDefinitionReader.setResourceLoader(this);
             beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));

      // Allow a subclass to provide custom initialization of the reader,
             // then proceed with actually loading the bean definitions.
             initBeanDefinitionReader(beanDefinitionReader);

      // 这里转到定义好的XmlBeanDefinitionReader中对载入bean信息进行处理 
             loadBeanDefinitions(beanDefinitionReader);
       } 

protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) throws BeansException, IOException {
             Resource[] configResources = getConfigResources();
             if (configResources != null) {
                     reader.loadBeanDefinitions(configResources);
             }
             String[] configLocations = getConfigLocations();
             if (configLocations != null) {
                     reader.loadBeanDefinitions(configLocations);
             }
       }

reader.loadBeanDefinitions(configLocations);涉及到XmlBeanDefinitionReader 工具类的使用(以后整理

2.调用工厂后处理器:根据反射机制从BeanDefinitionRegistry中找出所有BeanFactoryPostProcessor类型的Bean,并调用其postProcessBeanFactory()接口方法;

经过第一步加载配置文件,已经把配置文件中定义的所有bean装载到BeanDefinitionRegistry这个Beanfactory中,对于ApplicationContext应用来说这个BeanDefinitionRegistry类型的BeanFactory就是Spring默认的DefaultListableBeanFactory

public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory
                                                           implements ConfigurableListableBeanFactory, BeanDefinitionRegistry

在这些被装载的bean中,若有类型为BeanFactoryPostProcessor的bean(配置文件中配置的),则将对应的BeanDefinition生成BeanFactoryPostProcessor对象

容器扫描BeanDefinitionRegistry中的BeanDefinition,使用java反射自动识别出Bean工厂后处理器(实现BeanFactoryPostProcessor接口)的bean,然后调用这些bean工厂后处理器对BeanDefinitionRegistry中的BeanDefinition进行加工处理,可以完成以下两项工作(当然也可以有其他的操作,用户自己定义):

1 对使用到占位符的<bean>元素标签进行解析,得到最终的配置值,这意味着对一些半成品式的BeanDefinition对象进行加工处理并取得成品的BeanDefinition对象。2 对BeanDefinitionRegistry中的BeanDefinition进行扫描,通过Java反射机制找出所有属性编辑器的Bean(实现java.beans.PropertyEditor接口的Bean),并自动将它们注册到Spring容器的属性编辑器注册表中(PropertyEditorRegistry),这个Spring提供了实现:CustomEditorConfigurer,它实现了BeanFactoryPostProcessor,用它来在此注册自定义属性编辑器;

AbstractApplicationContext中的代码如下:

protected void invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory beanFactory) {
             // Invoke factory processors registered with the context instance.
             for (Iterator it = getBeanFactoryPostProcessors().iterator(); it.hasNext();) {
                   BeanFactoryPostProcessor factoryProcessor = (BeanFactoryPostProcessor) it.next();
                   factoryProcessor.postProcessBeanFactory(beanFactory);
             }

      // Do not initialize FactoryBeans here: We need to leave all regular beans
             // 通过ApplicatinContext管理的beanfactory获取已经注册的BeanFactoryPostProcessor类型的bean的名字

             String[] factoryProcessorNames =
                              beanFactory.getBeanNamesForType(BeanFactoryPostProcessor.class, true, false);

      // Separate between BeanFactoryPostProcessors that implement the Ordered
             // interface and those that do not.
             List orderedFactoryProcessors = new ArrayList();
             List nonOrderedFactoryProcessorNames = new ArrayList();
             for (int i = 0; i < factoryProcessorNames.length; i++) {
                   if (isTypeMatch(factoryProcessorNames[i], Ordered.class)) {

                   // 调用beanfactory的getBean取得所有的BeanFactoryPostProcessor对象
                         orderedFactoryProcessors.add(beanFactory.getBean(factoryProcessorNames[i]));
                   }
                   else {
                         nonOrderedFactoryProcessorNames.add(factoryProcessorNames[i]);
                   }
             }

      // First, invoke the BeanFactoryPostProcessors that implement Ordered.
             Collections.sort(orderedFactoryProcessors, new OrderComparator());
             for (Iterator it = orderedFactoryProcessors.iterator(); it.hasNext();) {
                  BeanFactoryPostProcessor factoryProcessor = (BeanFactoryPostProcessor) it.next();

           // 执行BeanFactoryPostProcessor的方法,传入当前持有的beanfactory对象,以获取要操作的 

           // BeanDefinition
                  factoryProcessor.postProcessBeanFactory(beanFactory);
             }
             // Second, invoke all other BeanFactoryPostProcessors, one by one.
             for (Iterator it = nonOrderedFactoryProcessorNames.iterator(); it.hasNext();) {
                  String factoryProcessorName = (String) it.next();
                  ((BeanFactoryPostProcessor) getBean(factoryProcessorName)).

                                                                      postProcessBeanFactory(beanFactory);
             }
       }

 

BeanFactoryPostProcessor接口代码如下,实际的操作由用户扩展并配置(扩展点,如何扩展?

package org.springframework.beans.factory.config;

public interface BeanFactoryPostProcessor {

     /**
             * Modify the application context's internal bean factory after its standard
            */
             void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException;

}

 

3.注册Bean后处理器:根据反射机制从BeanDefinitionRegistry中找出所有BeanPostProcessor类型的Bean,并将它们注册到容器Bean后处理器的注册表中;

AbstractApplicatinContext中对应代码如下:

protected void registerBeanPostProcessors(ConfigurableListableBeanFactory beanFactory) {
              String[] processorNames = beanFactory.getBeanNamesForType(BeanPostProcessor.class, true, false);

         // Register BeanPostProcessorChecker that logs an info message when
                int beanProcessorTargetCount = beanFactory.getBeanPostProcessorCount() + 1 +  

                                                                                                                        processorNames.length;
                beanFactory.addBeanPostProcessor(new BeanPostProcessorChecker(beanFactory,  

                                                                                                                beanProcessorTargetCount));
                List orderedProcessors = new ArrayList();
                List nonOrderedProcessorNames = new ArrayList();  

         for (int i = 0; i < processorNames.length; i++) {
                      if (isTypeMatch(processorNames[i], Ordered.class)) {
                           orderedProcessors.add(getBean(processorNames[i]));
                      }
                      else {
                           nonOrderedProcessorNames.add(processorNames[i]);
                      }  
                }

         // First, register the BeanPostProcessors that implement Ordered.
                Collections.sort(orderedProcessors, new OrderComparator());
                for (Iterator it = orderedProcessors.iterator(); it.hasNext();) {

               // 注册bean后处理器,该方法定义于ConfigurableBeanFactory接口
                      beanFactory.addBeanPostProcessor((BeanPostProcessor) it.next());
                }
                // Second, register all other BeanPostProcessors, one by one.
                for (Iterator it = nonOrderedProcessorNames.iterator(); it.hasNext();) {
                      String processorName = (String) it.next();
                      beanFactory.addBeanPostProcessor((BeanPostProcessor) getBean(processorName));
                }
       }

整段代码类似于第三步的调用工厂后处理器,区别之处在于,工厂后处理器在获取后立即调用,而Bean后处理器在获取后注册到上下文持有的beanfactory中,供以后操作调用(在用户获取bean的过程中,对已经完成属性设置工作的Bean进行后续加工,他加工的是bean,而工厂后处理器加工的是BeanDefinition)

BeanPostProcessor 接口代码如下,实际的操作由用户扩展并配置(扩展点,如何扩展?

package org.springframework.beans.factory.config;

public interface BeanPostProcessor {
             Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException;
             Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException;

}

 

4.初始化消息源:初始化容器的国际化信息资源;

源代码如下:

protected void initMessageSource() {
                // 补充
       }

 

5.初始化应用上下文事件广播器;(观察者模式中的具体主题角色,持有观察者角色的集合,称为注册表)

AbstractApplciationContext拥有一个applicationEventMulticaster 成员变量,applicationEventMulticaster 提供了容器监听器的注册表,成其为事件广播器。在第七步中将会将事件监听器装入其中

AbstractApplicationContext中的代码如下:

private ApplicationEventMulticaster applicationEventMulticaster;

protected void initApplicationEventMulticaster() {

        // "applicationEventMulticaster",先看配置文件中有无配置该类型类(用户扩展 扩展点,如何扩展
               if (containsLocalBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME)) {
                    this.applicationEventMulticaster = (ApplicationEventMulticaster)
                    getBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, ApplicationEventMulticaster.class);
               }
               else {

              // 若没有,则应用Spring框架提供的事件广播器实例
                     this.applicationEventMulticaster = new SimpleApplicationEventMulticaster();
               }
       }
       public boolean containsLocalBean(String name) {
               return getBeanFactory().containsLocalBean(name);
       }

public Object getBean(String name, Class requiredType) throws BeansException {
              return getBeanFactory().getBean(name, requiredType);
       }

Spring初始化事件广播器,用户可以在配置文件中为容器定义一个自定义的事件广播器(bean的名称要为"applicationEventMulticaster"),只要实现ApplicationEventMulticaster就可以了,Spring在此会根据beanfactory自动获取。如果没有找到外部配置的事件广播器,Spring使用SimpleApplicationEventMulticaster作为事件广播器。

 

6.初始化其他特殊的Bean:这是一个钩子方法,子类可以借助这个钩子方法执行一些特殊的操作:如AbstractRefreshableWebApplicationContext就使用该钩子方法执行初始化ThemeSource的操作;

protected void onRefresh() throws BeansException {(扩展点,如何扩展

package org.springframework.context;
            // For subclasses: do nothing by default.
       }

 

7.注册事件监听器;(观察者模式中的观察者角色)

Spring根据上下文持有的beanfactory对象,从它的BeanDefinitionRegistry中找出所有实现org.springfamework.context.ApplicationListener的bean,将BeanDefinition对象生成bean,注册为容器的事件监听器,实际的操作就是将其添加到事件广播器所提供的监听器注册表中

AbstractApplicationContext中的代码如下:

/** Statically specified listeners */

private List applicationListeners = new ArrayList();

public List getApplicationListeners() {
              return this.applicationListeners;
       }

protected void registerListeners() {
              // Register statically specified listeners first.
              for (Iterator it = getApplicationListeners().iterator(); it.hasNext();) {
                     addListener((ApplicationListener) it.next());
              }
              // 获取ApplicationListener类型的所有bean,即事件监听器
              // uninitialized to let post-processors apply to them!
              Collection listenerBeans = getBeansOfType(ApplicationListener.class, true, false).values();
              for (Iterator it = listenerBeans.iterator(); it.hasNext();) {

              // 将事件监听器装入第五步初始化的事件广播器
                     addListener((ApplicationListener) it.next());
              }
       }

public Map getBeansOfType(Class type, boolean includePrototypes, boolean allowEagerInit)
                                                                                                                          throws BeansException {

         return getBeanFactory().getBeansOfType(type, includePrototypes, allowEagerInit);
       }

protected void addListener(ApplicationListener listener) {
                getApplicationEventMulticaster().addApplicationListener(listener);
       }

ApplicationListener 的源代码如下:(扩展点,如何扩展

package org.springframework.context;

import java.util.EventListener;

/**
        * Interface to be implemented by application event listeners.
        * @see org.springframework.context.event.ApplicationEventMulticaster
       */
       public interface ApplicationListener extends EventListener {
                void onApplicationEvent(ApplicationEvent event);

}

 

8.初始化singleton的Bean:实例化所有singleton的Bean,并将它们放入Spring容器的缓存中;这就是和直接在应用中使用BeanFactory的区别之处,在创建ApplicationContext对象时,不仅创建了一个BeanFactory对象,并且还应用它实例化所有单实例的bean。

AbstractApplicationContext中的代码如下:

beanFactory.preInstantiateSingletons();

关于BeanFactory体系的代码参照。。。。。。

 

9.发布上下文刷新事件:在此处时容器已经启动完成,发布容器refresh事件(ContextRefreshedEvent)

创建上下文刷新事件,事件广播器负责将些事件广播到每个注册的事件监听器中。

publishEvent(new ContextRefreshedEvent(this));

public void publishEvent(ApplicationEvent event) {
              Assert.notNull(event, "Event must not be null");

       // 在此获取事件广播器,并调用其方法发布事件:调用所有注册的监听器的方法
              getApplicationEventMulticaster().multicastEvent(event);
              if (this.parent != null) {
                    this.parent.publishEvent(event);
              }
       }

 

至此,ApplicationContext对象就完成了初始化工作:创建BeanFactory来装配BeanDefiniton,加工处理BeanDefiniton,注册了bean后处理器,初始化了消息资源,初始化了应用上下文事件广播器,注册了事件监听器,初始化了所有singleton的bean,最后发布上下文刷新事件

分享到:
评论

相关推荐

    Spring Boot 在启动时进行配置文件加解密

    Spring Boot 在启动时进行配置文件加解密是指在 Spring Boot 应用程序启动时对配置文件进行加解密的过程。在这个过程中,Spring Boot 会读取 application.yml 文件,并触发一个事件,监听器会捕捉到这个事件,并对...

    Spring源码解密之默认标签的解析

    最后,使用`BeanDefinitionReaderUtils`的`registerBeanDefinition`方法将解析后的`BeanDefinition`注册到Bean定义注册表中,使得Spring容器在启动时能够识别并实例化这些Bean。注册过程中,`getReaderContext().get...

    spring配置文件加密实现

    接下来,我们需要编写Java代码来实现加密和解密过程。在加密阶段,我们读取配置文件的内容,使用选定的加密算法进行处理,并将结果保存到新的加密文件中。在解密阶段,我们需要先读取加密后的文件,解密后的内容再写...

    Spring项目application.xml配置文件加解密

    当Spring启动时,它会自动解密配置文件中的加密属性,从而保护了敏感信息的安全。这种方式可以有效地避免因配置文件泄露而导致的数据安全问题。同时,由于使用了对称加密算法,加解密过程相对高效,不会对应用性能...

    SpringCloud.pdf

    通过设置 `spring.cloud.bootstrap.enabled`,可以选择启用或禁用引导过程。应用程序上下文层次结构允许子上下文从父上下文中继承属性,增强了配置管理的灵活性。 总之,Spring Cloud 是构建云原生应用的强大工具,...

    spring中的数据源配置信息加密方案

    在Spring启动时,通过配置Jasypt的解密器,使得Spring能够自动解密并加载这些加密的属性。 2. **环境变量或系统属性**:将敏感信息存储在环境变量或系统属性中,而不是直接写在配置文件里。这样,即使有人获取到...

    jasypt-spring-boot-starter 3.0.5依赖的pom及jar

    这样,Spring Boot在启动时会自动识别并处理这些加密的配置。 总的来说,jasypt-spring-boot-starter 3.0.5为Java开发者提供了一个高效且安全的方式来管理和使用加密数据,简化了Spring Boot应用中的安全实践。通过...

    spring cloud 官方文档

    1. Spring Cloud Context: 提供了对ApplicationContext的扩展支持,例如BootstrapApplicationContext(用于初始化应用程序上下文中的引导过程)和ApplicationContext Hierarchies(应用程序上下文层次结构)。...

    Spring Cloud 中文文档 参考手册 中文版2018

    应用程序上下文层次结构可以改变引导位置,也就是说,Spring Cloud允许开发者通过配置改变应用程序上下文启动的优先级。通过Properties覆盖可以远程覆盖Properties的值,提供自定义引导配置和自定义引导属性源的方法...

    spring-jdbc文件数据库配置加密

    2. **配置文件加密**:使用加密工具对包含数据库配置的properties或yaml文件进行加密,然后在应用程序启动时解密。例如,可以使用Apache Commons Codec库的Base64算法进行编码解码。 3. **Spring Cloud Config ...

    Spring Cloud 中文文档.pdf

    Spring Cloud 提供了一系列的自动配置来简化这一过程。 - **引导应用程序上下文**:是指应用程序启动时加载的第一个上下文,这个上下文包含了应用程序的基础配置,用于初始化其他上下文。 - **应用程序上下文层次...

    spring中properties加密

    Spring会自动调用解密工具类解密。 ```java @Component public class MyService { @Value("${encrypted.property}") private String decryptedValue; } ``` 6. **安全存储密钥** 需要安全地存储加密所用的...

    在Spring中使用加密外部属性文件

    - 加密和解密操作的性能影响,因为这会影响应用启动时间和运行效率。 - 密钥管理的策略,包括密钥的生成、存储、更新和撤销,以及如何在多环境下共享或分发密钥。 - 安全性评估,确保选择的加密算法和实施过程符合...

    spring boot面试题及答案.docx

    Spring Boot 是一款由 Pivotal 团队提供的全新框架,旨在简化新Spring应用的初始搭建以及开发过程。传统的Spring应用需要进行大量的XML配置,这不仅繁琐而且容易出错。Spring Boot通过提供一套约定优于配置的机制,...

    spring cloud中文版【Spring Cloud Config】--spring cloud中文文档.pdf

    服务端是一个Spring Boot应用程序,因此用户可以从命令行启动,也可以从IDE启动。 **客户端示例** 客户端示例部分会介绍如何在Spring应用中使用Spring Cloud Config客户端,通过配置客户端引入配置服务器的信息,并...

    SpringCloud之七 分布式配置中心SpringCloudConfig.pdf

    5. 加密解密功能:对于一些敏感的配置信息,Spring Cloud Config支持对这些信息进行加密存储,在使用时再进行解密,确保配置的安全性。 6. 与Spring Cloud的无缝集成:Spring Cloud Config天然与Spring Cloud生态中...

    Spring Boot是一个由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程 以

    - **安全性应用程序**:Spring Boot 还提供了丰富的安全特性,包括但不限于认证和授权机制、访问控制策略、加密和解密操作等。 #### 总结 Spring Boot 是一个多功能且高度集成的框架,它通过简化配置和开发流程,...

    spring-boot-mybits:Spring启动的秘诀

    首先,让我们解密Spring Boot的启动过程。Spring Boot应用通常由一个主类开始,该类通常包含`@SpringBootApplication`注解。这个注解是`@Configuration`、`@EnableAutoConfiguration`和`@ComponentScan`三个注解的...

    jdk1.8实现http接口rsa加密解密.zip

    在Java开发中,使用JDK 1.8结合Spring MVC框架来实现HTTP接口的RSA加密解密,可以增强数据安全性,防止敏感信息在传输过程中被窃取。 首先,我们需要理解RSA的工作原理。RSA基于数论中的大数因子分解难题,它包含两...

    Spring Cloud (Dalston)中文文档

    Spring Cloud应用程序使用“引导”上下文启动,它是主应用程序的父上下文,负责加载外部配置属性并解密属性。Bootstrap属性优先级高于常规应用属性,它们使用不同的配置文件约定,如`bootstrap.yml`和`application....

Global site tag (gtag.js) - Google Analytics