一个快速找到Spring框架是在哪里找到XML配置文件并解析Beans定义的小技巧
We can define bean configuration in xml and then can get instantiated bean instance with help of all kinds of containers for example ClassPathXmlApplicationContext as displayed below:
The content of Beans.xml:
<?xml version="1.0" encoding="UTF-8"?> <!-- http://stackoverflow.com/questions/18802982/no-declaration-can-be-found-for-element-contextannotation-config --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <bean id="helloWorld" class="main.java.com.sap.HelloWorld"> <property name="message" value="sss"/> <property name="testMin" value="2"/> <property name="phone" value="1"/> </bean> </beans>
Where can we set breakpoint to start? No hint. Here is a tip: we can make the Beans.xml invalid by deliberately changing te tag bean to beana, and relaunch application. Now exception is raised as expected: Click the hyperlink XmlBeanDefinitionReader.java:399,
The line 399 where exception is raised will be automatically located. The core logic to load xml file is just near the exception raise position: line 391. So we can set breakpoint in line 391 now:
Change the tag from beana back to bean, and start application via debug mode. The code below is the core logic of Bean configuration file parse in Spring framework. The logic consists of two main steps:
- parse XML as a dom structure in memory ( line 391 )
- extract bean information contained in dom structure and generate BeanDefinition structure ( line 392 )
from screenshot below we can find out the xml is parsed via SAX parser:
My “helloWorld” bean is parsed here:
本文来自云栖社区合作伙伴“汪子熙”,了解相关信息可以关注微信公众号"汪子熙"。
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
搭建K8S多节点LB负载均衡和keepalived
搭建LB负载均衡和keepalived 一、环境优化LB1 [root@localhost ~]# hostnamectl set-hostname lb1 [root@localhost ~]# su //修改主机名 [root@lb1 ~]# systemctl stop NetworkManager //关闭NetworkManage服务 [root@lb1 ~]# systemctl disable NetworkManager Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service. Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service. Removed symlink /etc/systemd/system/network-online.target.wants/NetworkManager-wait-online.service. [root@lb1 ~]# s...
- 下一篇
Spring Boot + Spring Kafka配置公网接入阿里云Kafka
场景说明 今天接到的一个任务是做公网接入阿里云的kafka。不推荐通过公网访问。 由于通过公网问,需要配置为客户端接入配置SASL_SSL的鉴权,设置证书,协议,访问模式的账号密码等参数。 自己的应用采用的是spring boot + spring kafka来接入kafka。 因此,在配置上需要做一些适配和调整。 官方文档 https://help.aliyun.com/knowledge_detail/99958.html 原生的配置,主要有几个点: 在控制台下载ssl证书 ---- kafka.client.truststore.jks,放在机器的某个路径上,不要跟着应用打包 构建 kafka_client_jaas.conf,它包含着登录模式,登录用账号密码等的信息,账号密码信息在控制台上能找到。将应用启动参数java.security.auth.login.config设置为kafka_client_jaas.conf的绝对路径,可以通过代码或者启动参数设置。 注意 : spring boot配置中可以不需要的这个kafka_client_jaas.conf,它通过读取app...
相关文章
文章评论
共有0条评论来说两句吧...