SOFABoot源码解析之模块化开发

匿名 (未验证) 提交于 2019-12-03 00:38:01

1.SOFABoot源码解析

模块化开发

模块化开发简述


Module-Name=com.alipay.test.biz.service.impl
Spring-Parent=com.alipay.test.common.dal
Require-Module=com.alipay.test.biz.shared
Module-Profile=dev

模块并发启动

com.alipay.sofa.boot.module-start-up-parallel=false

SOFABoot Profile

com.alipay.sofa.boot.active-profiles=dev

Module-Profile=dev

com.alipay.sofa.boot.active-profiles=dev,test

Module-Profile=test,product

com.alipay.sofa.boot.active-profiles=dev

Module-Profile=!product

com.alipay.sofa.boot.active-profiles=dev,test

<?xml version="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"







10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27. </beans>

@SpringBootApplication
public class ApplicationRun {



}

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.alipay.sofa.isle.spring.configuration.SofaModuleAutoConfiguration

protectedvoid finishRefresh() {
super.finishRefresh();





}

protected void finishRefresh() {


publishEvent(new ContextRefreshedEvent(this));


}

public voidonApplicationEvent(ContextRefreshedEvent event) {








10.
11. pipelineContext.process();
12.
13.
14.
15.
16.
17.


ApplicationRuntimeModel application = newApplicationRuntimeModel();


getAllDeployments(application);


private voidgetAllDeployments(ApplicationRuntimeModel application) throws IOException {





while (urls.hasMoreElements()) {


10.
11.
12.
13.
14.
15.
16.
17.
18. if (application.isModuleDeployment(dd)) {
19.
20. application.addDeployment(dd);
21.
22. application.addInactiveDeployment(dd);
23.
24.
25. }
26.


ApplicationRuntimeModel application =applicationContext.getBean(



doProcess(application);



10.

private voiddoProcess(ApplicationRuntimeModel application) throws Exception {


installSpringContext(application, springContextLoader);





10.
11.
12.

private voidoutputModulesMessage(ApplicationRuntimeModel application)



application.getResolvedDeployments(),


}



resolvedDeployments = deployRegistry.getResolvedObjects();




commitDeployments();




add(fd.getModuleName(), fd,fd.getRequiredModules());


public void add(K key, T object,Collection<K> requires) {








10.
11. updateDependencies(entry, requires);
12.
13.
14.
15.
16.

protected voidupdateDependencies(Entry<K, T> entry, Collection<K> requires) {






reqEntry.addDependsOnMe(entry);

10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.

private voidinstallSpringContext(ApplicationRuntimeModel application,



for (DeploymentDescriptor deployment :application.getResolvedDeployments()) {




10. springContextLoader.loadSpringContext(deployment,application);
11.
12.
13.
14.
15. Thread.currentThread().setContextClassLoader(oldClassLoader);
16.
17.
18.
19.

public voidloadSpringContext(DeploymentDescriptor deployment,








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. XmlBeanDefinitionReader beanDefinitionReader =new XmlBeanDefinitionReader(ctx);
41.
42.
43.
44.
45.
46.
47.
48.
49. beanDefinitionReader.loadBeanDefinitions(entry.getValue());
50.
51.
52.
53.

org.springframework.boot.context.properties.ConfigurationBeanFactoryMetaData
org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
com.alipay.sofa.runtime.spring.ServiceAnnotationBeanPostProcessor
com.alipay.sofa.isle.spring.listener.SofaModuleBeanFactoryPostProcessor
com.alipay.sofa.runtime.spring.SofaRuntimeContextAwareProcessor
com.alipay.sofa.runtime.spring.ClientFactoryBeanPostProcessor
org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor
org.springframework.boot.web.servlet.ErrorPageRegistrarBeanPostProcessor
10. org.springframework.context.annotation.ConfigurationClassPostProcessor
11. org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor

private voidrefreshSpringContextParallel(ApplicationRuntimeModel application) {


ThreadPoolExecutor executor = newThreadPoolExecutor(CPU_COUNT + 1, CPU_COUNT + 1, 60,



for (DeploymentDescriptor deployment :application.getResolvedDeployments()) {

10.
11.
12.
13.
14.
15. refreshSpringContextParallel(coreRoots,application.getResolvedDeployments().size(),
16.
17.
18.
19.
20.
21.
22.

private voidrefreshSpringContextParallel(List<DeploymentDescriptor> rootDeployments,





final CountDownLatch latch = newCountDownLatch(totalSize);


10. for (final DeploymentDescriptor deployment :rootDeployments) {
11.
12.
13.
14.
15. latch.await();
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.

private voidrefreshSpringContextParallel(final DeploymentDescriptor deployment,



executor.submit(new Runnable() {




10.
11.
12. doRefreshSpringContext(deployment,application);
13.
14.
15.
16.
17. for (final DependencyTree.Entry<String,DeploymentDescriptor> child : entry
18. {
19.
20. if (child.getDependencies().size() == 0) {
21.
22.
23.
24.
25.
26.
27.
28.
29. latch.countDown();
30.
31.
32.
33.
34.

private voiddoRefreshSpringContext(DeploymentDescriptor deployment,






ctx.refresh();

10.
11.
12.
13.
14.
15.
16.
17.
18.






logInstalledModules(stringBuilder,application.getInstalled());



10.
11.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!