首页 文章 精选 留言 我的

精选列表

搜索[依赖管理],共10000篇文章
优秀的个人博客,低调大师

ABAP模拟Java Spring依赖注入(Dependency injection)的一个尝试

Recently I will deliver a session regarding dependency inversion principle to my team. As Java Spring is already widely used in all other Java development teams in my site, some ABAPers are not well aware of its idea and implementation under the hood. In order for ABAPers to easily understand the mechanism of Java Spring dependency inversion, I wrote a prototype in ABAP after going through related Java source code of Spring. Before I start, I perform the search in SCN. There are already several excellent blogs written regarding dependency injection in ABAP: (1) ABAP Dependency Injection – An implementation approach(2) Shoot Me Up ABAP(3) Dependency Injection for ABAP(4) MockA in github Thanks a lot for efforts spent by authors of them!Compared with those blogs, the advantage of my prototype is: it follows exactly the design of Java Spring, it is not needed for users to do any other manual dependency registration except a single annotation @Inject. So it is useful for ABAPers to understand Spring dependency internal implementation. Let me begin with a simple example. In real world I have a switch. By pressing it, the lamp connected by that switch is turned on. With switch pressed for second time, the lamp is turned off. That’s all. Implementation without using Dependency injection I have an interface ZIF_SWITCHABLE with two simple methods: And a ZCL_LAMP which simply implements this interface: CLASS ZCL_LAMP IMPLEMENTATION. method ZIF_SWITCHABLE~OFF. WRITE: / 'lamp off'. endmethod. method ZIF_SWITCHABLE~ON. WRITE: / 'lamp on'. endmethod. ENDCLASS. And a switch which internally maintains the current switch status and a reference to ZIF_SWITCHABLE: The switch has a push method to toggle: METHOD push. IF isswitchon = abap_true. mo_switchable->off( ). isswitchon = abap_false. ELSE. mo_switchable->on( ). isswitchon = abap_true. ENDIF. ENDMETHOD. And a setter method is needed to inject the switchable instance: method SET_SWITCHABLE. mo_switchable = io_switchable. endmethod. These two classes and one interface are put to the following package: Consumer code – version one without using dependency injection Here the ZCL_SWITCH has tight dependency on ZCL_LAMP: it has to manually inject this dependency via setter method in line 11. Let’s summarize how many manual / unnecessary operations are done by consumer: (1) line 8: create lamp instance(2) line 9: create switch instance(3) line 11: connect switch with lamp Implementation using ABAP Summer I call my prototype as ABAP Summer just to show my admire on Java Spring When the same requirement is implemented in Java Spring, the logic in line 11 could completely be avoided, with help of various powerful annotation like @Autowired, @Named, @Inject etc. Thanks to Java Spring container, lots of labor work has been done by it under the hood, saving lots of routine effort from application developers so that they can only concentrate on the core business logic. For example, in Java using Spring, all developers need to do is to add annotation @Inject on top of attribute switchable – in the runtime Spring will guarantee that the annotated implementation for this interface is instantiated automatically. How can we simulate the similar logic of Spring now in ABAP Summer? (1) Add the annotation @Inject to attribute mo_switchable, which tells ABAP summer “hey, I would like this attribute to be automatically injected with proper implementation in the runtime”.Since I have no other way to add metadata in class attribute in ABAP – there is no first class annotation supported in ABAP – I have to use description field for simulation. (2) And below is my consumer code, no more manual instance initialization and manual setter call. Very clean, isn’t it? data(summer) = zcl_summer=>get_instance( ). data(lo_switch) = cast zcl_switch( summer->get_bean( EXPORTING iv_bean_name = 'ZCL_SWITCH' ) ). lo_switch->push( ). lo_switch->push( ). Let’s make comparison. By using ABAP summer, consumer can simply get switch instance from container by passing bean technical name ( here again, I use Spring terminology “bean” to name those ABAP classes which owns an injected member attribute with @Inject ). This is exactly the way a Java developer doing daily work using Java Spring: How does ABAP summer work? There are lots of books written to illustrate the design of Java Spring, I read one of them listed below, and wrote this ABAP summer based on my understanding. I draw a diagram below to explain the core method init of ABAP summer: Last by not least, when you try this demo, after you copy the source code of ZCL_SWITCH to your system and activate it, NEVER forget to add this annotation in description field manually, as in ABAP, the attribute description is not stored in source code but in DB table. More thought on ABAP annotation The annotation in Java is a form of metadata which could be defined by application developer and are available in the runtime by Java reflection. It is a built-in language feature supported by JVM. In ABAP there is no such first-class annotation supported. In CDS view, there are some grammar which have annotation-like style. You can append lots of annotation defined in SAP help to a CDS view. However those annotation are not first-class annotation supported by ABAP language itself as well. It is just CDS view framework which parses the source code of these annotation and react accordingly. For details please see these two blogs of mine: (1) My CDS view self study tutorial – Part 3 how is view source in Eclipse converted to ABAP view in the backend(2) My CDS view self study tutorial – Part 4 how does annotation @OData.publish work 本文来自云栖社区合作伙伴“汪子熙”,了解相关信息可以关注微信公众号"汪子熙"。

优秀的个人博客,低调大师

Apache Fineract 1.3.0 修复了一个上游依赖安全漏洞

Apache Fineract 项目在 1.3.0 版本中修复了一个 Spring Security OAuth 安全漏洞CVE-2016-4977,该漏洞允许恶意用户远程执行代码。 NATIONAL VULNERABILITY DATABASE(NVD)介绍了该漏洞的具体情况,在 Spring Security OAuth 2.0.0-2.0.9 和 1.0.0-1.0.5 版本中使用 whitelabel 视图处理授权请求时,response_type 参数值作为 Spring SpEL 执行,这使恶意用户能够通过手工触发远程代码执行 response_type 的值。 Fineract 是一个用于核心银行系统平台化建设的系统,它为创业者、金融机构和服务提供商提供了一个可靠、健壮的金融服务解决方案。 通告查看: http://mail-archives.apache.org/mod_mbox/www-announce/201910.mbox/%3cCACqpLwJGBRp9cpyhVwxvc0SSrTbUoDxAr+YnywXjj=BRFhiyPw@mail.gmail.com%3e

优秀的个人博客,低调大师

IDEA 打war包部署时子模块jar包没依赖上

使用IDEA在tomcat中部署maven多模块时出现的一个莫名的bug 首先在server中打印下: 可以看见 context [] startup failed due to previous error, see server log for details. [2018-10-19 10:55:28,273] Artifact springmvc-test:war exploded: Artifact is being deployed, please wait... Oct 19, 2018 10:55:29 AM org.apache.catalina.startup.TldConfig execute INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Oct 19, 2018 10:55:30 AM org.apache.catalina.core.StandardContext startInternal SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file Oct 19, 2018 10:55:30 AM org.apache.catalina.core.StandardContext startInternal SEVERE: Context [] startup failed due to previous errors [2018-10-19 10:55:30,410] Artifact springmvc-test:war exploded: Error during artifact deployment. See server log for details. Oct 19, 2018 10:55:38 AM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory /opt/apache-tomcat-7.0.90/webapps/manager Oct 19, 2018 10:55:38 AM org.apache.catalina.startup.TldConfig execute INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. Oct 19, 2018 10:55:38 AM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deployment of web application directory /opt/apache-tomcat-7.0.90/webapps/manager has finished in 222 ms 于是我们打开tomcat日志位置并查看: 显示framework-base中的ConfigItem NotFound. zwj@ubuntu:~/.IntelliJIdea2018.1/system/tomcat/Unnamed_learn/logs$ ls catalina.2018-10-18.log localhost_access_log.2018-10-17.txt catalina.2018-10-19.log localhost_access_log.2018-10-18.txt host-manager.2018-10-18.log localhost_access_log.2018-10-19.txt host-manager.2018-10-19.log manager.2018-10-18.log localhost.2018-10-18.log manager.2018-10-19.log localhost.2018-10-19.log cat localhost。2018-10-19.log org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.zwj.framework.base.config.ConfigItem] for bean with name 'com.zwj.framework.base.config.ConfigItem#0' defined in class path resource [spring/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: com.zwj.framework.base.config.ConfigItem 果然在war包下的lib中并没有framework-base,springwork-mybatis等子模块的jar包: 显然使用idea点击运行tomcat时,在编译打包过程中我们的子模块给遗漏了?带着问题继续查看IDEA的日志。。。 zwj@ubuntu:~$ cd .IntelliJIdea2018.1/system/log/ zwj@ubuntu:~/.IntelliJIdea2018.1/system/log$ ls build-log idea.log.2 idea.log.5 idea.log idea.log.3 threadDumps-freeze-20181016-152806-IU-181.5540.7-20sec idea.log.1 idea.log.4 zwj@ubuntu:~/.IntelliJIdea2018.1/system/log$ tail -f idea.log com.intellij.execution.ExecutionException: Cannot load /home/zwj/learn/learn/springmvc-test/target/artifacts/springmvc_test_war_exploded /META-INF/context.xml: /home/zwj/learn/learn/springmvc-test/target/artifacts/springmvc_test_war_exploded/META-INF/context.xml (No such file or directory) at org.jetbrains.idea.tomcat.TomcatUtil.loadXMLFile(TomcatUtil.java:208) at org.jetbrains.idea.tomcat.TomcatUtil.findContextInContextXml(TomcatUtil.java:107) at org.jetbrains.idea.tomcat.TomcatUtil.findContextElement(TomcatUtil.java:381) at org.jetbrains.idea.tomcat.admin.TomcatAdminLocalServerImpl.addApplicationContext(TomcatAdminLocalServerImpl.java:191) 百度了半天发现,这个context文件没有加载并不是错误的根本,而是没有导入子模块的jar包时产生的子错误。 庆幸的是最终还是找到了错误,我们看到下图中artifacts的lib中没有子模块的jar包,需要先点击lib,然后在available elements中点开相应模块,然后再 pack into进去。 最后点击运行就行了。。。。。。。 坑。。。。。

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册